Skip to content

Commit

Permalink
test: add test refreshSTSToken() to browser test case (#1231)
Browse files Browse the repository at this point in the history
* test: add test refreshSTSToken() to browser test case

* fix: use assert.fail

---------

Co-authored-by: csg01123119 <csg01123119@alibaba-inc.com>
Co-authored-by: Undefined <peizerao@gmail.com>
  • Loading branch information
3 people authored Aug 25, 2023
1 parent 7656d6f commit c1f06c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
});
2 changes: 1 addition & 1 deletion test/node/sts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down

0 comments on commit c1f06c5

Please sign in to comment.