sts: Implement get_caller_identity (#806)

Return a canned response

Signed-off-by: Andrew Harris <andrew.harris@getbraintree.com>
This commit is contained in:
Jesse Szwedko 2017-01-18 19:59:04 -08:00 committed by Steve Pulec
parent 55f39265dd
commit f68b2963db
3 changed files with 35 additions and 0 deletions

View File

@ -39,6 +39,9 @@ class TokenResponse(BaseResponse):
template = self.response_template(ASSUME_ROLE_RESPONSE) template = self.response_template(ASSUME_ROLE_RESPONSE)
return template.render(role=role) return template.render(role=role)
def get_caller_identity(self):
template = self.response_template(GET_CALLER_IDENTITY_RESPONSE)
return template.render()
GET_SESSION_TOKEN_RESPONSE = """<GetSessionTokenResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/"> GET_SESSION_TOKEN_RESPONSE = """<GetSessionTokenResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
<GetSessionTokenResult> <GetSessionTokenResult>
@ -95,3 +98,15 @@ ASSUME_ROLE_RESPONSE = """<AssumeRoleResponse xmlns="https://sts.amazonaws.com/d
<RequestId>c6104cbe-af31-11e0-8154-cbc7ccf896c7</RequestId> <RequestId>c6104cbe-af31-11e0-8154-cbc7ccf896c7</RequestId>
</ResponseMetadata> </ResponseMetadata>
</AssumeRoleResponse>""" </AssumeRoleResponse>"""
GET_CALLER_IDENTITY_RESPONSE = """<GetCallerIdentityResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
<GetCallerIdentityResult>
<Arn>arn:aws:sts::123456789012:user/moto</Arn>
<UserId>AKIAIOSFODNN7EXAMPLE</UserId>
<Account>123456789012</Account>
</GetCallerIdentityResult>
<ResponseMetadata>
<RequestId>c6104cbe-af31-11e0-8154-cbc7ccf896c7</RequestId>
</ResponseMetadata>
</GetCallerIdentityResponse>
"""

View File

@ -26,3 +26,14 @@ def test_sts_get_federation_token():
res.status_code.should.equal(200) res.status_code.should.equal(200)
res.data.should.contain(b"SessionToken") res.data.should.contain(b"SessionToken")
res.data.should.contain(b"AccessKeyId") res.data.should.contain(b"AccessKeyId")
def test_sts_get_caller_identity():
backend = server.create_backend_app("sts")
test_client = backend.test_client()
res = test_client.get('/?Action=GetCallerIdentity')
res.status_code.should.equal(200)
res.data.should.contain(b"Arn")
res.data.should.contain(b"UserId")
res.data.should.contain(b"Account")

View File

@ -2,6 +2,7 @@ from __future__ import unicode_literals
import json import json
import boto import boto
import boto3
from freezegun import freeze_time from freezegun import freeze_time
import sure # noqa import sure # noqa
@ -64,3 +65,11 @@ def test_assume_role():
role.user.arn.should.equal("arn:aws:iam::123456789012:role/test-role") role.user.arn.should.equal("arn:aws:iam::123456789012:role/test-role")
role.user.assume_role_id.should.contain("session-name") role.user.assume_role_id.should.contain("session-name")
@mock_sts
def test_get_caller_identity():
identity = boto3.client("sts").get_caller_identity()
identity['Arn'].should.equal('arn:aws:sts::123456789012:user/moto')
identity['UserId'].should.equal('AKIAIOSFODNN7EXAMPLE')
identity['Account'].should.equal('123456789012')