Skip to content

Commit ececae6

Browse files
dominiciampogo
authored andcommitted
sdk/node: prevent v1.x params for tag updating
Closes #3331 Author: Dominic Dagradi <ddagradi@gmail.com> Date: Mon Apr 16 10:17:37 2018 -0700 upstream:6237025e5908eef83f260feac5e5908f106b7610
1 parent cd9d25a commit ececae6

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/api/accounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const accountsAPI = (client: Client) => {
7575
* @returns {Promise<Object>} Success message.
7676
*/
7777
updateTags: (params: UpdateTagsRequest) =>
78-
client.request('/update-account-tags', params),
78+
client.request('/update-account-tags', params, 'UpdateTagsSchema'),
7979

8080
/**
8181
* Query a list of accounts matching the specified query.

src/api/flavors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const flavorsAPI = (client: Client) => {
7474
* @returns {Promise<Object>} Success message.
7575
*/
7676
updateTags: (params: UpdateTagsRequest) =>
77-
client.request('/update-flavor-tags', params),
77+
client.request('/update-flavor-tags', params, 'UpdateTagsSchema'),
7878

7979
/**
8080
* Query a list of flavors matching the specified query.

src/validate.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,14 @@ ajv.addSchema(
3535
},
3636
'CreateAccountOrFlavorSchema'
3737
)
38+
39+
ajv.addSchema(
40+
{
41+
properties: {
42+
id: { type: 'string' },
43+
tags: { type: 'object' },
44+
},
45+
additionalProperties: false,
46+
},
47+
'UpdateTagsSchema'
48+
)

test/validateSchema.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ describe('Schemas', () => {
2121
})
2222
})
2323

24+
it('rejects tag updates with alias', () => {
25+
return client.accounts.updateTags({alias: 'foo', tags: {foo: 'bar'}})
26+
.then(() => assert(false, 'should not accept `alias` field'))
27+
.catch(err => {
28+
expect(err.message).to.contain("should NOT have additional properties '.alias'")
29+
})
30+
})
31+
2432
it('rejects creation with keys', () => {
2533
return client.accounts.create({ keys: [1,2,3] })
2634
.then(() => assert(false, 'should not accept `keys` field'))
@@ -39,6 +47,14 @@ describe('Schemas', () => {
3947
})
4048
})
4149

50+
it('rejects tag updates with alias', () => {
51+
return client.flavors.updateTags({alias: 'foo', tags: {foo: 'bar'}})
52+
.then(() => assert(false, 'should not accept `alias` field'))
53+
.catch(err => {
54+
expect(err.message).to.contain("should NOT have additional properties '.alias'")
55+
})
56+
})
57+
4258
it('rejects creation with keys', () => {
4359
return client.flavors.create({ keys: [1,2,3] })
4460
.then(() => assert(false, 'should not accept `keys` field'))

0 commit comments

Comments
 (0)