Skip to content

Commit

Permalink
fix: remove completeMultipartUpload encryption header (#718)
Browse files Browse the repository at this point in the history
close #715
  • Loading branch information
Pedestrian93 authored and PeterRao committed Dec 27, 2019
1 parent 4e137d4 commit 0ed0d57
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/common/multipart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

const copy = require('copy-to');
const callback = require('./callback');
const deepCopy = require('./utils/deepCopy');

const proto = exports;

Expand Down Expand Up @@ -181,8 +182,9 @@ proto.completeMultipartUpload = async function completeMultipartUpload(name, upl
xml += '</CompleteMultipartUpload>';

options = options || {};
const opt = {};
copy(options).to(opt);
let opt = {};
opt = deepCopy(options);
if (opt.headers) delete opt.headers['x-oss-server-side-encryption'];
opt.subres = { uploadId };

const params = this._objectRequestParams('POST', name, opt);
Expand Down
20 changes: 20 additions & 0 deletions lib/common/utils/deepCopy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = function deepCopy(obj, cache = []) {
if (obj === null || typeof obj !== 'object') {
return obj;
}
const hit = cache.filter(c => c.original === obj)[0];
if (hit) {
return hit.copy;
}
const copy = Array.isArray(obj) ? [] : {};
cache.push({
original: obj,
copy
});

Object.keys(obj).forEach((key) => {
copy[key] = deepCopy(obj[key], cache);
});

return copy;
};
12 changes: 12 additions & 0 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,18 @@ describe('browser', () => {
assert.equal(result.res.headers['x-oss-server-side-encryption'], 'AES256');
});

it('should multipartUpload with x-oss-server-side-encryption', async () => {
const name = 'multipart-x-oss-server-side-encryption';
const fileContent = Array(1034 * 1024).fill('a').join('');
const fileName = new File([fileContent], 'multipart-upload-kms');
const result = await store.multipartUpload(name, fileName, {
headers: {
'x-oss-server-side-encryption': 'KMS'
}
});
assert.equal(result.res.headers['x-oss-server-side-encryption'], 'KMS');
});

it('should fallback to putStream when file size is smaller than 100KB', async () => {
const file = new File(['multipart-fallback-test'], 'multipart-fallback');
const name = `${prefix}multipart/fallback`;
Expand Down
14 changes: 14 additions & 0 deletions test/node/multipart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ describe('test/multipart.test.js', () => {
assert.equal(result.res.headers['x-oss-server-side-encryption'], 'AES256');
});

it('should multipartUpload with x-oss-server-side-encryption', async () => {
const name = 'multipart-x-oss-server-side-encryption';
const fileName = await utils.createTempFile(
'multipart-fallback',
1003 * 1020
);
const result = await store.multipartUpload(name, fileName, {
headers: {
'x-oss-server-side-encryption': 'KMS'
}
});
assert.equal(result.res.headers['x-oss-server-side-encryption'], 'KMS');
});

it('should fallback to putStream when file size is smaller than 100KB', async () => {
const fileName = await utils.createTempFile('multipart-fallback', (100 * 1024) - 1);
const name = `${prefix}multipart/fallback`;
Expand Down

0 comments on commit 0ed0d57

Please sign in to comment.