Merge pull request #2280 from acsbendi/create-access-key-fix

Create access key fix
This commit is contained in:
Steve Pulec 2019-07-06 15:40:12 -05:00 committed by GitHub
commit 04f8446a93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 9 deletions

View File

@ -292,8 +292,8 @@ class AccessKey(BaseModel):
def __init__(self, user_name): def __init__(self, user_name):
self.user_name = user_name self.user_name = user_name
self.access_key_id = random_access_key() self.access_key_id = "AKIA" + random_access_key()
self.secret_access_key = random_alphanumeric(32) self.secret_access_key = random_alphanumeric(40)
self.status = 'Active' self.status = 'Active'
self.create_date = datetime.utcnow() self.create_date = datetime.utcnow()
self.last_used = datetime.utcnow() self.last_used = datetime.utcnow()

View File

@ -1493,6 +1493,7 @@ CREATE_ACCESS_KEY_TEMPLATE = """<CreateAccessKeyResponse>
<AccessKeyId>{{ key.access_key_id }}</AccessKeyId> <AccessKeyId>{{ key.access_key_id }}</AccessKeyId>
<Status>{{ key.status }}</Status> <Status>{{ key.status }}</Status>
<SecretAccessKey>{{ key.secret_access_key }}</SecretAccessKey> <SecretAccessKey>{{ key.secret_access_key }}</SecretAccessKey>
<CreateDate>{{ key.created_iso_8601 }}</CreateDate>
</AccessKey> </AccessKey>
</CreateAccessKeyResult> </CreateAccessKeyResult>
<ResponseMetadata> <ResponseMetadata>

View File

@ -7,7 +7,7 @@ import six
def random_alphanumeric(length): def random_alphanumeric(length):
return ''.join(six.text_type( return ''.join(six.text_type(
random.choice( random.choice(
string.ascii_letters + string.digits string.ascii_letters + string.digits + "+" + "/"
)) for _ in range(length) )) for _ in range(length)
) )

View File

@ -577,13 +577,17 @@ def test_delete_login_profile():
conn.delete_login_profile('my-user') conn.delete_login_profile('my-user')
@mock_iam_deprecated() @mock_iam()
def test_create_access_key(): def test_create_access_key():
conn = boto.connect_iam() conn = boto3.client('iam', region_name='us-east-1')
with assert_raises(BotoServerError): with assert_raises(ClientError):
conn.create_access_key('my-user') conn.create_access_key(UserName='my-user')
conn.create_user('my-user') conn.create_user(UserName='my-user')
conn.create_access_key('my-user') access_key = conn.create_access_key(UserName='my-user')["AccessKey"]
(datetime.utcnow() - access_key["CreateDate"].replace(tzinfo=None)).seconds.should.be.within(0, 10)
access_key["AccessKeyId"].should.have.length_of(20)
access_key["SecretAccessKey"].should.have.length_of(40)
assert access_key["AccessKeyId"].startswith("AKIA")
@mock_iam_deprecated() @mock_iam_deprecated()