Skip to content

Commit

Permalink
fix: validate action of getSignedUrl() function (#684)
Browse files Browse the repository at this point in the history
* validate action of getSignedUrl() function

* use existing enum for validation
  • Loading branch information
AVaksman authored May 1, 2019
1 parent 8b40e6a commit 1b09d24
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,10 @@ class File extends ServiceObject<File> {

const method = ActionToHTTPMethod[cfg.action];

if (!method) {
throw new Error('The action is not provided or invalid.');
}

const name = encodeURIComponent(this.name);
const resource = `/${this.bucket.name}/${name}`;

Expand Down
22 changes: 22 additions & 0 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2556,6 +2556,28 @@ describe('File', () => {
}, /Invalid signed URL version: v42\. Supported versions are 'v2' and 'v4'\./);
});

it('should error if action is null', () => {
const config = Object.assign({}, CONFIG, {action: null});
assert.throws(() => {
file.getSignedUrl(config, () => {});
}, /The action is not provided or invalid./);
});

it('should error if action is undefined', () => {
const config = Object.assign({}, CONFIG);
delete config.action;
assert.throws(() => {
file.getSignedUrl(config, () => {});
}, /The action is not provided or invalid./);
});

it('should error for an invalid action', () => {
const config = Object.assign({}, CONFIG, {action: 'watch'});
assert.throws(() => {
file.getSignedUrl(config, () => {});
}, /The action is not provided or invalid./);
});

describe('v4 signed URL', () => {
beforeEach(() => {
CONFIG.version = 'v4';
Expand Down

0 comments on commit 1b09d24

Please sign in to comment.