-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IAM: get_user() should return PasswordLastUsed-field if set (#5942)
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import boto3 | ||
from datetime import datetime | ||
from moto import mock_iam, settings | ||
from moto.backends import get_backend | ||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID | ||
from unittest import SkipTest | ||
|
||
|
||
@mock_iam | ||
def test_password_last_used(): | ||
if settings.TEST_SERVER_MODE: | ||
raise SkipTest("Can't set password_last_used in ServerMode") | ||
client = boto3.client("iam", "us-east-1") | ||
username = "test.user" | ||
client.create_user(Path="/staff/", UserName=username)["User"] | ||
client.create_login_profile( | ||
UserName=username, Password="Password1", PasswordResetRequired=False | ||
) | ||
|
||
access_key = client.create_access_key(UserName=username)["AccessKey"] | ||
|
||
as_new_user = boto3.resource( | ||
"iam", | ||
region_name="us-east-1", | ||
aws_access_key_id=access_key["AccessKeyId"], | ||
aws_secret_access_key=access_key["SecretAccessKey"], | ||
) | ||
|
||
# Username is set, but password not yet | ||
assert as_new_user.CurrentUser().user_name == username | ||
assert not as_new_user.CurrentUser().password_last_used | ||
|
||
iam_backend = get_backend("iam")[ACCOUNT_ID]["global"] | ||
iam_backend.users[username].password_last_used = datetime.utcnow() | ||
|
||
# Password is returned now | ||
assert as_new_user.CurrentUser().password_last_used |