Compare commits

..

No commits in common. "3a367fceef739889340e8d753429eaa1e38f2c12" and "77137f2b4db5bdc619305d62b8deaf1b2e163a52" have entirely different histories.

2 changed files with 24 additions and 9 deletions

View File

@ -41,11 +41,31 @@ function createCanonicalRequest(params) {
// canonical query string
let canonicalQueryStr = '';
if (pQuery && !(service === 'iam' && pHttpVerb === 'POST')) {
const sortedQueryParams = Object.keys(pQuery).sort().map(key => {
const encodedKey = awsURIencode(key);
const queryParams = Object.keys(pQuery).map(key => {
const value = pQuery[key] ? awsURIencode(pQuery[key]) : '';
return `${encodedKey}=${value}`;
return {
qParam: awsURIencode(key),
value,
};
});
queryParams.sort((a, b) => {
if (a.qParam[0] && b.qParam[0]) {
if (a.qParam[0].toUpperCase() === a.qParam[0]
&& b.qParam[0].toUpperCase() !== b.qParam[0]) {
// a is capitalized so comes first
return -1;
}
if (b.qParam[0].toUpperCase() === b.qParam[0]
&& a.qParam[0].toUpperCase() !== a.qParam[0]) {
// b is capitalized so comes first
return 1;
}
}
return a.qParam.localeCompare(b.qParam);
});
const sortedQueryParams = queryParams.map(item =>
`${item.qParam}=${item.value}`);
canonicalQueryStr = sortedQueryParams.join('&');
}

View File

@ -136,8 +136,6 @@ describe('createCanonicalRequest function', () => {
'X-Amz-Date': '20130524T000000Z',
'X-Amz-Credential': 'AKIAIOSFODNN7EXAMPLE/20130524/' +
'us-east-1/s3/aws4_request',
'X-Amz-Meta-camelCase': 'before',
'X-Amz-Meta-camelcase': 'after',
},
pHeaders: {
host: 'examplebucket.s3.amazonaws.com',
@ -150,10 +148,7 @@ describe('createCanonicalRequest function', () => {
'X-Amz-Algorithm=AWS4-HMAC-SHA256&' +
'X-Amz-Credential=AKIAIOSFODNN7EXAMPLE%2F20130524%2' +
'Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20130524T000000' +
'Z&X-Amz-Expires=86400' +
'&X-Amz-Meta-camelCase=before' +
'&X-Amz-Meta-camelcase=after' +
'&X-Amz-SignedHeaders=host' +
'Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host' +
'&x-amz-acl=public\n' +
'host:examplebucket.s3.amazonaws.com\n' +
'x-amz-acl:public\n\n' +