Skip to content

Commit d7da573

Browse files
author
Will Toozs
committed
fixup: func tests: auth functional tests
1 parent 1b7361e commit d7da573

File tree

1 file changed

+16
-7
lines changed
  • tests/functional/aws-node-sdk/test/object

1 file changed

+16
-7
lines changed

tests/functional/aws-node-sdk/test/object/post.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ const calculateFields = (ak, sk, bucketName, additionalConditions) => {
6060
});
6161
}
6262
const policy = {
63-
expiration: new Date(new Date().getTime() + 60000).toISOString(),
63+
// 15 minutes from now
64+
expiration: new Date(new Date().getTime() + 15 * 60 * 1000).toISOString(),
6465
conditions: conditionsFields,
6566
};
6667
const policyBase64 = Buffer.from(JSON.stringify(policy)).toString('base64');
@@ -515,6 +516,7 @@ describe('POST object', () => {
515516

516517
it('should handle error when signature is invalid', done => {
517518
const { url, bucketName } = testContext;
519+
518520
const fields = calculateFields(ak, sk, bucketName);
519521
fields.push({ name: 'X-Amz-Signature', value: 'invalid-signature' });
520522
const formData = new FormData();
@@ -530,18 +532,25 @@ describe('POST object', () => {
530532
return done(err);
531533
}
532534

533-
axios.post(url, formData, {
535+
return axios.post(url, formData, {
534536
headers: {
535537
...formData.getHeaders(),
536538
'Content-Length': length,
537539
},
538540
})
539-
.then(() => {
540-
done(new Error('Expected error but got success response'));
541-
})
541+
.then(() => done(new Error('Expected error but got success response')))
542542
.catch(err => {
543543
assert.equal(err.response.status, 403);
544-
done();
544+
return xml2js.parseString(err.response.data, (err, result) => {
545+
if (err) {
546+
return done(err);
547+
}
548+
549+
const error = result.Error;
550+
assert.equal(error.Code[0], 'SignatureDoesNotMatch');
551+
assert.equal(error.Message[0], 'The request signature we calculated does not match the signature you provided.');
552+
return done();
553+
});
545554
});
546555
});
547556
});
@@ -666,7 +675,7 @@ describe('POST object', () => {
666675
const laterThanNow = new Date(new Date().getTime() + 60000);
667676
const shortFormattedDate = formatDate(laterThanNow);
668677

669-
const credential = `${ak}/${shortFormattedDate}/ap-east-1/s3/aws4_request`;
678+
const credential = `${ak}/${shortFormattedDate}/eu-west-1/blabla/aws4_request`;
670679

671680
// Modify the signature to be invalid
672681
fields = fields.map(field => {

0 commit comments

Comments
 (0)