22
33namespace AsyncAws \Core \Tests \Integration ;
44
5+ use AsyncAws \Core \Credentials \Credentials ;
56use AsyncAws \Core \Credentials \NullProvider ;
67use AsyncAws \Core \Sts \Input \AssumeRoleRequest ;
78use AsyncAws \Core \Sts \Input \AssumeRoleWithWebIdentityRequest ;
89use AsyncAws \Core \Sts \Input \GetCallerIdentityRequest ;
9- use AsyncAws \Core \Sts \Input \PolicyDescriptorType ;
10- use AsyncAws \Core \Sts \Input \Tag ;
1110use AsyncAws \Core \Sts \StsClient ;
11+ use AsyncAws \Core \Sts \ValueObject \PolicyDescriptorType ;
12+ use AsyncAws \Core \Sts \ValueObject \Tag ;
1213use AsyncAws \Core \Test \TestCase ;
1314
1415class StsClientTest extends TestCase
@@ -18,72 +19,66 @@ public function testAssumeRole(): void
1819 $ client = $ this ->getClient ();
1920
2021 $ input = new AssumeRoleRequest ([
21- 'RoleArn ' => 'change me ' ,
22- 'RoleSessionName ' => 'change me ' ,
22+ 'RoleArn ' => 'arn:aws::iam::123456789012:role/demo ' ,
23+ 'RoleSessionName ' => 'John-session ' ,
2324 'PolicyArns ' => [new PolicyDescriptorType ([
24- 'arn ' => 'change me ' ,
25+ 'arn ' => 'arn:aws::iam::123456789012:policy/demo ' ,
2526 ])],
26- 'Policy ' => 'change me ' ,
27- 'DurationSeconds ' => 1337 ,
27+ 'Policy ' => '{"Version":"2012-10-17","Statement":[{"Sid": "Stmt1","Effect": "Allow","Action": "s3:*","Resource": "*"}]} ' ,
28+ 'DurationSeconds ' => 300 ,
2829 'Tags ' => [new Tag ([
29- 'Key ' => 'change me ' ,
30- 'Value ' => 'change me ' ,
30+ 'Key ' => 'Project ' ,
31+ 'Value ' => 'Pegasus ' ,
3132 ])],
32- 'TransitiveTagKeys ' => ['change me ' ],
33- 'ExternalId ' => 'change me ' ,
34- 'SerialNumber ' => 'change me ' ,
33+ 'TransitiveTagKeys ' => ['Project ' , ' Cost-Center ' ],
34+ 'ExternalId ' => '123ABC ' ,
35+ 'SerialNumber ' => '12345678 ' ,
3536 'TokenCode ' => 'change me ' ,
3637 ]);
3738 $ result = $ client ->AssumeRole ($ input );
3839
39- $ result ->resolve ( );
40-
41- // self::assertTODO(expected, $result->getCredentials ());
42- // self::assertTODO(expected , $result->getAssumedRoleUser());
43- self ::assertSame (1337 , $ result ->getPackedPolicySize ());
40+ self :: assertNotNull ( $ result ->getCredentials () );
41+ self :: assertLessThanOrEqual ( new \ DateTime ( ' +5min ' ), $ result -> getCredentials ()-> getExpiration ());
42+ self ::assertNotNull ( $ result ->getAssumedRoleUser ());
43+ self ::assertSame ( ' arn:aws:sts::000000000000:assumed-role/demo/John-session ' , $ result ->getAssumedRoleUser ()-> getArn ());
44+ self ::assertSame (6 , $ result ->getPackedPolicySize ());
4445 }
4546
4647 public function testAssumeRoleWithWebIdentity (): void
4748 {
4849 $ client = $ this ->getClient ();
4950
5051 $ input = new AssumeRoleWithWebIdentityRequest ([
51- 'RoleArn ' => 'change me ' ,
52- 'RoleSessionName ' => 'change me ' ,
53- 'WebIdentityToken ' => 'change me ' ,
54- 'ProviderId ' => 'change me ' ,
52+ 'RoleArn ' => 'arn:aws:iam::123456789012:role/FederatedWebIdentityRole ' ,
53+ 'RoleSessionName ' => 'app1 ' ,
54+ 'WebIdentityToken ' => 'FooBarBaz ' ,
55+ 'ProviderId ' => 'www.amazon.com ' ,
5556 'PolicyArns ' => [new PolicyDescriptorType ([
56- 'arn ' => 'change me ' ,
57+ 'arn ' => 'arn:aws:iam::123456789012:policy/q=webidentitydemopolicy1 ' ,
58+ ]), new PolicyDescriptorType ([
59+ 'arn ' => 'arn:aws:iam::123456789012:policy/webidentitydemopolicy2 ' ,
5760 ])],
58- 'Policy ' => 'change me ' ,
59- 'DurationSeconds ' => 1337 ,
61+ 'DurationSeconds ' => 300 ,
6062 ]);
6163 $ result = $ client ->AssumeRoleWithWebIdentity ($ input );
6264
63- $ result ->resolve ();
64-
65- // self::assertTODO(expected, $result->getCredentials());
66- self ::assertSame ('changeIt ' , $ result ->getSubjectFromWebIdentityToken ());
67- // self::assertTODO(expected, $result->getAssumedRoleUser());
68- self ::assertSame (1337 , $ result ->getPackedPolicySize ());
69- self ::assertSame ('changeIt ' , $ result ->getProvider ());
70- self ::assertSame ('changeIt ' , $ result ->getAudience ());
65+ self ::assertNotNull ($ result ->getCredentials ());
66+ self ::assertLessThanOrEqual (new \DateTime ('+5min ' ), $ result ->getCredentials ()->getExpiration ());
67+ self ::assertNotNull ($ result ->getAssumedRoleUser ());
68+ self ::assertSame ('arn:aws:sts::000000000000:assumed-role/FederatedWebIdentityRole/app1 ' , $ result ->getAssumedRoleUser ()->getArn ());
69+ self ::assertSame (6 , $ result ->getPackedPolicySize ());
7170 }
7271
7372 public function testGetCallerIdentity (): void
7473 {
7574 $ client = $ this ->getClient ();
7675
77- $ input = new GetCallerIdentityRequest ([
78-
79- ]);
76+ $ input = new GetCallerIdentityRequest ();
8077 $ result = $ client ->GetCallerIdentity ($ input );
8178
82- $ result ->resolve ();
83-
84- self ::assertStringContainsString ('change it ' , $ result ->getUserId ());
85- self ::assertStringContainsString ('change it ' , $ result ->getAccount ());
86- self ::assertStringContainsString ('change it ' , $ result ->getArn ());
79+ self ::assertNotNull ($ result ->getUserId ());
80+ self ::assertStringContainsString ('000000000000 ' , $ result ->getAccount ());
81+ self ::assertStringContainsString ('arn:aws:sts::000000000000:user/moto ' , $ result ->getArn ());
8782 }
8883
8984 public function testNonAwsRegionWithCustomEndpoint (): void
@@ -127,10 +122,8 @@ public function testCustomEndpointSignature(): void
127122
128123 private function getClient (): StsClient
129124 {
130- self ::markTestSkipped ('No Docker image for STS ' );
131-
132125 return new StsClient ([
133- 'endpoint ' => 'http://localhost ' ,
134- ], new NullProvider ( ));
126+ 'endpoint ' => 'http://localhost:4566 ' ,
127+ ], new Credentials ( ' aws_id ' , ' aws_secret ' ));
135128 }
136129}
0 commit comments