@@ -4,8 +4,7 @@ const querystring = require('querystring');
44const { parseString } = require ( 'xml2js' ) ;
55
66const { bucketPut } = require ( '../../../lib/api/bucketPut' ) ;
7- const initiateMultipartUpload
8- = require ( '../../../lib/api/initiateMultipartUpload' ) ;
7+ const initiateMultipartUpload = require ( '../../../lib/api/initiateMultipartUpload' ) ;
98const listMultipartUploads = require ( '../../../lib/api/listMultipartUploads' ) ;
109const { cleanup, DummyRequestLogger, makeAuthInfo } = require ( '../helpers' ) ;
1110
@@ -195,8 +194,7 @@ describe('listMultipartUploads API', () => {
195194 } ) ;
196195 } ) ;
197196
198- it ( 'should return key following specified ' +
199- 'key-marker' , done => {
197+ it ( 'should return key following specified key-marker' , done => {
200198 const testListRequest = {
201199 bucketName,
202200 namespace,
@@ -208,22 +206,161 @@ describe('listMultipartUploads API', () => {
208206
209207 async . waterfall ( [
210208 next => bucketPut ( authInfo , testPutBucketRequest , log , next ) ,
211- ( corsHeaders , next ) => initiateMultipartUpload ( authInfo ,
212- testInitiateMPURequest1 , log , next ) ,
213- ( result , corsHeaders , next ) => initiateMultipartUpload ( authInfo ,
214- testInitiateMPURequest2 , log , next ) ,
215- ( result , corsHeaders , next ) => initiateMultipartUpload ( authInfo ,
216- testInitiateMPURequest3 , log , next ) ,
217- ( result , corsHeaders , next ) => listMultipartUploads ( authInfo ,
218- testListRequest , log , next ) ,
219- ( result , corsHeaders , next ) =>
220- parseString ( result , corsHeaders , next ) ,
209+ ( corsHeaders , next ) => initiateMultipartUpload ( authInfo , testInitiateMPURequest1 , log , next ) ,
210+ ( result , corsHeaders , next ) => initiateMultipartUpload ( authInfo , testInitiateMPURequest2 , log , next ) ,
211+ ( result , corsHeaders , next ) => initiateMultipartUpload ( authInfo , testInitiateMPURequest3 , log , next ) ,
212+ ( result , corsHeaders , next ) => listMultipartUploads ( authInfo , testListRequest , log , next ) ,
213+ ( result , corsHeaders , next ) => parseString ( result , corsHeaders , next ) ,
221214 ] ,
222215 ( err , result ) => {
223- assert . strictEqual ( result . ListMultipartUploadsResult
224- . Upload [ 0 ] . Key [ 0 ] , objectName2 ) ;
225- assert . strictEqual ( result . ListMultipartUploadsResult
226- . Upload [ 1 ] , undefined ) ;
216+ assert . strictEqual ( result . ListMultipartUploadsResult . Upload [ 0 ] . Key [ 0 ] , objectName2 ) ;
217+ assert . strictEqual ( result . ListMultipartUploadsResult . Upload [ 1 ] , undefined ) ;
218+ done ( ) ;
219+ } ) ;
220+ } ) ;
221+
222+ it ( 'should include ChecksumAlgorithm and ChecksumType when set on MPU' , done => {
223+ const checksumKey = 'checksum-object' ;
224+ const testInitChecksumRequest = {
225+ bucketName,
226+ namespace,
227+ objectKey : checksumKey ,
228+ headers : { 'x-amz-checksum-algorithm' : 'CRC32' } ,
229+ url : `/${ bucketName } /${ checksumKey } ?uploads` ,
230+ actionImplicitDenies : false ,
231+ } ;
232+ const testListRequest = {
233+ bucketName,
234+ namespace,
235+ headers : { host : '/' } ,
236+ url : `/${ bucketName } ?uploads` ,
237+ query : { } ,
238+ actionImplicitDenies : false ,
239+ } ;
240+
241+ async . waterfall ( [
242+ next => bucketPut ( authInfo , testPutBucketRequest , log , next ) ,
243+ ( corsHeaders , next ) => initiateMultipartUpload ( authInfo , testInitChecksumRequest , log , next ) ,
244+ ( result , corsHeaders , next ) => listMultipartUploads ( authInfo , testListRequest , log , next ) ,
245+ ( result , corsHeaders , next ) => parseString ( result , corsHeaders , next ) ,
246+ ] ,
247+ ( err , result ) => {
248+ const upload = result . ListMultipartUploadsResult . Upload [ 0 ] ;
249+ assert . strictEqual ( upload . Key [ 0 ] , checksumKey ) ;
250+ assert . strictEqual ( upload . ChecksumAlgorithm [ 0 ] , 'CRC32' ) ;
251+ assert . strictEqual ( upload . ChecksumType [ 0 ] , 'COMPOSITE' ) ;
252+ done ( ) ;
253+ } ) ;
254+ } ) ;
255+
256+ it ( 'should not include ChecksumAlgorithm or ChecksumType when not set on MPU' , done => {
257+ const testListRequest = {
258+ bucketName,
259+ namespace,
260+ headers : { host : '/' } ,
261+ url : `/${ bucketName } ?uploads` ,
262+ query : { } ,
263+ actionImplicitDenies : false ,
264+ } ;
265+
266+ async . waterfall ( [
267+ next => bucketPut ( authInfo , testPutBucketRequest , log , next ) ,
268+ ( corsHeaders , next ) => initiateMultipartUpload ( authInfo , testInitiateMPURequest1 , log , next ) ,
269+ ( result , corsHeaders , next ) => listMultipartUploads ( authInfo , testListRequest , log , next ) ,
270+ ( result , corsHeaders , next ) => parseString ( result , corsHeaders , next ) ,
271+ ] ,
272+ ( err , result ) => {
273+ const upload = result . ListMultipartUploadsResult . Upload [ 0 ] ;
274+ assert . strictEqual ( upload . Key [ 0 ] , objectName1 ) ;
275+ assert . strictEqual ( upload . ChecksumAlgorithm , undefined ) ;
276+ assert . strictEqual ( upload . ChecksumType , undefined ) ;
277+ done ( ) ;
278+ } ) ;
279+ } ) ;
280+
281+ it ( 'should include ChecksumAlgorithm and ChecksumType with explicit type' , done => {
282+ const checksumKey = 'checksum-explicit' ;
283+ const testInitChecksumRequest = {
284+ bucketName,
285+ namespace,
286+ objectKey : checksumKey ,
287+ headers : {
288+ 'x-amz-checksum-algorithm' : 'CRC32' ,
289+ 'x-amz-checksum-type' : 'FULL_OBJECT' ,
290+ } ,
291+ url : `/${ bucketName } /${ checksumKey } ?uploads` ,
292+ actionImplicitDenies : false ,
293+ } ;
294+ const testListRequest = {
295+ bucketName,
296+ namespace,
297+ headers : { host : '/' } ,
298+ url : `/${ bucketName } ?uploads` ,
299+ query : { } ,
300+ actionImplicitDenies : false ,
301+ } ;
302+
303+ async . waterfall ( [
304+ next => bucketPut ( authInfo , testPutBucketRequest , log , next ) ,
305+ ( corsHeaders , next ) => initiateMultipartUpload ( authInfo , testInitChecksumRequest , log , next ) ,
306+ ( result , corsHeaders , next ) => listMultipartUploads ( authInfo , testListRequest , log , next ) ,
307+ ( result , corsHeaders , next ) => parseString ( result , corsHeaders , next ) ,
308+ ] ,
309+ ( err , result ) => {
310+ const upload = result . ListMultipartUploadsResult . Upload [ 0 ] ;
311+ assert . strictEqual ( upload . Key [ 0 ] , checksumKey ) ;
312+ assert . strictEqual ( upload . ChecksumAlgorithm [ 0 ] , 'CRC32' ) ;
313+ assert . strictEqual ( upload . ChecksumType [ 0 ] , 'FULL_OBJECT' ) ;
314+ done ( ) ;
315+ } ) ;
316+ } ) ;
317+
318+ it ( 'should list mixed uploads with and without checksum correctly' , done => {
319+ const checksumKey = 'aaa-checksum-object' ;
320+ const noChecksumKey = 'zzz-no-checksum-object' ;
321+ const testInitChecksumRequest = {
322+ bucketName,
323+ namespace,
324+ objectKey : checksumKey ,
325+ headers : { 'x-amz-checksum-algorithm' : 'SHA256' } ,
326+ url : `/${ bucketName } /${ checksumKey } ?uploads` ,
327+ actionImplicitDenies : false ,
328+ } ;
329+ const testInitNoChecksumRequest = {
330+ bucketName,
331+ namespace,
332+ objectKey : noChecksumKey ,
333+ headers : { } ,
334+ url : `/${ bucketName } /${ noChecksumKey } ?uploads` ,
335+ actionImplicitDenies : false ,
336+ } ;
337+ const testListRequest = {
338+ bucketName,
339+ namespace,
340+ headers : { host : '/' } ,
341+ url : `/${ bucketName } ?uploads` ,
342+ query : { } ,
343+ actionImplicitDenies : false ,
344+ } ;
345+
346+ async . waterfall ( [
347+ next => bucketPut ( authInfo , testPutBucketRequest , log , next ) ,
348+ ( corsHeaders , next ) => initiateMultipartUpload ( authInfo , testInitChecksumRequest , log , next ) ,
349+ ( result , corsHeaders , next ) => initiateMultipartUpload ( authInfo , testInitNoChecksumRequest , log , next ) ,
350+ ( result , corsHeaders , next ) => listMultipartUploads ( authInfo , testListRequest , log , next ) ,
351+ ( result , corsHeaders , next ) => parseString ( result , corsHeaders , next ) ,
352+ ] ,
353+ ( err , result ) => {
354+ const uploads = result . ListMultipartUploadsResult . Upload ;
355+ assert . strictEqual ( uploads . length , 2 ) ;
356+
357+ const withChecksum = uploads . find ( u => u . Key [ 0 ] === checksumKey ) ;
358+ assert . strictEqual ( withChecksum . ChecksumAlgorithm [ 0 ] , 'SHA256' ) ;
359+ assert . strictEqual ( withChecksum . ChecksumType [ 0 ] , 'COMPOSITE' ) ;
360+
361+ const withoutChecksum = uploads . find ( u => u . Key [ 0 ] === noChecksumKey ) ;
362+ assert . strictEqual ( withoutChecksum . ChecksumAlgorithm , undefined ) ;
363+ assert . strictEqual ( withoutChecksum . ChecksumType , undefined ) ;
227364 done ( ) ;
228365 } ) ;
229366 } ) ;
0 commit comments