Skip to content

Commit cef1840

Browse files
authored
fix: _signatureForURL bug (#772)
1 parent 262cc4c commit cef1840

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,7 @@ parameters:
18881888
- [process] {String} image process params, will send with `x-oss-process`
18891889
e.g.: `{process: 'image/resize,w_200'}`
18901890
- [trafficLimit] {Number} traffic limit, range: `819200`~`838860800`.
1891+
- [subResource] {Object} additional signature parameters in url.
18911892
- [response] {Object} set the response headers for download
18921893
- [content-type] {String} set the response content type
18931894
- [content-disposition] {String} set the response content disposition

lib/common/signUtils.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ exports.authorization = function authorization(accessKeyId, accessKeySecret, can
103103
* @param {String} resource
104104
* @param {Number} expires
105105
*/
106-
exports._signatureForURL = function _signatureForURL(accessKeySecret, options, resource, expires) {
106+
exports._signatureForURL = function _signatureForURL(accessKeySecret, options = {}, resource, expires) {
107107
const headers = {};
108-
const subResource = {};
108+
const { subResource = {} } = options;
109109

110110
if (options.process) {
111111
const processKeyword = 'x-oss-process';
@@ -133,8 +133,6 @@ exports._signatureForURL = function _signatureForURL(accessKeySecret, options, r
133133
headers[key] = value;
134134
} else if (lowerKey.indexOf('content-type') === 0) {
135135
headers[key] = value;
136-
} else if (lowerKey !== 'expires' && lowerKey !== 'response' && lowerKey !== 'process' && lowerKey !== 'method' && lowerKey !== 'trafficlimit') {
137-
subResource[lowerKey] = value;
138136
}
139137
});
140138

test/node/object.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ describe('test/object.test.js', () => {
951951
assert.equal(urlRes.data.toString(), result.content.toString());
952952
});
953953

954-
it('should signature url with reponse limitation', async () => {
954+
it('should signature url with response limitation', async () => {
955955
const response = {
956956
'content-type': 'xml',
957957
'content-language': 'zh-cn'
@@ -961,6 +961,30 @@ describe('test/object.test.js', () => {
961961
assert(url.indexOf('response-content-language=zh-cn') !== -1);
962962
});
963963

964+
it('should signature url with options contains other parameters', async () => {
965+
const options = {
966+
expires: 3600,
967+
subResource: {
968+
'x-oss-process': 'image/resize,w_200',
969+
},
970+
// others parameters
971+
filename: 'test.js',
972+
testParameters: 'xxx',
973+
};
974+
const imageName = `${prefix}ali-sdk/oss/nodejs-test-signature-1024x768.png`;
975+
const originImagePath = path.join(__dirname, 'nodejs-1024x768.png');
976+
path.join(__dirname, 'nodejs-processed-w200.png');
977+
await store.put(imageName, originImagePath, {
978+
mime: 'image/png',
979+
});
980+
981+
const signUrl = store.signatureUrl(imageName, options);
982+
const processedKeyword = 'x-oss-process=image%2Fresize%2Cw_200';
983+
assert.equal(signUrl.match(processedKeyword), processedKeyword);
984+
const urlRes = await urllib.request(signUrl);
985+
assert.equal(urlRes.status, 200);
986+
});
987+
964988
it('should signature url with image processed and get object ok', async () => {
965989
const imageName = `${prefix}ali-sdk/oss/nodejs-test-signature-1024x768.png`;
966990
const originImagePath = path.join(__dirname, 'nodejs-1024x768.png');

0 commit comments

Comments
 (0)