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: to #50200336 合并修复uploadPart无法传递headers参数的问题 #1214

Merged
merged 21 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5c9f71e
fix: to #50200336 修复uploadPart无法传递headers参数的问 题
Jun 7, 2023
6ac831e
fix: to #50200336 修复uploadPart无法传递headers参数的问题并优化添加测试用例
Jun 16, 2023
20d5b9c
fix: to #50200336 修复uploadPart无法传递headers参数的问题并优化添加测试用例
Jun 16, 2023
5b64683
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 16, 2023
0b0d55c
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 16, 2023
5b17f86
fix: to #50200336 修复uploadPart无法传递headers参数的问 题
Jun 16, 2023
8f6a691
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 16, 2023
26a1874
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 19, 2023
33bcb3b
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 19, 2023
6d8f1c8
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 19, 2023
b7facb2
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 19, 2023
9f7c2a4
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 19, 2023
a9e32bc
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 19, 2023
4b272dd
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 19, 2023
e80ab5c
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 19, 2023
68bb248
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 20, 2023
970c8fc
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 20, 2023
0c8a6e2
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 20, 2023
2b1b7c7
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 20, 2023
f98f3cc
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 20, 2023
d44b336
fix: to #50200336 修复uploadPart无法传递headers参数的问题
Jun 20, 2023
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
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ module.exports = {
'no-buffer-constructor': [2],
"comma-dangle": [0],
'import/prefer-default-export': [0],
'@typescript-eslint/no-var-requires': [0],
'@typescript-eslint/no-require-imports': [0]
}
};
12 changes: 1 addition & 11 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
# 代码审计 #
name: "CodeQL"

on:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# 每天0点定时清理测试的bucket
name: 'Schdule Delete'

on:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/snyk.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# 漏洞扫描 #
name: SNYK_SCAN
on:
push:
Expand Down
5 changes: 1 addition & 4 deletions lib/browser/managed-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ proto._resumeMultipart = async function _resumeMultipart(checkpoint, options) {

let result;
try {
result = await self._uploadPart(name, uploadId, partNo, data, {
timeout: options.timeout,
disabledMD5: options.disabledMD5
});
result = await self._uploadPart(name, uploadId, partNo, data, options);
} catch (error) {
if (error.status === 404) {
throw self._makeAbortEvent();
Expand Down
6 changes: 5 additions & 1 deletion lib/common/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,18 @@ proto._uploadPart = async function _uploadPart(name, uploadId, partNo, data, opt
options = options || {};
const opt = {};
copy(options).to(opt);
opt.headers = opt.headers || {};
opt.headers = {
...opt.headers,
'Content-Length': data.size
};

// 移除x-oss-server-side-encryption,避免测试用例报错:should multipartUpload with x-oss-server-side-encryption
opt.headers = omit(opt.headers, ['x-oss-server-side-encryption']);
opt.subres = {
partNumber: partNo,
uploadId
};

const params = this._objectRequestParams('PUT', name, opt);
params.mime = opt.mime;
const isBrowserEnv = process && process.browser;
Expand Down
4 changes: 1 addition & 3 deletions lib/managed-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ proto._resumeMultipart = async function _resumeMultipart(checkpoint, options) {

let result;
try {
result = await self._uploadPart(name, uploadId, partNo, data, {
timeout: options.timeout
});
result = await self._uploadPart(name, uploadId, partNo, data, options);
} catch (error) {
removeStreamFromMultipartUploadStreams();
if (error.status === 404) {
Expand Down
21 changes: 8 additions & 13 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1168,8 +1168,7 @@ describe('browser', () => {
await Promise.all(
Array(5)
.fill(1)
// eslint-disable-next-line no-unused-vars
.map(_ => store.initMultipartUpload(name))
.map(() => store.initMultipartUpload(name))
)
)
.map(_ => _.uploadId)
Expand Down Expand Up @@ -1204,8 +1203,7 @@ describe('browser', () => {
await Promise.all(
Array(5)
.fill(1)
// eslint-disable-next-line no-unused-vars
.map(_ => store.initMultipartUpload(fooName))
.map(() => store.initMultipartUpload(fooName))
)
)
.map(_ => _.uploadId)
Expand All @@ -1216,8 +1214,7 @@ describe('browser', () => {
await Promise.all(
Array(5)
.fill(5)
// eslint-disable-next-line no-unused-vars
.map(_ => store.initMultipartUpload(barName))
.map(() => store.initMultipartUpload(barName))
)
)
.map(_ => _.uploadId)
Expand Down Expand Up @@ -1535,9 +1532,7 @@ describe('browser', () => {
const parts = await Promise.all(
Array(10)
.fill(1)
.map((v, i) =>
store.uploadPart(name, uploadId, i + 1, file, i * partSize, Math.min((i + 1) * partSize, 10 * 100 * 1024))
)
.map((v, i) => store.uploadPart(name, uploadId, i + 1, file, i * partSize, Math.min((i + 1) * partSize, 10 * 100 * 1024)))
);
const dones = parts.map((_, i) => ({
number: i + 1,
Expand Down Expand Up @@ -1723,12 +1718,12 @@ describe('browser', () => {
const filename = `multipart-upload-file-${Date.now()}`;
const file = new File([fileContent], filename);
const name = `${prefix}multipart/upload-file`;
let progress = 0;
// let progress = 0;
try {
const result = await store.multipartUpload(name, file, {
await store.multipartUpload(name, file, {
partSize: 14.56,
progress() {
progress++;
// progress++;
}
});
} catch (e) {
Expand All @@ -1739,7 +1734,7 @@ describe('browser', () => {
await store.multipartUpload(name, file, {
partSize: 1,
progress() {
progress++;
// progress++;
}
});
} catch (e) {
Expand Down
8 changes: 6 additions & 2 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
const { env } = process;

const config = module.exports;
const USWEST = 'oss-us-west-1'; // ONCI 用美国硅谷的region速度会快些

config.oss = {
accessKeyId: env.ALI_SDK_OSS_ID,
accessKeySecret: env.ALI_SDK_OSS_SECRET,
accountId: env.ALI_SDK_STS_ROLE.match(/^acs:ram::(\d+):role/i)[1], // 通过roleRan获取主账号id
region: env.ALI_SDK_OSS_REGION || 'oss-cn-hangzhou',
endpoint: env.ONCI ? 'https://oss-us-west-1.aliyuncs.com' : null
endpoint: env.ONCI ? `https://${USWEST}.aliyuncs.com` : undefined
};

config.sts = {
accessKeyId: env.ALI_SDK_STS_ID,
accessKeySecret: env.ALI_SDK_STS_SECRET,
roleArn: env.ALI_SDK_STS_ROLE,
bucket: env.ALI_SDK_STS_BUCKET,
endpoint: env.ONCI ? 'https://sts.aliyuncs.com/' : null
endpoint: env.ONCI ? 'https://sts.aliyuncs.com/' : undefined
};

config.metaSyncTime = env.ONCI ? '30s' : '1000ms';
config.timeout = '120s';

console.log('--99-', config.oss.accountId);
8 changes: 2 additions & 6 deletions test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ const config = require('../config').oss;
const ms = require('humanize-ms');
const { metaSyncTime, timeout } = require('../config');

// only run on travis ci

// if (!process.env.CI) { return;
// }

describe('test/bucket.test.js', () => {
const { prefix, includesConf } = utils;
let store;
let bucket;
let bucketRegion;
const { accountId } = config;
const defaultRegion = config.region;
before(async () => {
store = oss(config);
Expand Down Expand Up @@ -1320,7 +1316,7 @@ describe('test/bucket.test.js', () => {
prefix: 'ttt',
OSSBucketDestination: {
format: 'CSV',
accountId: '1817184078010220',
accountId, // 目标Bucket拥有者的主账号ID
rolename: 'AliyunOSSRole',
bucket,
prefix: 'test'
Expand Down
2 changes: 1 addition & 1 deletion test/node/bucket_worm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const assert = require('assert');
const utils = require('./utils');
const oss = require('../..');
const config = require('../config').oss;
const timeout = require('../config').timeout;
const { timeout } = require('../config');

describe('test/bucket_worm.test.js', () => {
const { prefix } = utils;
Expand Down
26 changes: 13 additions & 13 deletions test/node/cleanAllBucket.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
/* eslint-disable no-console */
const utils = require('./utils');
const config = require('../config').oss;
const OSS = require('../..');

const store = new OSS(config);
const interval = new Date().getTime() - 24 * 60 * 60 * 1 * 1000;
// const interval = new Date().getTime() - 24 * 60 * 60 * 1 * 1000;
// const calculateData = bucket => {
// return parseInt(bucket.split('-').pop());
// };

store.listBuckets().then(r => {
const bucketList = [];
r.buckets.forEach(i => {
if (i.name.indexOf('ali-oss') === 0) {
if (calculateData(i.name) < interval) {
bucketList.push({
bucket: i.name,
region: i.region
});
}
if (i.name.indexOf('ali-oss-') === 0) {
bucketList.push({
bucket: i.name,
region: i.region
});
}
});

for (const bucketListItem of bucketList) {
console.log(`正在清理:${bucketListItem.bucket}`);
store.options.endpoint.parse(`https://${bucketListItem.region}.aliyuncs.com`);
const client = new OSS({
...store.options,
bucket: bucketListItem.bucket,
region: bucketListItem.region
region: bucketListItem.region,
});
utils.cleanBucket(client, bucketListItem.bucket).catch(e => {
console.log('bucket name =======>', bucketListItem.bucket);
console.log('error:====>', e);
});
}
});

const calculateData = bucket => {
return parseInt(bucket.split('-').pop());
};
33 changes: 16 additions & 17 deletions test/node/multipart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('test/multipart.test.js', () => {
await Promise.all(
Array(5)
.fill(1)
.map(_ => store.initMultipartUpload(name))
.map(() => store.initMultipartUpload(name))
)
)
.map(_ => _.uploadId)
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('test/multipart.test.js', () => {
await Promise.all(
Array(5)
.fill(1)
.map(_ => store.initMultipartUpload(fooName))
.map(() => store.initMultipartUpload(fooName))
)
)
.map(_ => _.uploadId)
Expand All @@ -121,7 +121,7 @@ describe('test/multipart.test.js', () => {
await Promise.all(
Array(5)
.fill(5)
.map(_ => store.initMultipartUpload(barName))
.map(() => store.initMultipartUpload(barName))
)
)
.map(_ => _.uploadId)
Expand Down Expand Up @@ -484,16 +484,14 @@ describe('test/multipart.test.js', () => {
const parts = await Promise.all(
Array(10)
.fill(1)
.map((v, i) =>
store.uploadPart(
name,
uploadId,
i + 1,
fileName,
i * partSize,
Math.min((i + 1) * partSize, 10 * 100 * 1024)
)
)
.map((v, i) => store.uploadPart(
name,
uploadId,
i + 1,
fileName,
i * partSize,
Math.min((i + 1) * partSize, 10 * 100 * 1024)
))
);
const dones = parts.map((_, i) => ({
number: i + 1,
Expand All @@ -509,12 +507,12 @@ describe('test/multipart.test.js', () => {
const fileName = await utils.createTempFile('multipart-upload-file', 1024 * 1024);

const name = `${prefix}multipart/upload-file`;
let progress = 0;
// let progress = 0;
try {
const result = await store.multipartUpload(name, fileName, {
await store.multipartUpload(name, fileName, {
partSize: 14.56,
progress() {
progress++;
// progress++;
}
});
} catch (e) {
Expand All @@ -525,7 +523,7 @@ describe('test/multipart.test.js', () => {
await store.multipartUpload(name, fileName, {
partSize: 1,
progress() {
progress++;
// progress++;
}
});
} catch (e) {
Expand Down Expand Up @@ -861,6 +859,7 @@ describe('test/multipart.test.js', () => {
const stubUploadPart = sinon.stub(
clientTmp,
'uploadPartCopy',
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async (objectKey, uploadId, partNo, range, sourceData, options) => {
if (partNo === 1) {
throw new Error('TestErrorException');
Expand Down
13 changes: 5 additions & 8 deletions test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const AgentKeepalive = require('agentkeepalive');
const HttpsAgentKeepalive = require('agentkeepalive').HttpsAgent;
const utils = require('./utils');
const oss = require('../..');
const sts = require('../..').STS;
const config = require('../config').oss;
const stsConfig = require('../config').sts;
const urllib = require('urllib');
const copy = require('copy-to');
const mm = require('mm');
Expand Down Expand Up @@ -2331,13 +2329,12 @@ describe('test/object.test.js', () => {
}
};

const postFile = () =>
new Promise((resolve, reject) => {
request(options, (err, res) => {
if (err) reject(err);
if (res) resolve(res);
});
const postFile = () => new Promise((resolve, reject) => {
request(options, (err, res) => {
if (err) reject(err);
if (res) resolve(res);
});
});

const result = await postFile();
assert(result.statusCode === 204);
Expand Down
1 change: 1 addition & 0 deletions test/node/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ exports.cleanAllBucket = async function (store) {
bucket: bucketListItem.bucket,
region: bucketListItem.region
});
// eslint-disable-next-line no-await-in-loop
await this.cleanBucket(client, bucketListItem.bucket);
}
};
Expand Down