Compare commits

..

No commits in common. "6927f2b6ee25327c892d4e2eec46062df1ed3289" and "63bf2cb5b1e3ccf4725dd6be1d02496913f396f4" have entirely different histories.

4 changed files with 8 additions and 46 deletions

View File

@ -181,8 +181,7 @@ function generateV4Headers(
secretKeyValue: string,
awsService: string,
proxyPath: string,
sessionToken: string,
payload: string,
sessionToken: string
) {
Object.assign(request, { headers: {} });
const amzDate = convertUTCtoISO8601(Date.now());
@ -195,7 +194,7 @@ function generateV4Headers(
const timestamp = amzDate;
const algorithm = 'AWS4-HMAC-SHA256';
payload = payload || '';
let payload = '';
if (request.method === 'POST') {
payload = queryString.stringify(data, undefined, undefined, {
encodeURIComponent,
@ -206,8 +205,7 @@ function generateV4Headers(
request.setHeader('host', request._headers.host);
request.setHeader('x-amz-date', amzDate);
request.setHeader('x-amz-content-sha256', payloadChecksum);
request.setHeader('content-md5', crypto.createHash('md5')
.update(payload, 'binary').digest('base64'))
if (sessionToken) {
request.setHeader('x-amz-security-token', sessionToken);
}
@ -217,7 +215,6 @@ function generateV4Headers(
.filter(headerName =>
headerName.startsWith('x-amz-')
|| headerName.startsWith('x-scal-')
|| headerName === 'content-md5'
|| headerName === 'host'
).sort().join(';');
const params = { request, signedHeaders, payloadChecksum,

View File

@ -501,27 +501,15 @@ export default class LifecycleConfiguration {
_checkDate(date: string) {
const isoRegex = new RegExp('^(-?(?:[1-9][0-9]*)?[0-9]{4})-' +
'(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9])' +
':([0-5][0-9]):([0-5][0-9])(\\.[0-9]+)?(Z|[+-][0-5][0-9]:[0-5][0-9])?$');
':([0-5][0-9]):([0-5][0-9])(\\.[0-9]+)?(Z)?$');
if (!isoRegex.test(date)) {
const msg = 'Date must be in ISO 8601 format';
return errors.InvalidArgument.customizeDescription(msg);
}
// Extract the time portion of the date string to check if a timezone
// is specified. If not, add a Z to indicate UTC. We split to avoid
// then hyphens in the date portion.
const time = date.split('T')[1];
if (!time.includes('Z') && !time.includes('+') && !time.includes('-')) {
date += 'Z';
}
const dateObj = new Date(date);
if (Number.isNaN(dateObj.getTime())) {
const msg = 'Date is not a valid date';
return errors.InvalidArgument.customizeDescription(msg);
}
if (dateObj.getUTCHours() !== 0
|| dateObj.getUTCMinutes() !== 0
|| dateObj.getUTCSeconds() !== 0
|| dateObj.getUTCMilliseconds() !== 0) {
const midnightRegex = new RegExp('^(-?(?:[1-9][0-9]*)?[0-9]{4})-' +
'(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T00' +
':00:00(\\.0+)?(Z)?$');
if (!midnightRegex.test(date)) {
const msg = '\'Date\' must be at midnight GMT';
return errors.InvalidArgument.customizeDescription(msg);
}

View File

@ -80,7 +80,6 @@
"lint_md": "mdlint $(git ls-files '*.md')",
"lint_yml": "yamllint $(git ls-files '*.yml')",
"test": "jest tests/unit",
"test_auth": "jest tests/unit/auth",
"build": "tsc",
"prepare": "yarn build",
"ft_test": "jest tests/functional --testTimeout=120000 --forceExit",

View File

@ -420,12 +420,6 @@ describe('LifecycleConfiguration', () => {
assert.strictEqual(error, null);
});
it('should return no error with a valid ISO date at midnight with timezone', () => {
const date = '2024-01-08T06:00:00+06:00';
const error = lifecycleConfiguration._checkDate(date);
assert.strictEqual(error, null);
});
it('should return an error with a non-ISO date', () => {
const date = '2016-01-01T00:00:00000Z';
const error = lifecycleConfiguration._checkDate(date);
@ -442,14 +436,6 @@ describe('LifecycleConfiguration', () => {
expect(error.description).toEqual(msg);
});
it('should return an error with a non-ISO date', () => {
const date = '2024-01-08T00:00:00+34:00';
const error = lifecycleConfiguration._checkDate(date);
const msg = 'Date is not a valid date';
expect(error.is.InvalidArgument).toBeTruthy();
expect(error.description).toEqual(msg);
});
it('should return an error with a date that is not set to midnight', () => {
const date = '2024-01-04T15:22:40Z';
const error = lifecycleConfiguration._checkDate(date);
@ -457,14 +443,6 @@ describe('LifecycleConfiguration', () => {
expect(error.is.InvalidArgument).toBeTruthy();
expect(error.description).toEqual(msg);
});
it('should return an error with a date that is not set to midnight', () => {
const date = '2024-01-08T00:00:00.123Z';
const error = lifecycleConfiguration._checkDate(date);
const msg = '\'Date\' must be at midnight GMT';
expect(error.is.InvalidArgument).toBeTruthy();
expect(error.description).toEqual(msg);
});
});
});