From a0b4063b9fa18891e42f5c4b2790ed18f673e998 Mon Sep 17 00:00:00 2001 From: YunZZY <1263206327@qq.com> Date: Mon, 18 Dec 2023 13:44:29 +0800 Subject: [PATCH] test: add test cases for signatureUrl and asyncSignatureUrl (#1271) --- CHANGELOG.md | 2 +- test/browser/browser.test.js | 37 +++++++++++++++++++++++++++++++++++- test/node/object.test.js | 36 ++++++++++++++++++++++++++++++++--- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c07b78c4..c94f0d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/test/browser/browser.test.js b/test/browser/browser.test.js index 53eefcc2..9e32f577 100644 --- a/test/browser/browser.test.js +++ b/test/browser/browser.test.js @@ -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 () => { diff --git a/test/node/object.test.js b/test/node/object.test.js index 57a3a249..eddef672 100644 --- a/test/node/object.test.js +++ b/test/node/object.test.js @@ -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); @@ -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; @@ -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 () => {