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

test: add test cases for signatureUrl and asyncSignatureUrl #1271

Merged
merged 1 commit into from
Dec 18, 2023
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
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
Loading