Add support for login profile deletion (#768)

* Add support for delete_login_profile.

Mock deletion of login profile. Set password to
none. Add tests to cover new endpoint.

* Fix typo in create_login_profile response.

Change CreateUserResult to CreateLoginProfileResult
in the CREATE_LOGIN_PROFILE_TEMPLATE. Caused KeyError
when using boto3.

Add test to cover boto3 in addition to boto.
This commit is contained in:
Sean Marlow 2016-11-11 15:05:02 -07:00 committed by Steve Pulec
parent 71c1fbadbe
commit fa3663c610
3 changed files with 40 additions and 2 deletions

View File

@ -604,6 +604,12 @@ class IAMBackend(BaseBackend):
raise IAMConflictException("User {0} already has password".format(user_name)) raise IAMConflictException("User {0} already has password".format(user_name))
user.password = password user.password = password
def delete_login_profile(self, user_name):
user = self.get_user(user_name)
if not user.password:
raise IAMNotFoundException("Login profile for {0} not found".format(user_name))
user.password = None
def add_user_to_group(self, group_name, user_name): def add_user_to_group(self, group_name, user_name):
user = self.get_user(user_name) user = self.get_user(user_name)
group = self.get_group(group_name) group = self.get_group(group_name)

View File

@ -289,6 +289,12 @@ class IamResponse(BaseResponse):
template = self.response_template(GENERIC_EMPTY_TEMPLATE) template = self.response_template(GENERIC_EMPTY_TEMPLATE)
return template.render(name='DeleteUser') return template.render(name='DeleteUser')
def delete_login_profile(self):
user_name = self._get_param('UserName')
iam_backend.delete_login_profile(user_name)
template = self.response_template(GENERIC_EMPTY_TEMPLATE)
return template.render(name='DeleteLoginProfile')
def generate_credential_report(self): def generate_credential_report(self):
if iam_backend.report_generated(): if iam_backend.report_generated():
template = self.response_template(CREDENTIAL_REPORT_GENERATED) template = self.response_template(CREDENTIAL_REPORT_GENERATED)
@ -730,12 +736,12 @@ LIST_USERS_TEMPLATE = """<{{ action }}UsersResponse>
CREATE_LOGIN_PROFILE_TEMPLATE = """ CREATE_LOGIN_PROFILE_TEMPLATE = """
<CreateLoginProfileResponse> <CreateLoginProfileResponse>
<CreateUserResult> <CreateLoginProfileResult>
<LoginProfile> <LoginProfile>
<UserName>{{ user_name }}</UserName> <UserName>{{ user_name }}</UserName>
<CreateDate>2011-09-19T23:00:56Z</CreateDate> <CreateDate>2011-09-19T23:00:56Z</CreateDate>
</LoginProfile> </LoginProfile>
</CreateUserResult> </CreateLoginProfileResult>
<ResponseMetadata> <ResponseMetadata>
<RequestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestId> <RequestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestId>
</ResponseMetadata> </ResponseMetadata>

View File

@ -5,6 +5,7 @@ import boto
import boto3 import boto3
import sure # noqa import sure # noqa
from boto.exception import BotoServerError from boto.exception import BotoServerError
from botocore.exceptions import ClientError
from moto import mock_iam from moto import mock_iam
from moto.iam.models import aws_managed_policies from moto.iam.models import aws_managed_policies
from nose.tools import assert_raises, assert_equals, assert_not_equals from nose.tools import assert_raises, assert_equals, assert_not_equals
@ -187,6 +188,7 @@ def test_get_user():
conn.create_user('my-user') conn.create_user('my-user')
conn.get_user('my-user') conn.get_user('my-user')
@mock_iam() @mock_iam()
def test_list_users(): def test_list_users():
path_prefix = '/' path_prefix = '/'
@ -211,6 +213,16 @@ def test_create_login_profile():
conn.create_login_profile('my-user', 'my-pass') conn.create_login_profile('my-user', 'my-pass')
@mock_iam()
def test_delete_login_profile():
conn = boto.connect_iam()
conn.create_user('my-user')
with assert_raises(BotoServerError):
conn.delete_login_profile('my-user')
conn.create_login_profile('my-user', 'my-pass')
conn.delete_login_profile('my-user')
@mock_iam() @mock_iam()
def test_create_access_key(): def test_create_access_key():
conn = boto.connect_iam() conn = boto.connect_iam()
@ -313,3 +325,17 @@ def test_managed_policy():
{'RoleName': role_name}, {'RoleName': role_name},
list_marker='AttachedPolicies') list_marker='AttachedPolicies')
resp['list_attached_role_policies_response']['list_attached_role_policies_result']['attached_policies'].should.have.length_of(2) resp['list_attached_role_policies_response']['list_attached_role_policies_result']['attached_policies'].should.have.length_of(2)
@mock_iam
def test_boto3_create_login_profile():
conn = boto3.client('iam')
with assert_raises(ClientError):
conn.create_login_profile(UserName='my-user', Password='Password')
conn.create_user(UserName='my-user')
conn.create_login_profile(UserName='my-user', Password='Password')
with assert_raises(ClientError):
conn.create_login_profile(UserName='my-user', Password='Password')