11const assert = require ( 'assert' ) ;
22const process = require ( 'node:process' ) ;
33const cp = require ( 'child_process' ) ;
4+ const util = require ( 'util' ) ;
5+ const timers = require ( 'timers/promises' ) ;
46const {
57 S3Client,
68 CreateBucketCommand,
@@ -12,6 +14,7 @@ const {
1214const { getSignedUrl } = require ( '@aws-sdk/s3-request-presigner' ) ;
1315const getConfig = require ( '../support/config' ) ;
1416const provideRawOutput = require ( '../../lib/utility/provideRawOutput' ) ;
17+ const provideRawOutputAsync = util . promisify ( provideRawOutput ) ;
1518
1619const random = Math . round ( Math . random ( ) * 100 ) . toString ( ) ;
1720const bucket = `mybucket-${ random } ` ;
@@ -60,49 +63,32 @@ describe('aws-node-sdk v2auth query tests', function testSuite() {
6063 const futureExpiry = Math . floor ( Date . now ( ) / 1000 ) + 604810 ; // 10 seconds more than limit
6164 urlObj . searchParams . set ( 'Expires' , futureExpiry . toString ( ) ) ;
6265 const invalidUrl = urlObj . toString ( ) ;
63- await new Promise ( resolve => {
64- provideRawOutput ( [ '-verbose' , '-X' , 'PUT' , invalidUrl ] , httpCode => {
65- assert . strictEqual ( httpCode , '403 FORBIDDEN' ) ;
66- resolve ( ) ;
67- } ) ;
68- } ) ;
66+ const { httpCode } = await provideRawOutputAsync ( [ '-verbose' , '-X' , 'PUT' , invalidUrl ] ) ;
67+ assert . strictEqual ( httpCode , '403 FORBIDDEN' ) ;
6968 } ) ;
7069
7170 it ( 'should return an error code if request occurs after expiry' , async ( ) => {
7271 const command = new CreateBucketCommand ( { Bucket : bucket } ) ;
7372 const url = await getSignedUrl ( s3 , command , { expiresIn : 1 } ) ;
74- await new Promise ( resolve => {
75- setTimeout ( ( ) => {
76- provideRawOutput ( [ '-verbose' , '-X' , 'PUT' , url ] , httpCode => {
77- assert . strictEqual ( httpCode , '403 FORBIDDEN' ) ;
78- resolve ( ) ;
79- } ) ;
80- } , 1500 ) ;
81- } ) ;
73+ await timers . setTimeout ( 1500 ) ;
74+ const { httpCode } = await provideRawOutputAsync ( [ '-verbose' , '-X' , 'PUT' , url ] ) ;
75+ assert . strictEqual ( httpCode , '403 FORBIDDEN' ) ;
8276 } ) ;
8377
8478 it ( 'should create a bucket' , async ( ) => {
8579 const command = new CreateBucketCommand ( { Bucket : bucket } ) ;
8680 const url = await getSignedUrl ( s3 , command , { expiresIn : almostOutsideTime } ) ;
87- await new Promise ( resolve => {
88- provideRawOutput ( [ '-verbose' , '-X' , 'PUT' , url ] , httpCode => {
89- assert . strictEqual ( httpCode , '200 OK' ) ;
90- resolve ( ) ;
91- } ) ;
92- } ) ;
81+ const { httpCode } = await provideRawOutputAsync ( [ '-verbose' , '-X' , 'PUT' , url ] ) ;
82+ assert . strictEqual ( httpCode , '200 OK' ) ;
9383 } ) ;
9484
9585
9686 it ( 'should put an object' , async ( ) => {
9787 const command = new PutObjectCommand ( { Bucket : bucket , Key : 'key' } ) ;
9888 const url = await getSignedUrl ( s3 , command , { expiresIn : almostOutsideTime } ) ;
99- await new Promise ( resolve => {
100- provideRawOutput ( [ '-verbose' , '-X' , 'PUT' , url ,
101- '--upload-file' , 'uploadFile' ] , httpCode => {
102- assert . strictEqual ( httpCode , '200 OK' ) ;
103- resolve ( ) ;
104- } ) ;
105- } ) ;
89+ const { httpCode } = await provideRawOutputAsync ( [ '-verbose' , '-X' , 'PUT' , url ,
90+ '--upload-file' , 'uploadFile' ] ) ;
91+ assert . strictEqual ( httpCode , '200 OK' ) ;
10692 } ) ;
10793
10894 it ( 'should put an object with an acl setting and a storage class setting' , async ( ) => {
@@ -118,25 +104,17 @@ describe('aws-node-sdk v2auth query tests', function testSuite() {
118104 StorageClass : 'STANDARD'
119105 } ) ;
120106 const url = await getSignedUrl ( s3 , command ) ;
121- await new Promise ( resolve => {
122- provideRawOutput ( [ '-verbose' , '-X' , 'PUT' , url ,
123- '--upload-file' , 'uploadFile' ] , httpCode => {
124- assert . strictEqual ( httpCode , '200 OK' ) ;
125- resolve ( ) ;
126- } ) ;
127- } ) ;
107+ const { httpCode } = await provideRawOutputAsync ( [ '-verbose' , '-X' , 'PUT' , url ,
108+ '--upload-file' , 'uploadFile' ] ) ;
109+ assert . strictEqual ( httpCode , '200 OK' ) ;
128110 } ) ;
129111
130112
131113 it ( 'should get an object' , async ( ) => {
132114 const command = new GetObjectCommand ( { Bucket : bucket , Key : 'key' } ) ;
133115 const url = await getSignedUrl ( s3 , command , { expiresIn : almostOutsideTime } ) ;
134- await new Promise ( resolve => {
135- provideRawOutput ( [ '-verbose' , '-o' , 'download' , url ] , httpCode => {
136- assert . strictEqual ( httpCode , '200 OK' ) ;
137- resolve ( ) ;
138- } ) ;
139- } ) ;
116+ const { httpCode } = await provideRawOutputAsync ( [ '-verbose' , '-o' , 'download' , url ] ) ;
117+ assert . strictEqual ( httpCode , '200 OK' ) ;
140118 } ) ;
141119
142120 it ( 'downloaded file should equal file that was put' , done => {
@@ -148,23 +126,15 @@ describe('aws-node-sdk v2auth query tests', function testSuite() {
148126 it ( 'should delete an object' , async ( ) => {
149127 const command = new DeleteObjectCommand ( { Bucket : bucket , Key : 'key' } ) ;
150128 const url = await getSignedUrl ( s3 , command , { expiresIn : almostOutsideTime } ) ;
151- await new Promise ( resolve => {
152- provideRawOutput ( [ '-verbose' , '-X' , 'DELETE' , url ] , httpCode => {
153- assert . strictEqual ( httpCode , '204 NO CONTENT' ) ;
154- resolve ( ) ;
155- } ) ;
156- } ) ;
129+ const { httpCode } = await provideRawOutputAsync ( [ '-verbose' , '-X' , 'DELETE' , url ] ) ;
130+ assert . strictEqual ( httpCode , '204 NO CONTENT' ) ;
157131 } ) ;
158132
159133
160134 it ( 'should delete a bucket' , async ( ) => {
161135 const command = new DeleteBucketCommand ( { Bucket : bucket } ) ;
162136 const url = await getSignedUrl ( s3 , command , { expiresIn : almostOutsideTime } ) ;
163- await new Promise ( resolve => {
164- provideRawOutput ( [ '-verbose' , '-X' , 'DELETE' , url ] , httpCode => {
165- assert . strictEqual ( httpCode , '204 NO CONTENT' ) ;
166- resolve ( ) ;
167- } ) ;
168- } ) ;
137+ const { httpCode } = await provideRawOutputAsync ( [ '-verbose' , '-X' , 'DELETE' , url ] ) ;
138+ assert . strictEqual ( httpCode , '204 NO CONTENT' ) ;
169139 } ) ;
170140} ) ;
0 commit comments