From f68b2963db4ac7b8f0943d8b9ea101fdcbd451a5 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Wed, 18 Jan 2017 19:59:04 -0800 Subject: [PATCH] sts: Implement get_caller_identity (#806) Return a canned response Signed-off-by: Andrew Harris --- moto/sts/responses.py | 15 +++++++++++++++ tests/test_sts/test_server.py | 11 +++++++++++ tests/test_sts/test_sts.py | 9 +++++++++ 3 files changed, 35 insertions(+) diff --git a/moto/sts/responses.py b/moto/sts/responses.py index 193085623..d721bfaaa 100644 --- a/moto/sts/responses.py +++ b/moto/sts/responses.py @@ -39,6 +39,9 @@ class TokenResponse(BaseResponse): template = self.response_template(ASSUME_ROLE_RESPONSE) 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 = """ @@ -95,3 +98,15 @@ ASSUME_ROLE_RESPONSE = """ + + arn:aws:sts::123456789012:user/moto + AKIAIOSFODNN7EXAMPLE + 123456789012 + + + c6104cbe-af31-11e0-8154-cbc7ccf896c7 + + +""" diff --git a/tests/test_sts/test_server.py b/tests/test_sts/test_server.py index fdc6879e9..40260a49f 100644 --- a/tests/test_sts/test_server.py +++ b/tests/test_sts/test_server.py @@ -26,3 +26,14 @@ def test_sts_get_federation_token(): res.status_code.should.equal(200) res.data.should.contain(b"SessionToken") 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") diff --git a/tests/test_sts/test_sts.py b/tests/test_sts/test_sts.py index 067ebcce2..9bd02ce12 100644 --- a/tests/test_sts/test_sts.py +++ b/tests/test_sts/test_sts.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import json import boto +import boto3 from freezegun import freeze_time 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.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')