| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved | 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 3 # | 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a | 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the | 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including | 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- | 7 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 8 # tribute, sublicense, and/or sell copies of the Software, and to permit | 8 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- | 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: | 10 # lowing conditions: |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 def test_delete_saml_provider(self): | 157 def test_delete_saml_provider(self): |
| 158 self.set_http_response(status_code=200) | 158 self.set_http_response(status_code=200) |
| 159 response = self.service_connection.delete_saml_provider('arn') | 159 response = self.service_connection.delete_saml_provider('arn') |
| 160 | 160 |
| 161 self.assert_request_parameters( | 161 self.assert_request_parameters( |
| 162 { | 162 { |
| 163 'Action': 'DeleteSAMLProvider', | 163 'Action': 'DeleteSAMLProvider', |
| 164 'SAMLProviderArn': 'arn' | 164 'SAMLProviderArn': 'arn' |
| 165 }, | 165 }, |
| 166 ignore_params_values=['Version']) | 166 ignore_params_values=['Version']) |
| 167 |
| 168 |
| 169 class TestCreateRole(AWSMockServiceTestCase): |
| 170 connection_class = IAMConnection |
| 171 |
| 172 def default_body(self): |
| 173 return """ |
| 174 <CreateRoleResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> |
| 175 <CreateRoleResult> |
| 176 <Role> |
| 177 <Path>/application_abc/component_xyz/</Path> |
| 178 <Arn>arn:aws:iam::123456789012:role/application_abc/component_xy
z/S3Access</Arn> |
| 179 <RoleName>S3Access</RoleName> |
| 180 <AssumeRolePolicyDocument>{"Version":"2012-10-17","Statement":[{
"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},"Action":["sts:As
sumeRole"]}]}</AssumeRolePolicyDocument> |
| 181 <CreateDate>2012-05-08T23:34:01.495Z</CreateDate> |
| 182 <RoleId>AROADBQP57FF2AEXAMPLE</RoleId> |
| 183 </Role> |
| 184 </CreateRoleResult> |
| 185 <ResponseMetadata> |
| 186 <RequestId>4a93ceee-9966-11e1-b624-b1aEXAMPLE7c</RequestId> |
| 187 </ResponseMetadata> |
| 188 </CreateRoleResponse> |
| 189 """ |
| 190 |
| 191 def test_create_role_default(self): |
| 192 self.set_http_response(status_code=200) |
| 193 response = self.service_connection.create_role('a_name') |
| 194 |
| 195 self.assert_request_parameters( |
| 196 {'Action': 'CreateRole', |
| 197 'AssumeRolePolicyDocument': '{"Statement": [{"Action": ["sts:Assume
Role"], "Effect": "Allow", "Principal": {"Service": ["ec2.amazonaws.com"]}}]}', |
| 198 'RoleName': 'a_name'}, |
| 199 ignore_params_values=['Version']) |
| 200 |
| 201 def test_create_role_default_cn_north(self): |
| 202 self.set_http_response(status_code=200) |
| 203 self.service_connection.host = 'iam.cn-north-1.amazonaws.com.cn' |
| 204 response = self.service_connection.create_role('a_name') |
| 205 |
| 206 self.assert_request_parameters( |
| 207 {'Action': 'CreateRole', |
| 208 'AssumeRolePolicyDocument': '{"Statement": [{"Action": ["sts:Assume
Role"], "Effect": "Allow", "Principal": {"Service": ["ec2.amazonaws.com.cn"]}}]}
', |
| 209 'RoleName': 'a_name'}, |
| 210 ignore_params_values=['Version']) |
| 211 |
| 212 def test_create_role_string_policy(self): |
| 213 self.set_http_response(status_code=200) |
| 214 response = self.service_connection.create_role( |
| 215 'a_name', |
| 216 # Historical usage. |
| 217 assume_role_policy_document='{"hello": "policy"}' |
| 218 ) |
| 219 |
| 220 self.assert_request_parameters( |
| 221 {'Action': 'CreateRole', |
| 222 'AssumeRolePolicyDocument': '{"hello": "policy"}', |
| 223 'RoleName': 'a_name'}, |
| 224 ignore_params_values=['Version']) |
| 225 |
| 226 def test_create_role_data_policy(self): |
| 227 self.set_http_response(status_code=200) |
| 228 response = self.service_connection.create_role( |
| 229 'a_name', |
| 230 # With plain data, we should dump it for them. |
| 231 assume_role_policy_document={"hello": "policy"} |
| 232 ) |
| 233 |
| 234 self.assert_request_parameters( |
| 235 {'Action': 'CreateRole', |
| 236 'AssumeRolePolicyDocument': '{"hello": "policy"}', |
| 237 'RoleName': 'a_name'}, |
| 238 ignore_params_values=['Version']) |
| 239 |
| 240 |
| 241 class TestGetSigninURL(AWSMockServiceTestCase): |
| 242 connection_class = IAMConnection |
| 243 |
| 244 def default_body(self): |
| 245 return """ |
| 246 <ListAccountAliasesResponse> |
| 247 <ListAccountAliasesResult> |
| 248 <IsTruncated>false</IsTruncated> |
| 249 <AccountAliases> |
| 250 <member>foocorporation</member> |
| 251 <member>anotherunused</member> |
| 252 </AccountAliases> |
| 253 </ListAccountAliasesResult> |
| 254 <ResponseMetadata> |
| 255 <RequestId>c5a076e9-f1b0-11df-8fbe-45274EXAMPLE</RequestId> |
| 256 </ResponseMetadata> |
| 257 </ListAccountAliasesResponse> |
| 258 """ |
| 259 |
| 260 def test_get_signin_url_default(self): |
| 261 self.set_http_response(status_code=200) |
| 262 url = self.service_connection.get_signin_url() |
| 263 self.assertEqual( |
| 264 url, |
| 265 'https://foocorporation.signin.aws.amazon.com/console/ec2' |
| 266 ) |
| 267 |
| 268 def test_get_signin_url_s3(self): |
| 269 self.set_http_response(status_code=200) |
| 270 url = self.service_connection.get_signin_url(service='s3') |
| 271 self.assertEqual( |
| 272 url, |
| 273 'https://foocorporation.signin.aws.amazon.com/console/s3' |
| 274 ) |
| 275 |
| 276 def test_get_signin_url_cn_north(self): |
| 277 self.set_http_response(status_code=200) |
| 278 self.service_connection.host = 'iam.cn-north-1.amazonaws.com.cn' |
| 279 url = self.service_connection.get_signin_url() |
| 280 self.assertEqual( |
| 281 url, |
| 282 'https://foocorporation.signin.aws.amazon.com/console/ec2' |
| 283 ) |
| 284 |
| 285 |
| 286 class TestGetSigninURL(AWSMockServiceTestCase): |
| 287 connection_class = IAMConnection |
| 288 |
| 289 def default_body(self): |
| 290 return """ |
| 291 <ListAccountAliasesResponse> |
| 292 <ListAccountAliasesResult> |
| 293 <IsTruncated>false</IsTruncated> |
| 294 <AccountAliases></AccountAliases> |
| 295 </ListAccountAliasesResult> |
| 296 <ResponseMetadata> |
| 297 <RequestId>c5a076e9-f1b0-11df-8fbe-45274EXAMPLE</RequestId> |
| 298 </ResponseMetadata> |
| 299 </ListAccountAliasesResponse> |
| 300 """ |
| 301 |
| 302 def test_get_signin_url_no_aliases(self): |
| 303 self.set_http_response(status_code=200) |
| 304 |
| 305 with self.assertRaises(Exception): |
| 306 self.service_connection.get_signin_url() |
| OLD | NEW |