Skip to content

Commit c1f06c5

Browse files
shungangcsg01123119PeterRao
authoredAug 25, 2023
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 <csg01123119@alibaba-inc.com> Co-authored-by: Undefined <peizerao@gmail.com>
1 parent 7656d6f commit c1f06c5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
 

‎test/browser/browser.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -2484,4 +2484,32 @@ describe('browser', () => {
24842484
assert.strictEqual(res.res.headers['x-oss-next-append-position'], '6');
24852485
});
24862486
});
2487+
2488+
describe('refreshSTSToken()', () => {
2489+
let store;
2490+
before(async () => {
2491+
store = oss({ ...ossConfig, refreshSTSTokenInterval: 1000 });
2492+
});
2493+
2494+
it('should refresh sts token when token is expired', async () => {
2495+
try {
2496+
const temp = { accessKeySecret: 's', accessKeyId: 'a', stsToken: 's' };
2497+
store.options.refreshSTSToken = async () => {
2498+
mm.restore();
2499+
return temp;
2500+
};
2501+
const { accessKeyId: ak } = store.options;
2502+
await store.listV2({ 'max-keys': 1 });
2503+
assert.strictEqual(ak, store.options.accessKeyId);
2504+
await sleep(2000);
2505+
try {
2506+
await store.listV2({ 'max-keys': 1 });
2507+
} catch (e) {
2508+
assert.strictEqual(store.options.stsToken, temp.stsToken);
2509+
}
2510+
} catch (error) {
2511+
assert.fail(error);
2512+
}
2513+
});
2514+
});
24872515
});

‎test/node/sts.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ describe('test/sts.test.js', () => {
196196
await store.listBuckets();
197197
assert.notStrictEqual(ak, store.options.accessKeyId);
198198
} catch (error) {
199-
assert(false, error);
199+
assert.fail(error);
200200
}
201201
});
202202

0 commit comments

Comments
 (0)
Please sign in to comment.