Skip to content

Commit

Permalink
test: add test cases for signatureUrl and asyncSignatureUrl (#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
YunZZY authored Dec 18, 2023
1 parent 830e36e commit a0b4063
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [6.19.0](https://github.com/ali-sdk/ali-oss/compare/v6.18.1...v6.19.0) (2023-12-15)
## [6.19.0](https://github.com/ali-sdk/ali-oss/compare/v6.18.1...v6.19.0) (2023-12-18)

### Features

Expand Down
37 changes: 36 additions & 1 deletion test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,42 @@ describe('browser', () => {

const url = signatureStore.signatureUrl(name);
// http://www.aliyun.com/darwin-v4.4.2/ali-sdk/oss/get-meta.js?OSSAccessKeyId=
assert.equal(url.indexOf('http://www.aliyun.com/'), 0);
assert.strictEqual(url.indexOf('http://www.aliyun.com/'), 0);
signatureStore
.asyncSignatureUrl(name)
.then(asyncUrl => {
assert.strictEqual(asyncUrl.indexOf('http://www.aliyun.com/'), 0);
})
.catch(() => {
assert.fail('Expected asyncSignatureUrl to be executed successfully');
});
});

it('should signature url with custom host that endpoint cannot be an IP', () => {
const signatureStore = oss(
Object.assign({}, ossConfig, {
endpoint: '127.0.0.1',
cname: true
})
);

assert.throws(() => {
try {
signatureStore.signatureUrl(name);
} catch (err) {
assert.strictEqual(err.message, 'can not get the object URL when endpoint is IP');
throw err;
}
}, Error);

signatureStore
.asyncSignatureUrl(name)
.then(() => {
assert.fail('Expected asyncSignatureUrl to throw an error');
})
.catch(err => {
assert.strictEqual(err.message, 'can not get the object URL when endpoint is IP');
});
});

it('signatureUrl will should use refreshSTSToken', async () => {
Expand Down
36 changes: 33 additions & 3 deletions test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ describe('test/object.test.js', () => {
}
});

it('should verify object name strictly by default', () => {
it('should verify object name strictly by default', async () => {
assert.throws(() => {
try {
store.signatureUrl(testSignatureObjectName);
Expand All @@ -1072,7 +1072,7 @@ describe('test/object.test.js', () => {
}
}, Error);

assert.rejects(store.asyncSignatureUrl(testSignatureObjectName), err => {
await assert.rejects(store.asyncSignatureUrl(testSignatureObjectName), err => {
assert.strictEqual(err.message, `Invalid object name ${testSignatureObjectName}`);

return true;
Expand Down Expand Up @@ -1220,7 +1220,37 @@ describe('test/object.test.js', () => {

const url = tempStore.signatureUrl(name);
// http://www.aliyun.com/darwin-v4.4.2/ali-sdk/oss/get-meta.js?OSSAccessKeyId=
assert.equal(url.indexOf('http://www.aliyun.com/'), 0);
assert.strictEqual(url.indexOf('http://www.aliyun.com/'), 0);

try {
const asyncUrl = await tempStore.asyncSignatureUrl(name);
assert.strictEqual(asyncUrl.indexOf('http://www.aliyun.com/'), 0);
} catch {
assert.fail('Expected asyncSignatureUrl to be executed successfully');
}
});

it('should signature url with custom host that endpoint cannot be an IP', async () => {
const conf = {};
copy(config).to(conf);
conf.endpoint = '127.0.0.1';
conf.cname = true;
const tempStore = oss(conf);

assert.throws(() => {
try {
tempStore.signatureUrl(name);
} catch (err) {
assert.strictEqual(err.message, 'can not get the object URL when endpoint is IP');
throw err;
}
}, Error);

await assert.rejects(tempStore.asyncSignatureUrl(testSignatureObjectName), err => {
assert.strictEqual(err.message, 'can not get the object URL when endpoint is IP');

return true;
});
});

it('should signature url with traffic limit', async () => {
Expand Down

0 comments on commit a0b4063

Please sign in to comment.