2
2
3
3
namespace AsyncAws \Core \Tests \Integration ;
4
4
5
+ use AsyncAws \Core \Credentials \Credentials ;
5
6
use AsyncAws \Core \Credentials \NullProvider ;
6
7
use AsyncAws \Core \Sts \Input \AssumeRoleRequest ;
7
8
use AsyncAws \Core \Sts \Input \AssumeRoleWithWebIdentityRequest ;
8
9
use AsyncAws \Core \Sts \Input \GetCallerIdentityRequest ;
9
- use AsyncAws \Core \Sts \Input \PolicyDescriptorType ;
10
- use AsyncAws \Core \Sts \Input \Tag ;
11
10
use AsyncAws \Core \Sts \StsClient ;
11
+ use AsyncAws \Core \Sts \ValueObject \PolicyDescriptorType ;
12
+ use AsyncAws \Core \Sts \ValueObject \Tag ;
12
13
use AsyncAws \Core \Test \TestCase ;
13
14
14
15
class StsClientTest extends TestCase
@@ -18,72 +19,66 @@ public function testAssumeRole(): void
18
19
$ client = $ this ->getClient ();
19
20
20
21
$ input = new AssumeRoleRequest ([
21
- 'RoleArn ' => 'change me ' ,
22
- 'RoleSessionName ' => 'change me ' ,
22
+ 'RoleArn ' => 'arn:aws::iam::123456789012:role/demo ' ,
23
+ 'RoleSessionName ' => 'John-session ' ,
23
24
'PolicyArns ' => [new PolicyDescriptorType ([
24
- 'arn ' => 'change me ' ,
25
+ 'arn ' => 'arn:aws::iam::123456789012:policy/demo ' ,
25
26
])],
26
- 'Policy ' => 'change me ' ,
27
- 'DurationSeconds ' => 1337 ,
27
+ 'Policy ' => '{"Version":"2012-10-17","Statement":[{"Sid": "Stmt1","Effect": "Allow","Action": "s3:*","Resource": "*"}]} ' ,
28
+ 'DurationSeconds ' => 300 ,
28
29
'Tags ' => [new Tag ([
29
- 'Key ' => 'change me ' ,
30
- 'Value ' => 'change me ' ,
30
+ 'Key ' => 'Project ' ,
31
+ 'Value ' => 'Pegasus ' ,
31
32
])],
32
- 'TransitiveTagKeys ' => ['change me ' ],
33
- 'ExternalId ' => 'change me ' ,
34
- 'SerialNumber ' => 'change me ' ,
33
+ 'TransitiveTagKeys ' => ['Project ' , ' Cost-Center ' ],
34
+ 'ExternalId ' => '123ABC ' ,
35
+ 'SerialNumber ' => '12345678 ' ,
35
36
'TokenCode ' => 'change me ' ,
36
37
]);
37
38
$ result = $ client ->AssumeRole ($ input );
38
39
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 ());
44
45
}
45
46
46
47
public function testAssumeRoleWithWebIdentity (): void
47
48
{
48
49
$ client = $ this ->getClient ();
49
50
50
51
$ 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 ' ,
55
56
'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 ' ,
57
60
])],
58
- 'Policy ' => 'change me ' ,
59
- 'DurationSeconds ' => 1337 ,
61
+ 'DurationSeconds ' => 300 ,
60
62
]);
61
63
$ result = $ client ->AssumeRoleWithWebIdentity ($ input );
62
64
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 ());
71
70
}
72
71
73
72
public function testGetCallerIdentity (): void
74
73
{
75
74
$ client = $ this ->getClient ();
76
75
77
- $ input = new GetCallerIdentityRequest ([
78
-
79
- ]);
76
+ $ input = new GetCallerIdentityRequest ();
80
77
$ result = $ client ->GetCallerIdentity ($ input );
81
78
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 ());
87
82
}
88
83
89
84
public function testNonAwsRegionWithCustomEndpoint (): void
@@ -127,10 +122,8 @@ public function testCustomEndpointSignature(): void
127
122
128
123
private function getClient (): StsClient
129
124
{
130
- self ::markTestSkipped ('No Docker image for STS ' );
131
-
132
125
return new StsClient ([
133
- 'endpoint ' => 'http://localhost ' ,
134
- ], new NullProvider ( ));
126
+ 'endpoint ' => 'http://localhost:4566 ' ,
127
+ ], new Credentials ( ' aws_id ' , ' aws_secret ' ));
135
128
}
136
129
}
0 commit comments