Fix bug with listing IAM users.

This commit is contained in:
Steve Pulec 2017-01-11 20:54:37 -05:00
parent 2a02259a3c
commit 201efd5773
3 changed files with 11 additions and 11 deletions

View File

@ -176,15 +176,15 @@ class Group(object):
class User(object):
def __init__(self, name, path='/'):
def __init__(self, name, path=None):
self.name = name
self.id = random_resource_id()
self.path = path
self.path = path if path else "/"
self.created = datetime.strftime(
datetime.utcnow(),
"%Y-%m-%d-%H-%M-%S"
)
self.arn = 'arn:aws:iam::123456789012:user/{0}'.format(name)
self.arn = 'arn:aws:iam::123456789012:user{0}{1}'.format(self.path, name)
self.policies = {}
self.access_keys = []
self.password = None
@ -591,7 +591,7 @@ class IAMBackend(BaseBackend):
def list_users(self, path_prefix, marker, max_items):
users = None
try:
users = self.users
users = self.users.values()
except KeyError:
raise IAMNotFoundException("Users {0}, {1}, {2} not found".format(path_prefix, marker, max_items))

View File

@ -204,9 +204,9 @@ class IamResponse(BaseResponse):
path_prefix = self._get_param('PathPrefix')
marker = self._get_param('Marker')
max_items = self._get_param('MaxItems')
user = iam_backend.list_users(path_prefix, marker, max_items)
users = iam_backend.list_users(path_prefix, marker, max_items)
template = self.response_template(LIST_USERS_TEMPLATE)
return template.render(action='List', user=user)
return template.render(action='List', users=users)
def create_login_profile(self):
user_name = self._get_param('UserName')
@ -724,7 +724,7 @@ LIST_USERS_TEMPLATE = """<{{ action }}UsersResponse>
<UserId>{{ user.id }}</UserId>
<Path>{{ user.path }}</Path>
<UserName>{{ user.name }}</UserName>
<Arn>arn:aws:iam::123456789012:user/{{ user.path }}/{{ user.name }}</Arn>
<Arn>{{ user.arn }}</Arn>
</member>
{% endfor %}
</Users>

View File

@ -196,10 +196,10 @@ def test_list_users():
conn = boto3.client('iam')
conn.create_user(UserName='my-user')
response = conn.list_users(PathPrefix=path_prefix, MaxItems=max_items)
assert_equals(
response['Users'],
[]
)
user = response['Users'][0]
user['UserName'].should.equal('my-user')
user['Path'].should.equal('/')
user['Arn'].should.equal('arn:aws:iam::123456789012:user/my-user')
@mock_iam()