@@ -12,9 +12,15 @@ import { mockBootstrapStack, MockSdk, MockSdkProvider } from '../util/mock-sdk';
12
12
let bootstrapper : Bootstrapper ;
13
13
let mockGetPolicyIamCode : ( params : IAM . Types . GetPolicyRequest ) => IAM . Types . GetPolicyResponse ;
14
14
let mockCreatePolicyIamCode : ( params : IAM . Types . CreatePolicyRequest ) => IAM . Types . CreatePolicyResponse ;
15
+ let stderrMock : jest . SpyInstance ;
15
16
16
17
beforeEach ( ( ) => {
17
18
bootstrapper = new Bootstrapper ( { source : 'default' } ) ;
19
+ stderrMock = jest . spyOn ( process . stderr , 'write' ) . mockImplementation ( ( ) => { return true ; } ) ;
20
+ } ) ;
21
+
22
+ afterEach ( ( ) => {
23
+ stderrMock . mockRestore ( ) ;
18
24
} ) ;
19
25
20
26
function mockTheToolkitInfo ( stackProps : Partial < AWS . CloudFormation . Stack > ) {
@@ -114,6 +120,14 @@ describe('Bootstrapping v2', () => {
114
120
} ) ;
115
121
116
122
test ( 'passes value to PermissionsBoundary' , async ( ) => {
123
+ mockTheToolkitInfo ( {
124
+ Parameters : [
125
+ {
126
+ ParameterKey : 'InputPermissionsBoundary' ,
127
+ ParameterValue : 'existing-pb' ,
128
+ } ,
129
+ ] ,
130
+ } ) ;
117
131
await bootstrapper . bootstrapEnvironment ( env , sdk , {
118
132
parameters : {
119
133
customPermissionsBoundary : 'permissions-boundary-name' ,
@@ -125,6 +139,71 @@ describe('Bootstrapping v2', () => {
125
139
InputPermissionsBoundary : 'permissions-boundary-name' ,
126
140
} ) ,
127
141
} ) ) ;
142
+ expect ( stderrMock . mock . calls ) . toEqual ( expect . arrayContaining ( [
143
+ expect . arrayContaining ( [
144
+ expect . stringMatching ( / C h a n g i n g p e r m i s s i o n s b o u n d a r y f r o m e x i s t i n g - p b t o p e r m i s s i o n s - b o u n d a r y - n a m e / ) ,
145
+ ] ) ,
146
+ ] ) ) ;
147
+ } ) ;
148
+
149
+ test ( 'permission boundary switch message does not appear' , async ( ) => {
150
+ mockTheToolkitInfo ( {
151
+ Parameters : [
152
+ {
153
+ ParameterKey : 'InputPermissionsBoundary' ,
154
+ ParameterValue : '' ,
155
+ } ,
156
+ ] ,
157
+ } ) ;
158
+ await bootstrapper . bootstrapEnvironment ( env , sdk ) ;
159
+
160
+ expect ( stderrMock . mock . calls ) . toEqual ( expect . arrayContaining ( [
161
+ expect . not . arrayContaining ( [
162
+ expect . stringMatching ( / C h a n g i n g p e r m i s s i o n s b o u n d a r y / ) ,
163
+ ] ) ,
164
+ ] ) ) ;
165
+ } ) ;
166
+
167
+ test ( 'adding new permissions boundary' , async ( ) => {
168
+ mockTheToolkitInfo ( {
169
+ Parameters : [
170
+ {
171
+ ParameterKey : 'InputPermissionsBoundary' ,
172
+ ParameterValue : '' ,
173
+ } ,
174
+ ] ,
175
+ } ) ;
176
+ await bootstrapper . bootstrapEnvironment ( env , sdk , {
177
+ parameters : {
178
+ customPermissionsBoundary : 'permissions-boundary-name' ,
179
+ } ,
180
+ } ) ;
181
+
182
+ expect ( stderrMock . mock . calls ) . toEqual ( expect . arrayContaining ( [
183
+ expect . arrayContaining ( [
184
+ expect . stringMatching ( / A d d i n g n e w p e r m i s s i o n s b o u n d a r y p e r m i s s i o n s - b o u n d a r y - n a m e / ) ,
185
+ ] ) ,
186
+ ] ) ) ;
187
+ } ) ;
188
+
189
+ test ( 'removing existing permissions boundary' , async ( ) => {
190
+ mockTheToolkitInfo ( {
191
+ Parameters : [
192
+ {
193
+ ParameterKey : 'InputPermissionsBoundary' ,
194
+ ParameterValue : 'permissions-boundary-name' ,
195
+ } ,
196
+ ] ,
197
+ } ) ;
198
+ await bootstrapper . bootstrapEnvironment ( env , sdk , {
199
+ parameters : { } ,
200
+ } ) ;
201
+
202
+ expect ( stderrMock . mock . calls ) . toEqual ( expect . arrayContaining ( [
203
+ expect . arrayContaining ( [
204
+ expect . stringMatching ( / R e m o v i n g e x i s t i n g p e r m i s s i o n s b o u n d a r y p e r m i s s i o n s - b o u n d a r y - n a m e / ) ,
205
+ ] ) ,
206
+ ] ) ) ;
128
207
} ) ;
129
208
130
209
test ( 'passing trusted accounts without CFN managed policies results in an error' , async ( ) => {
0 commit comments