Skip to content

Commit

Permalink
test: add cases about signUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengzuoyu.zzy committed Jan 18, 2024
1 parent 8e7be93 commit 85c332b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
31 changes: 30 additions & 1 deletion test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,31 @@ describe('browser', () => {
});
});

it('signatureUrl will should use refreshSTSToken', async () => {
it('should set bucket when use signature V4', async () => {
const tempStore = oss(
Object.assign({}, ossConfig, moreConfigs, {
bucket: undefined
})
);

try {
await tempStore.signatureUrlV4('GET', 60, undefined, 'test.txt');
assert.fail('Expected getCanonicalRequest to throw an error');
} catch (err) {
assert.strictEqual(err.message, 'Please ensure that bucketName is passed into getCanonicalRequest.');
}
});

it('should additional headers are included in the request headers when use signature V4', async () => {
try {
await store.signatureUrlV4('GET', 60, undefined, 'test.txt', ['cache-control']);
assert.fail('Expected getCanonicalRequest to throw an error');
} catch (err) {
assert.strictEqual(err.message, "Can't find additional header cache-control in request headers.");
}
});

it('asyncSignatureUrl and signatureUrlV4 should use refreshSTSToken', async () => {
let flag = false;

store = oss({
Expand All @@ -1259,6 +1283,11 @@ describe('browser', () => {
await sleep(2000);
await store.asyncSignatureUrl('test.txt');
assert(flag);

flag = false;
await sleep(2000);
await store.signatureUrlV4('GET', 60, undefined, 'test.txt');
assert(flag);
});
});

Expand Down
19 changes: 19 additions & 0 deletions test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,25 @@ describe('test/object.test.js', () => {
});
assert.strictEqual(200, result.status);
});

it('should set bucket when use signature V4', async () => {
const conf = { ...config, ...moreConfigs, bucket: undefined };
const tempStore = oss(conf);

await assert.rejects(tempStore.signatureUrlV4('GET', 60, undefined, 'test.txt'), err => {
assert.strictEqual(err.message, 'Please ensure that bucketName is passed into getCanonicalRequest.');

return true;
});
});

it('should additional headers are included in the request headers when use signature V4', async () => {
await assert.rejects(store.signatureUrlV4('GET', 60, undefined, 'test.txt', ['cache-control']), err => {
assert.strictEqual(err.message, "Can't find additional header cache-control in request headers.");

return true;
});
});
});

describe('getStream()', () => {
Expand Down
7 changes: 6 additions & 1 deletion test/node/sts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('test/sts.test.js', () => {
}
});

it('asyncSignatureUrl will should use refreshSTSToken', async () => {
it('asyncSignatureUrl and signatureUrlV4 should use refreshSTSToken', async () => {
const { credentials } = await stsClient.assumeRole(stsConfig.roleArn);
let flag = false;

Expand All @@ -238,6 +238,11 @@ describe('test/sts.test.js', () => {
await store.asyncSignatureUrl('test.txt');

assert(flag);

flag = false;
await utils.sleep(2000);
await store.signatureUrlV4('GET', 60, undefined, 'test.txt');
assert(flag);
});
});
});
Expand Down

0 comments on commit 85c332b

Please sign in to comment.