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/critical #988

Merged
merged 4 commits into from
Sep 29, 2021
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
22 changes: 13 additions & 9 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
module.exports = function (config) {
config.set({
frameworks: ['mocha', 'browserify'],
browsers: ['Chrome', 'Safari', 'Firefox'],
files: [
'test/browser/build/aliyun-oss-sdk.min.js',
'test/browser/build/tests.js'
plugins: [
require('karma-mocha'),
require('karma-browserify'),
require('karma-chrome-launcher'),
require('karma-safari-launcher'),
require('karma-firefox-launcher')
],
preprocessors: {
// 'dist/aliyun-oss-sdk.js': ['coverage']
},
browsers: ['Chrome', 'Safari', 'Firefox'],
files: ['test/browser/build/aliyun-oss-sdk.min.js', 'test/browser/build/tests.js'],
// preprocessors: {
// 'dist/aliyun-oss-sdk.js': ['coverage']
// },
// coverageReporter: {
// type : 'html',
// dir : 'coverage-browser/'
// type: 'html',
// dir: 'coverage-browser/'
// },
// reporters: ['progress', 'coverage'],
reporters: ['progress'],
Expand Down
23 changes: 19 additions & 4 deletions lib/browser/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const merge = require('merge-descriptors');
const { isBlob } = require('../common/utils/isBlob');
const { isFile } = require('../common/utils/isFile');
const { isBuffer } = require('../common/utils/isBuffer');
const { obj2xml } = require('../common/utils/obj2xml');

// var assert = require('assert');

Expand Down Expand Up @@ -251,9 +252,9 @@ proto.listV2 = async function listV2(query, options = {}) {
storageClass: obj.StorageClass,
owner: obj.Owner
? {
id: obj.Owner.ID,
displayName: obj.Owner.DisplayName
}
id: obj.Owner.ID,
displayName: obj.Owner.DisplayName
}
: null
}));
}
Expand Down Expand Up @@ -281,13 +282,27 @@ proto.listV2 = async function listV2(query, options = {}) {
* @param {Object} options
* @returns {{res}}
*/
proto.restore = async function restore(name, options) {
proto.restore = async function restore(name, options = { type: 'Archive' }) {
options = options || {};
options.subres = Object.assign({ restore: '' }, options.subres);
if (options.versionId) {
options.subres.versionId = options.versionId;
}
const params = this._objectRequestParams('POST', name, options);
if (options.type === 'ColdArchive') {
const paramsXMLObj = {
RestoreRequest: {
Days: options.Days ? options.Days : 2,
JobParameters: {
Tier: options.JobParameters ? options.JobParameters : 'Standard'
}
}
};
params.content = obj2xml(paramsXMLObj, {
headers: true
});
params.mime = 'xml';
}
params.successStatuses = [202];

const result = await this.request(params);
Expand Down
2 changes: 1 addition & 1 deletion lib/common/utils/createRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function createRequest(params) {
'x-oss-date': dateFormat(date, 'UTC:ddd, dd mmm yyyy HH:MM:ss \'GMT\''),
};
if (typeof window !== 'undefined') {
headers['x-oss-user-agent']= this.userAgent
headers['x-oss-user-agent'] = this.userAgent;
}
if (this.userAgent.includes('nodejs')) {
headers['User-Agent'] = this.userAgent;
Expand Down
12 changes: 3 additions & 9 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ proto.listV2 = async function listV2(query, options = {}) {
storageClass: obj.StorageClass,
owner: obj.Owner
? {
id: obj.Owner.ID,
displayName: obj.Owner.DisplayName
}
id: obj.Owner.ID,
displayName: obj.Owner.DisplayName
}
: null
}));
}
Expand Down Expand Up @@ -306,16 +306,10 @@ proto.listV2 = async function listV2(query, options = {}) {
*/
proto.restore = async function restore(name, options = { type: 'Archive' }) {
options = options || {};
if (!options.type) {
throw new Error('option must be type for ColdArchive or Archive');
}

options.subres = Object.assign({ restore: '' }, options.subres);

if (options.versionId) {
options.subres.versionId = options.versionId;
}

const params = this._objectRequestParams('POST', name, options);
if (options.type === 'ColdArchive') {
const paramsXMLObj = {
Expand Down
22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"scripts": {
"build-change-log": "standard-version",
"test": "npm run tsc && mocha -t 60000 -r thunk-mocha -r should -r dotenv/config test/node/*.test.js test/node/**/*.test.js",
"test": "npm run tsc && mocha -t 60000 -r should -r dotenv/config test/node/*.test.js test/node/**/*.test.js",
"test-cov": "npm run tsc && nyc --reporter=lcov node_modules/.bin/_mocha -t 60000 -r thunk-mocha -r should test/node/*.test.js test/node/**/*.test.js",
"jshint": "jshint .",
"autod": "autod",
Expand Down Expand Up @@ -83,42 +83,40 @@
"bluebird": "^3.1.5",
"browserify": "^16.5.2",
"co-fs": "^1.2.0",
"co-mocha": "^1.2.1",
"core-js": "^3.6.5",
"crypto-js": "^3.1.9-1",
"dotenv": "^8.2.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-ali": "^9.0.2",
"eslint-plugin-import": "^2.21.1",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
"filereader": "^0.10.3",
"git-pre-hooks": "^1.2.0",
"immediate": "^3.3.0",
"karma": "^1.7.1",
"karma": "^6.3.4",
"karma-browserify": "^5.1.1",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.0.1",
"karma-ie-launcher": "^1.0.0",
"karma-mocha": "^1.3.0",
"karma-mocha": "^2.0.1",
"karma-safari-launcher": "^1.0.0",
"lint-staged": "^9.5.0",
"mm": "^2.0.0",
"mocha": "^3.5.3",
"nyc": "^13.3.0",
"mocha": "^9.1.2",
"nyc": "^15.1.0",
"promise-polyfill": "^6.0.2",
"request": "^2.88.0",
"should": "^11.0.0",
"sinon": "^1.17.7",
"snyk": "1.454.0",
"standard-version": "^8.0.1",
"snyk": "^1.727.0",
"standard-version": "^9.3.1",
"stream-equal": "^1.1.0",
"thunk-mocha": "^1.0.3",
"timemachine": "^0.3.0",
"typescript": "^3.9.5",
"uglify-js": "^2.8.29",
"watchify": "^3.9.0"
"watchify": "^3.11.1"
},
"dependencies": {
"address": "^1.0.0",
Expand All @@ -134,7 +132,7 @@
"humanize-ms": "^1.2.0",
"is-type-of": "^1.0.0",
"js-base64": "^2.5.2",
"jstoxml": "^0.2.3",
"jstoxml": "^2.0.0",
"merge-descriptors": "^1.0.1",
"mime": "^2.4.5",
"mz-modules": "^2.1.0",
Expand Down
13 changes: 6 additions & 7 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,8 @@ describe('browser', () => {
const putString = {
test: '1'
};
const url = store.signatureUrl(name, {
const newName = 'newName';
const url = store.signatureUrl(newName, {
method: 'PUT',
'Content-Type': 'application/json; charset=UTF-8',
});
Expand All @@ -781,7 +782,7 @@ describe('browser', () => {
};
const res = await oss.urllib.request(url, { method: 'PUT', data: putString, headers });
assert.equal(res.status, 200);
const headRes = await store.head(name);
const headRes = await store.head(newName);
assert.equal(headRes.status, 200);
});
});
Expand Down Expand Up @@ -1476,9 +1477,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 @@ -2092,7 +2091,7 @@ describe('browser', () => {
it('should not calculate MD5 default when use put', async () => {
const store = oss(ossConfig);
const name = `${prefix}put/test-md5-0`;
const request = store.urllib.request;
const { request } = store.urllib;
let reqParams;
store.urllib.request = (url, params) => {
reqParams = params;
Expand All @@ -2110,7 +2109,7 @@ describe('browser', () => {
const name = `${prefix}put/test-md5-2`;
const partSize = 100 * 1024;
const body2 = new File(Array(2 * partSize).fill(1), { type: 'text/plain' });
const request = store.urllib.request;
const { request } = store.urllib;
let headerWithMD5Count = 0;
store.urllib.request = (url, params) => {
if (params.headers['Content-MD5'] && /partNumber=\d/.test(url)) {
Expand Down
18 changes: 6 additions & 12 deletions test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ describe('test/bucket.test.js', () => {
'max-keys': 20
});

await Promise.all((bucketResult.buckets || [])
.filter(_ => _.name.startsWith('ali-oss'))
.map(_bucket => utils
.cleanBucket(
oss(Object.assign(config, { region: _bucket.region })),
_bucket.name
)));
await Promise.all(
(bucketResult.buckets || [])
.filter(_ => _.name.startsWith('ali-oss'))
.map(_bucket => utils.cleanBucket(oss(Object.assign(config, { region: _bucket.region })), _bucket.name))
);

config.region = defaultRegion;
store = oss(config);
Expand Down Expand Up @@ -185,9 +183,6 @@ describe('test/bucket.test.js', () => {

describe('putBucketACL()', () => {
it('should set bucket acl to public-read-write', async () => {
const result = await store.putBucket(bucket);
assert.equal(result.res.status, 200);

const resultAcl = await store.putBucketACL(bucket, 'public-read-write');
assert.equal(resultAcl.res.status, 200);
assert.equal(resultAcl.bucket, bucket);
Expand Down Expand Up @@ -809,7 +804,7 @@ describe('test/bucket.test.js', () => {
storageClass: 'Archive'
},
expiration: {
createdBeforeDate: '2020-02-19T00:00:00.000Z'
createdBeforeDate: '2020-02-17T00:00:00.000Z'
},
tag: {
key: 'test',
Expand Down Expand Up @@ -1384,5 +1379,4 @@ describe('test/bucket.test.js', () => {
});
});
});

});
5 changes: 3 additions & 2 deletions test/node/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ describe('test/client.test.js', () => {
assert.equal(result.res.status, 200);
assert(header['User-Agent']);
assert(header['User-Agent'].startsWith(`aliyun-sdk-nodejs/${pkg.version} Node.js ${process.version.slice(1)}`));
assert(header['x-oss-user-agent']);
assert(header['x-oss-user-agent'].startsWith(`aliyun-sdk-nodejs/${pkg.version} Node.js ${process.version.slice(1)}`));
// node 环境移除了x-oss-user-agent
// assert(header['x-oss-user-agent']);
// assert(header['x-oss-user-agent'].startsWith(`aliyun-sdk-nodejs/${pkg.version} Node.js ${process.version.slice(1)}`));
});

it('should check beta or alpha User-Agent', () => {
Expand Down