@@ -37,7 +37,7 @@ const calculateFields = (ak, sk, bucketName, additionalConditions) => {
37
37
38
38
const now = new Date ( ) ;
39
39
const formattedDate = now . toISOString ( ) . replace ( / [: -] | \. \d { 3 } / g, '' ) ;
40
- const shortFormattedDate = formatDate ( now ) ;
40
+ let shortFormattedDate = formatDate ( now ) ;
41
41
42
42
const credential = `${ ak } /${ shortFormattedDate } /${ region } /${ service } /aws4_request` ;
43
43
const conditionsFields = [
@@ -54,6 +54,9 @@ const calculateFields = (ak, sk, bucketName, additionalConditions) => {
54
54
const index = conditionsFields . findIndex ( condition => condition . hasOwnProperty ( key ) ) ;
55
55
if ( index !== - 1 ) {
56
56
conditionsFields [ index ] [ key ] = value ;
57
+ if ( key === 'x-amz-date' ) {
58
+ shortFormattedDate = value . split ( 'T' ) [ 0 ] ;
59
+ }
57
60
} else {
58
61
conditionsFields . push ( { [ key ] : value } ) ;
59
62
}
@@ -69,11 +72,11 @@ const calculateFields = (ak, sk, bucketName, additionalConditions) => {
69
72
const signature = crypto . createHmac ( 'sha256' , signingKey ) . update ( policyBase64 ) . digest ( 'hex' ) ;
70
73
71
74
const returnFields = [
72
- { name : 'X-Amz-Credential ' , value : credential } ,
73
- { name : 'X-Amz-Algorithm ' , value : 'AWS4-HMAC-SHA256' } ,
74
- { name : 'X-Amz-Signature ' , value : signature } ,
75
- { name : 'X-Amz-Date ' , value : formattedDate } ,
76
- { name : 'Policy ' , value : policyBase64 } ,
75
+ { name : 'x-amz-credential ' , value : credential } ,
76
+ { name : 'x-amz-algorithm ' , value : 'AWS4-HMAC-SHA256' } ,
77
+ { name : 'x-amz-signature ' , value : signature } ,
78
+ { name : 'x-amz-date ' , value : formattedDate } ,
79
+ { name : 'policy ' , value : policyBase64 } ,
77
80
{ name : 'bucket' , value : bucketName } ,
78
81
{ name : 'key' , value : filename } ,
79
82
] ;
@@ -95,7 +98,6 @@ const calculateFields = (ak, sk, bucketName, additionalConditions) => {
95
98
return returnFields ;
96
99
} ;
97
100
98
-
99
101
describe ( 'POST object' , ( ) => {
100
102
let bucketUtil ;
101
103
let config ;
@@ -372,7 +374,16 @@ describe('POST object', () => {
372
374
} )
373
375
. catch ( err => {
374
376
assert . equal ( err . response . status , 400 ) ;
375
- done ( ) ;
377
+ xml2js . parseString ( err . response . data , ( parseErr , result ) => {
378
+ if ( parseErr ) {
379
+ return done ( parseErr ) ;
380
+ }
381
+
382
+ const error = result . Error ;
383
+ assert . equal ( error . Code [ 0 ] , 'InvalidArgument' ) ;
384
+ assert . equal ( error . Message [ 0 ] , 'POST requires exactly one file upload per request.' ) ;
385
+ done ( ) ;
386
+ } ) ;
376
387
} ) ;
377
388
} ) ;
378
389
} ) ;
0 commit comments