From c1f06c5146786babd10b39814c3cee54f81de643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A1=BA=E5=88=9A?= <735073554@qq.com> Date: Fri, 25 Aug 2023 17:12:58 +0800 Subject: [PATCH] test: add test refreshSTSToken() to browser test case (#1231) * test: add test refreshSTSToken() to browser test case * fix: use assert.fail --------- Co-authored-by: csg01123119 Co-authored-by: Undefined --- test/browser/browser.test.js | 28 ++++++++++++++++++++++++++++ test/node/sts.test.js | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/test/browser/browser.test.js b/test/browser/browser.test.js index 3a9886d52..7f3fb930b 100644 --- a/test/browser/browser.test.js +++ b/test/browser/browser.test.js @@ -2484,4 +2484,32 @@ describe('browser', () => { assert.strictEqual(res.res.headers['x-oss-next-append-position'], '6'); }); }); + + describe('refreshSTSToken()', () => { + let store; + before(async () => { + store = oss({ ...ossConfig, refreshSTSTokenInterval: 1000 }); + }); + + it('should refresh sts token when token is expired', async () => { + try { + const temp = { accessKeySecret: 's', accessKeyId: 'a', stsToken: 's' }; + store.options.refreshSTSToken = async () => { + mm.restore(); + return temp; + }; + const { accessKeyId: ak } = store.options; + await store.listV2({ 'max-keys': 1 }); + assert.strictEqual(ak, store.options.accessKeyId); + await sleep(2000); + try { + await store.listV2({ 'max-keys': 1 }); + } catch (e) { + assert.strictEqual(store.options.stsToken, temp.stsToken); + } + } catch (error) { + assert.fail(error); + } + }); + }); }); diff --git a/test/node/sts.test.js b/test/node/sts.test.js index 8f3ffe96d..710eac46d 100644 --- a/test/node/sts.test.js +++ b/test/node/sts.test.js @@ -196,7 +196,7 @@ describe('test/sts.test.js', () => { await store.listBuckets(); assert.notStrictEqual(ak, store.options.accessKeyId); } catch (error) { - assert(false, error); + assert.fail(error); } });