Skip to content

Commit

Permalink
Merge pull request getmoto#248 from ttacon/master
Browse files Browse the repository at this point in the history
Add create_login_profile for iam service
  • Loading branch information
spulec committed Oct 30, 2014
2 parents 646bafc + 5aec4d9 commit 5c9fec1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions moto/iam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def __init__(self, name, path='/'):

self.policies = {}
self.access_keys = []
self.password = None

def get_policy(self, policy_name):
policy_json = None
Expand Down Expand Up @@ -270,6 +271,16 @@ def get_user(self, user_name):

return user

def create_login_profile(self, user_name, password):
if not user_name in self.users:
raise BotoServerError(404, 'Not Found')

# This does not currently deal with PasswordPolicyViolation.
user = self.users[user_name]
if user.password:
raise BotoServerError(409, 'Conflict')
user.password = password

def add_user_to_group(self, group_name, user_name):
group = None
user = None
Expand Down
22 changes: 22 additions & 0 deletions moto/iam/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ def get_user(self):
template = Template(USER_TEMPLATE)
return template.render(action='Get', user=user)

def create_login_profile(self):
user_name = self._get_param('UserName')
password = self._get_param('Password')
iam_backend.create_login_profile(user_name, password)

template = Template(CREATE_LOGIN_PROFILE_TEMPLATE)
return template.render(user_name=user_name)

def add_user_to_group(self):
group_name = self._get_param('GroupName')
user_name = self._get_param('UserName')
Expand Down Expand Up @@ -439,6 +447,20 @@ def delete_user(self):
</ResponseMetadata>
</{{ action }}UserResponse>"""

CREATE_LOGIN_PROFILE_TEMPLATE = """
<CreateLoginProfileResponse>
<CreateUserResult>
<LoginProfile>
<UserName>{{ user_name }}</UserName>
<CreateDate>2011-09-19T23:00:56Z</CreateDate>
</LoginProfile>
</CreateUserResult>
<ResponseMetadata>
<RequestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestId>
</ResponseMetadata>
</CreateLoginProfileResponse>
"""

GET_USER_POLICY_TEMPLATE = """<GetUserPolicyResponse>
<GetUserPolicyResult>
<UserName>{{ user_name }}</UserName>
Expand Down
11 changes: 11 additions & 0 deletions tests/test_iam/test_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ def test_get_user():
conn.get_user('my-user')


@mock_iam()
def test_create_login_profile():
conn = boto.connect_iam()
with assert_raises(BotoServerError):
conn.create_login_profile('my-user', 'my-pass')
conn.create_user('my-user')
conn.create_login_profile('my-user', 'my-pass')
with assert_raises(BotoServerError):
conn.create_login_profile('my-user', 'my-pass')


@mock_iam()
def test_add_user_to_group():
conn = boto.connect_iam()
Expand Down

0 comments on commit 5c9fec1

Please sign in to comment.