Skip to content

Commit 0ed0d57

Browse files
Pedestrian93PeterRao
authored andcommitted
fix: remove completeMultipartUpload encryption header (#718)
close #715
1 parent 4e137d4 commit 0ed0d57

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

lib/common/multipart.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
const copy = require('copy-to');
33
const callback = require('./callback');
4+
const deepCopy = require('./utils/deepCopy');
45

56
const proto = exports;
67

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

183184
options = options || {};
184-
const opt = {};
185-
copy(options).to(opt);
185+
let opt = {};
186+
opt = deepCopy(options);
187+
if (opt.headers) delete opt.headers['x-oss-server-side-encryption'];
186188
opt.subres = { uploadId };
187189

188190
const params = this._objectRequestParams('POST', name, opt);

lib/common/utils/deepCopy.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = function deepCopy(obj, cache = []) {
2+
if (obj === null || typeof obj !== 'object') {
3+
return obj;
4+
}
5+
const hit = cache.filter(c => c.original === obj)[0];
6+
if (hit) {
7+
return hit.copy;
8+
}
9+
const copy = Array.isArray(obj) ? [] : {};
10+
cache.push({
11+
original: obj,
12+
copy
13+
});
14+
15+
Object.keys(obj).forEach((key) => {
16+
copy[key] = deepCopy(obj[key], cache);
17+
});
18+
19+
return copy;
20+
};

test/browser/browser.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,18 @@ describe('browser', () => {
960960
assert.equal(result.res.headers['x-oss-server-side-encryption'], 'AES256');
961961
});
962962

963+
it('should multipartUpload with x-oss-server-side-encryption', async () => {
964+
const name = 'multipart-x-oss-server-side-encryption';
965+
const fileContent = Array(1034 * 1024).fill('a').join('');
966+
const fileName = new File([fileContent], 'multipart-upload-kms');
967+
const result = await store.multipartUpload(name, fileName, {
968+
headers: {
969+
'x-oss-server-side-encryption': 'KMS'
970+
}
971+
});
972+
assert.equal(result.res.headers['x-oss-server-side-encryption'], 'KMS');
973+
});
974+
963975
it('should fallback to putStream when file size is smaller than 100KB', async () => {
964976
const file = new File(['multipart-fallback-test'], 'multipart-fallback');
965977
const name = `${prefix}multipart/fallback`;

test/node/multipart.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ describe('test/multipart.test.js', () => {
157157
assert.equal(result.res.headers['x-oss-server-side-encryption'], 'AES256');
158158
});
159159

160+
it('should multipartUpload with x-oss-server-side-encryption', async () => {
161+
const name = 'multipart-x-oss-server-side-encryption';
162+
const fileName = await utils.createTempFile(
163+
'multipart-fallback',
164+
1003 * 1020
165+
);
166+
const result = await store.multipartUpload(name, fileName, {
167+
headers: {
168+
'x-oss-server-side-encryption': 'KMS'
169+
}
170+
});
171+
assert.equal(result.res.headers['x-oss-server-side-encryption'], 'KMS');
172+
});
173+
160174
it('should fallback to putStream when file size is smaller than 100KB', async () => {
161175
const fileName = await utils.createTempFile('multipart-fallback', (100 * 1024) - 1);
162176
const name = `${prefix}multipart/fallback`;

0 commit comments

Comments
 (0)