use conditional TEST_SERVER_MODE for backend tests
This commit is contained in:
parent
0423be259a
commit
1f1404352e
@ -12,9 +12,10 @@ from boto.exception import BotoServerError
|
||||
from botocore.exceptions import ClientError
|
||||
from dateutil.tz import tzutc
|
||||
|
||||
from moto import mock_iam, mock_iam_deprecated
|
||||
from moto import mock_iam, mock_iam_deprecated, settings
|
||||
from moto.core import ACCOUNT_ID
|
||||
from moto.iam.models import aws_managed_policies
|
||||
from moto.backends import get_backend
|
||||
from nose.tools import assert_raises, assert_equals
|
||||
from nose.tools import raises
|
||||
|
||||
@ -1227,6 +1228,9 @@ def test_boto3_get_credential_report_content():
|
||||
)
|
||||
key1 = conn.create_access_key(UserName=username)["AccessKey"]
|
||||
timestamp = datetime.utcnow()
|
||||
if not settings.TEST_SERVER_MODE:
|
||||
iam_backend = get_backend("iam")["global"]
|
||||
iam_backend.users[username].access_keys[1].last_used = timestamp
|
||||
with assert_raises(ClientError):
|
||||
conn.get_credential_report()
|
||||
result = conn.generate_credential_report()
|
||||
@ -1242,12 +1246,38 @@ def test_boto3_get_credential_report_content():
|
||||
user = next(report_dict)
|
||||
user["user"].should.equal("my-user")
|
||||
user["access_key_1_active"].should.equal("false")
|
||||
user["access_key_1_last_rotated"].should.match(
|
||||
timestamp.strftime(datetime.utcnow(), "%Y-%m-%d")
|
||||
)
|
||||
user["access_key_1_last_rotated"].should.match(timestamp.strftime("%Y-%m-%d"))
|
||||
user["access_key_1_last_used_date"].should.equal("N/A")
|
||||
user["access_key_2_active"].should.equal("true")
|
||||
user["access_key_2_last_used_date"].should.equal("N/A")
|
||||
if not settings.TEST_SERVER_MODE:
|
||||
user["access_key_2_last_used_date"].should.match(timestamp.strftime("%Y-%m-%d"))
|
||||
else:
|
||||
user["access_key_2_last_used_date"].should.equal("N/A")
|
||||
|
||||
|
||||
@mock_iam
|
||||
def test_get_access_key_last_used_when_used():
|
||||
iam = boto3.resource("iam", region_name="us-east-1")
|
||||
client = iam.meta.client
|
||||
username = "test-user"
|
||||
iam.create_user(UserName=username)
|
||||
with assert_raises(ClientError):
|
||||
client.get_access_key_last_used(AccessKeyId="non-existent-key-id")
|
||||
create_key_response = client.create_access_key(UserName=username)["AccessKey"]
|
||||
# Set last used date using the IAM backend. Moto currently does not have a mechanism for tracking usage of access keys
|
||||
if not settings.TEST_SERVER_MODE:
|
||||
timestamp = datetime.utcnow()
|
||||
iam_backend = get_backend("iam")["global"]
|
||||
iam_backend.users[username].access_keys[0].last_used = timestamp
|
||||
resp = client.get_access_key_last_used(
|
||||
AccessKeyId=create_key_response["AccessKeyId"]
|
||||
)
|
||||
if not settings.TEST_SERVER_MODE:
|
||||
datetime.strftime(
|
||||
resp["AccessKeyLastUsed"]["LastUsedDate"], "%Y-%m-%d"
|
||||
).should.equal(timestamp.strftime("%Y-%m-%d"))
|
||||
else:
|
||||
resp["AccessKeyLastUsed"].should_not.contain("LastUsedDate")
|
||||
|
||||
|
||||
@requires_boto_gte("2.39")
|
||||
|
Loading…
Reference in New Issue
Block a user