@@ -43,6 +43,45 @@ describe('Ec2ConnectClient', function () {
43
43
} )
44
44
} )
45
45
46
+ describe ( 'hasProperPolicies' , async function ( ) {
47
+ it ( 'correctly determines if proper policies are included' , async function ( ) {
48
+ async function assertAcceptsPolicies ( policies : IAM . Policy [ ] , expectedResult : boolean ) {
49
+ sinon . stub ( DefaultIamClient . prototype , 'listAttachedRolePolicies' ) . resolves ( policies )
50
+
51
+ const result = await client . hasProperPolicies ( '' )
52
+ assert . strictEqual ( result , expectedResult )
53
+
54
+ sinon . restore ( )
55
+ }
56
+ await assertAcceptsPolicies (
57
+ [ { PolicyName : 'name' } , { PolicyName : 'name2' } , { PolicyName : 'name3' } ] ,
58
+ false
59
+ )
60
+ await assertAcceptsPolicies (
61
+ [
62
+ { PolicyName : 'AmazonSSMManagedInstanceCore' } ,
63
+ { PolicyName : 'AmazonSSMManagedEC2InstanceDefaultPolicy' } ,
64
+ ] ,
65
+ true
66
+ )
67
+ await assertAcceptsPolicies ( [ { PolicyName : 'AmazonSSMManagedEC2InstanceDefaultPolicy' } ] , false )
68
+ await assertAcceptsPolicies ( [ { PolicyName : 'AmazonSSMManagedEC2InstanceDefaultPolicy' } ] , false )
69
+ } )
70
+
71
+ it ( 'throws error when sdk throws error' , async function ( ) {
72
+ sinon . stub ( DefaultIamClient . prototype , 'listAttachedRolePolicies' ) . throws ( new ToolkitError ( 'error' ) )
73
+
74
+ try {
75
+ await client . hasProperPolicies ( '' )
76
+ assert . ok ( false )
77
+ } catch {
78
+ assert . ok ( true )
79
+ }
80
+
81
+ sinon . restore ( )
82
+ } )
83
+ } )
84
+
46
85
describe ( 'isInstanceRunning' , async function ( ) {
47
86
it ( 'only returns true with the instance is running' , async function ( ) {
48
87
sinon . stub ( Ec2Client . prototype , 'getInstanceStatus' ) . callsFake ( async ( input : string ) => input . split ( ':' ) [ 0 ] )
@@ -118,45 +157,6 @@ describe('Ec2ConnectClient', function () {
118
157
} )
119
158
} )
120
159
121
- describe ( 'hasProperPolicies' , async function ( ) {
122
- it ( 'correctly determines if proper policies are included' , async function ( ) {
123
- async function assertAcceptsPolicies ( policies : IAM . Policy [ ] , expectedResult : boolean ) {
124
- sinon . stub ( DefaultIamClient . prototype , 'listAttachedRolePolicies' ) . resolves ( policies )
125
-
126
- const result = await client . hasProperPolicies ( '' )
127
- assert . strictEqual ( result , expectedResult )
128
-
129
- sinon . restore ( )
130
- }
131
- await assertAcceptsPolicies (
132
- [ { PolicyName : 'name' } , { PolicyName : 'name2' } , { PolicyName : 'name3' } ] ,
133
- false
134
- )
135
- await assertAcceptsPolicies (
136
- [
137
- { PolicyName : 'AmazonSSMManagedInstanceCore' } ,
138
- { PolicyName : 'AmazonSSMManagedEC2InstanceDefaultPolicy' } ,
139
- ] ,
140
- true
141
- )
142
- await assertAcceptsPolicies ( [ { PolicyName : 'AmazonSSMManagedEC2InstanceDefaultPolicy' } ] , false )
143
- await assertAcceptsPolicies ( [ { PolicyName : 'AmazonSSMManagedEC2InstanceDefaultPolicy' } ] , false )
144
- } )
145
-
146
- it ( 'throws error when sdk throws error' , async function ( ) {
147
- sinon . stub ( DefaultIamClient . prototype , 'listAttachedRolePolicies' ) . throws ( new ToolkitError ( 'error' ) )
148
-
149
- try {
150
- await client . hasProperPolicies ( '' )
151
- assert . ok ( false )
152
- } catch {
153
- assert . ok ( true )
154
- }
155
-
156
- sinon . restore ( )
157
- } )
158
- } )
159
-
160
160
describe ( 'sendSshKeysToInstance' , async function ( ) {
161
161
it ( 'calls the sdk with the proper parameters' , async function ( ) {
162
162
const sendCommandStub = sinon . stub ( SsmClient . prototype , 'sendCommandAndWait' )
0 commit comments