Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove completeMultipartUpload encryption header #718

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"publish-to-cdn": "node publish.js",
"snyk-protect": "snyk protect",
"prepublish": "npm run snyk-protect",
"lint-staged": "lint-staged",
"detect-secrets": "node task/detect-secrets"
},
"git-pre-hooks": {
Expand All @@ -38,7 +39,7 @@
"npm run publish-to-npm",
"npm run publish-to-cdn"
],
"pre-commit": "lint-staged"
"pre-commit": "npm run lint-staged"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions shims/crypto/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var algorithms = {
};

var blocksize = 64;
var zeroBuffer = Buffer.from(blocksize);
var zeroBuffer = Buffer.alloc(blocksize);
zeroBuffer.fill(0);

function hmac(fn, key, data) {
Expand All @@ -24,7 +24,7 @@ function hmac(fn, key, data) {
key = Buffer.concat([key, zeroBuffer], blocksize)
}

var ipad = Buffer.from(blocksize), opad = Buffer.from(blocksize);
var ipad = Buffer.alloc(blocksize), opad = Buffer.alloc(blocksize);
for(var i = 0; i < blocksize; i++) {
ipad[i] = key[i] ^ 0x36
opad[i] = key[i] ^ 0x5C
Expand Down
4 changes: 2 additions & 2 deletions shims/crypto/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var Buffer = require('buffer').Buffer;
var intSize = 4;
var zeroBuffer = Buffer.from(intSize); zeroBuffer.fill(0);
var zeroBuffer = Buffer.alloc(intSize); zeroBuffer.fill(0);
var chrsz = 8;

function toArray(buf, bigEndian) {
Expand All @@ -18,7 +18,7 @@ function toArray(buf, bigEndian) {
}

function toBuffer(arr, size, bigEndian) {
var buf = Buffer.from(size);
var buf = Buffer.alloc(size);
var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
for (var i = 0; i < arr.length; i++) {
fn.call(buf, arr[i], i * 4, true);
Expand Down
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