Skip to content

Commit 1b09d24

Browse files
authored
fix: validate action of getSignedUrl() function (#684)
* validate action of getSignedUrl() function * use existing enum for validation
1 parent 8b40e6a commit 1b09d24

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/file.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,10 @@ class File extends ServiceObject<File> {
23342334

23352335
const method = ActionToHTTPMethod[cfg.action];
23362336

2337+
if (!method) {
2338+
throw new Error('The action is not provided or invalid.');
2339+
}
2340+
23372341
const name = encodeURIComponent(this.name);
23382342
const resource = `/${this.bucket.name}/${name}`;
23392343

test/file.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,6 +2556,28 @@ describe('File', () => {
25562556
}, /Invalid signed URL version: v42\. Supported versions are 'v2' and 'v4'\./);
25572557
});
25582558

2559+
it('should error if action is null', () => {
2560+
const config = Object.assign({}, CONFIG, {action: null});
2561+
assert.throws(() => {
2562+
file.getSignedUrl(config, () => {});
2563+
}, /The action is not provided or invalid./);
2564+
});
2565+
2566+
it('should error if action is undefined', () => {
2567+
const config = Object.assign({}, CONFIG);
2568+
delete config.action;
2569+
assert.throws(() => {
2570+
file.getSignedUrl(config, () => {});
2571+
}, /The action is not provided or invalid./);
2572+
});
2573+
2574+
it('should error for an invalid action', () => {
2575+
const config = Object.assign({}, CONFIG, {action: 'watch'});
2576+
assert.throws(() => {
2577+
file.getSignedUrl(config, () => {});
2578+
}, /The action is not provided or invalid./);
2579+
});
2580+
25592581
describe('v4 signed URL', () => {
25602582
beforeEach(() => {
25612583
CONFIG.version = 'v4';

0 commit comments

Comments
 (0)