@@ -33,15 +33,9 @@ const testAPIs = [
33
33
} ,
34
34
] ;
35
35
36
- function checkResponseAsync ( credentials , bucket , object ) {
36
+ function checkResponseAsync ( checkResponseFn , credentials , bucket , object ) {
37
37
return new Promise ( ( resolve , reject ) => {
38
- // Use the appropriate test API based on current context
39
- const currentTestAPI = testAPIs . find ( api => bucket . includes ( api . API . toLowerCase ( ) ) ) ;
40
- if ( ! currentTestAPI ) {
41
- reject ( new Error ( 'Could not determine test API' ) ) ;
42
- return ;
43
- }
44
- currentTestAPI . checkResponse ( credentials , bucket , ( err , res ) => {
38
+ checkResponseFn ( credentials , bucket , ( err , res ) => {
45
39
if ( err ) {
46
40
reject ( err ) ;
47
41
return ;
@@ -91,7 +85,7 @@ testAPIs.forEach(testAPI => {
91
85
it (
92
86
`should not be able to ${ testAPI . API } without the permission s3:${ testAPI . API } ` ,
93
87
async ( ) => {
94
- const res = await checkResponseAsync ( userCredentials , bucketName , objectName ) ;
88
+ const res = await checkResponseAsync ( testAPI . checkResponse , userCredentials , bucketName , objectName ) ;
95
89
assert . strictEqual ( res . statusCode , 403 ) ;
96
90
assert . strictEqual ( res . code , errors . AccessDenied . message ) ;
97
91
} ,
@@ -109,7 +103,7 @@ testAPIs.forEach(testAPI => {
109
103
UserName : userName ,
110
104
PolicyArn : res . Policy . Arn ,
111
105
} ) ) ;
112
- const res2 = await checkResponseAsync ( userCredentials , bucketName , objectName ) ;
106
+ const res2 = await checkResponseAsync ( testAPI . checkResponse , userCredentials , bucketName , objectName ) ;
113
107
if ( testAPI . API === 'RestoreObject' ) {
114
108
assert . strictEqual ( res2 . statusCode , 403 ) ;
115
109
assert . strictEqual ( res2 . code , errors . InvalidObjectState . message ) ;
@@ -138,14 +132,14 @@ testAPIs.forEach(testAPI => {
138
132
} ) ) ;
139
133
policyArns . push ( res . Policy . Arn ) ;
140
134
await iam . send ( new AttachUserPolicyCommand ( { UserName : userName , PolicyArn : res . Policy . Arn } ) ) ;
141
- const res2 = await checkResponseAsync ( userCredentials , bucketName , objectName ) ;
135
+ const res2 = await checkResponseAsync ( testAPI . checkResponse , userCredentials , bucketName , objectName ) ;
142
136
if ( testAPI . API === 'RestoreObject' ) {
143
137
assert . strictEqual ( res2 . statusCode , 403 ) ;
144
138
assert . strictEqual ( res2 . code , errors . InvalidObjectState . message ) ;
145
139
} else {
146
140
assert . strictEqual ( res2 . statusCode , 200 ) ;
147
141
}
148
- const res3 = await checkResponseAsync ( userCredentials , bucketName2 , objectName2 ) ;
142
+ const res3 = await checkResponseAsync ( testAPI . checkResponse , userCredentials , bucketName2 , objectName2 ) ;
149
143
assert . strictEqual ( res3 . statusCode , 403 ) ;
150
144
assert . strictEqual ( res3 . code , errors . AccessDenied . message ) ;
151
145
} finally {
@@ -165,7 +159,7 @@ testAPIs.forEach(testAPI => {
165
159
} ) ) ;
166
160
policyArns . push ( res . Policy . Arn ) ;
167
161
await iam . send ( new AttachUserPolicyCommand ( { UserName : userName , PolicyArn : res . Policy . Arn } ) ) ;
168
- const res2 = await checkResponseAsync ( userCredentials , bucketName , objectName ) ;
162
+ const res2 = await checkResponseAsync ( testAPI . checkResponse , userCredentials , bucketName , objectName ) ;
169
163
assert . strictEqual ( res2 . statusCode , 403 ) ;
170
164
assert . strictEqual ( res2 . code , errors . AccessDenied . message ) ;
171
165
} finally {
@@ -195,10 +189,10 @@ testAPIs.forEach(testAPI => {
195
189
} ) ) ;
196
190
policyArns . push ( res2 . Policy . Arn ) ;
197
191
await iam . send ( new AttachUserPolicyCommand ( { UserName : userName , PolicyArn : res2 . Policy . Arn } ) ) ;
198
- const res3 = await checkResponseAsync ( userCredentials , bucketName , objectName ) ;
192
+ const res3 = await checkResponseAsync ( testAPI . checkResponse , userCredentials , bucketName , objectName ) ;
199
193
assert . strictEqual ( res3 . statusCode , 403 ) ;
200
194
assert . strictEqual ( res3 . code , errors . AccessDenied . message ) ;
201
- const res4 = await checkResponseAsync ( userCredentials , bucketName2 , objectName2 ) ;
195
+ const res4 = await checkResponseAsync ( testAPI . checkResponse , userCredentials , bucketName2 , objectName2 ) ;
202
196
if ( testAPI . API === 'RestoreObject' ) {
203
197
assert . strictEqual ( res4 . statusCode , 403 ) ;
204
198
assert . strictEqual ( res4 . code , errors . InvalidObjectState . message ) ;
0 commit comments