@@ -33,15 +33,9 @@ const testAPIs = [
3333 } ,
3434] ;
3535
36- function checkResponseAsync ( credentials , bucket , object ) {
36+ function checkResponseAsync ( checkResponseFn , credentials , bucket , object ) {
3737 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 ) => {
4539 if ( err ) {
4640 reject ( err ) ;
4741 return ;
@@ -91,7 +85,7 @@ testAPIs.forEach(testAPI => {
9185 it (
9286 `should not be able to ${ testAPI . API } without the permission s3:${ testAPI . API } ` ,
9387 async ( ) => {
94- const res = await checkResponseAsync ( userCredentials , bucketName , objectName ) ;
88+ const res = await checkResponseAsync ( testAPI . checkResponse , userCredentials , bucketName , objectName ) ;
9589 assert . strictEqual ( res . statusCode , 403 ) ;
9690 assert . strictEqual ( res . code , errors . AccessDenied . message ) ;
9791 } ,
@@ -109,7 +103,7 @@ testAPIs.forEach(testAPI => {
109103 UserName : userName ,
110104 PolicyArn : res . Policy . Arn ,
111105 } ) ) ;
112- const res2 = await checkResponseAsync ( userCredentials , bucketName , objectName ) ;
106+ const res2 = await checkResponseAsync ( testAPI . checkResponse , userCredentials , bucketName , objectName ) ;
113107 if ( testAPI . API === 'RestoreObject' ) {
114108 assert . strictEqual ( res2 . statusCode , 403 ) ;
115109 assert . strictEqual ( res2 . code , errors . InvalidObjectState . message ) ;
@@ -138,14 +132,14 @@ testAPIs.forEach(testAPI => {
138132 } ) ) ;
139133 policyArns . push ( res . Policy . Arn ) ;
140134 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 ) ;
142136 if ( testAPI . API === 'RestoreObject' ) {
143137 assert . strictEqual ( res2 . statusCode , 403 ) ;
144138 assert . strictEqual ( res2 . code , errors . InvalidObjectState . message ) ;
145139 } else {
146140 assert . strictEqual ( res2 . statusCode , 200 ) ;
147141 }
148- const res3 = await checkResponseAsync ( userCredentials , bucketName2 , objectName2 ) ;
142+ const res3 = await checkResponseAsync ( testAPI . checkResponse , userCredentials , bucketName2 , objectName2 ) ;
149143 assert . strictEqual ( res3 . statusCode , 403 ) ;
150144 assert . strictEqual ( res3 . code , errors . AccessDenied . message ) ;
151145 } finally {
@@ -165,7 +159,7 @@ testAPIs.forEach(testAPI => {
165159 } ) ) ;
166160 policyArns . push ( res . Policy . Arn ) ;
167161 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 ) ;
169163 assert . strictEqual ( res2 . statusCode , 403 ) ;
170164 assert . strictEqual ( res2 . code , errors . AccessDenied . message ) ;
171165 } finally {
@@ -195,10 +189,10 @@ testAPIs.forEach(testAPI => {
195189 } ) ) ;
196190 policyArns . push ( res2 . Policy . Arn ) ;
197191 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 ) ;
199193 assert . strictEqual ( res3 . statusCode , 403 ) ;
200194 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 ) ;
202196 if ( testAPI . API === 'RestoreObject' ) {
203197 assert . strictEqual ( res4 . statusCode , 403 ) ;
204198 assert . strictEqual ( res4 . code , errors . InvalidObjectState . message ) ;
0 commit comments