Skip to content

Commit cd9d25a

Browse files
dominiciampogo
authored andcommitted
sdk/node: prevent v1.x params for flavors.create
While Flavors have always been a forward-looking endpoint, users will attempt to find/replace `assets` with `flavors` and we should catch the bad parameter errors in the same way as `account`. Closes #3329 Author: Dominic Dagradi <ddagradi@gmail.com> Date: Mon Apr 16 10:15:39 2018 -0700 upstream:8ec4fbf18396efea3fa8623ca936a7647158043d
1 parent aa90f9b commit cd9d25a

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/api/accounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const accountsAPI = (client: Client) => {
6666
* @returns {Promise<Account>} Newly created account.
6767
*/
6868
create: (params: CreateRequest) =>
69-
client.request('/create-account', params, 'CreateAccountSchema'),
69+
client.request('/create-account', params, 'CreateAccountOrFlavorSchema'),
7070

7171
/**
7272
* Update account tags.

src/api/flavors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export const flavorsAPI = (client: Client) => {
6464
* @param {module:FlavorsApi~createRequest} params - Parameters for flavor creation.
6565
* @returns {Promise<Flavor>} Newly created flavor.
6666
*/
67-
create: (params: CreateRequest) => client.request('/create-flavor', params),
67+
create: (params: CreateRequest) =>
68+
client.request('/create-flavor', params, 'CreateAccountOrFlavorSchema'),
6869

6970
/**
7071
* Update flavor tags.

src/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ ajv.addSchema(
3333
},
3434
additionalProperties: false,
3535
},
36-
'CreateAccountSchema'
36+
'CreateAccountOrFlavorSchema'
3737
)

test/validateSchema.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,32 @@ describe('Schemas', () => {
2020
expect(err.message).to.contain("should NOT have additional properties '.alias'")
2121
})
2222
})
23+
24+
it('rejects creation with keys', () => {
25+
return client.accounts.create({ keys: [1,2,3] })
26+
.then(() => assert(false, 'should not accept `keys` field'))
27+
.catch(err => {
28+
expect(err.message).to.contain("should NOT have additional properties '.keys'")
29+
})
30+
})
31+
})
32+
33+
describe('Flavor', () => {
34+
it('rejects creation with alias', () => {
35+
return client.flavors.create({ alias: 'foo' })
36+
.then(() => assert(false, 'should not accept `alias` field'))
37+
.catch(err => {
38+
expect(err.message).to.contain("should NOT have additional properties '.alias'")
39+
})
40+
})
41+
42+
it('rejects creation with keys', () => {
43+
return client.flavors.create({ keys: [1,2,3] })
44+
.then(() => assert(false, 'should not accept `keys` field'))
45+
.catch(err => {
46+
expect(err.message).to.contain("should NOT have additional properties '.keys'")
47+
})
48+
})
2349
})
2450

2551
describe('Key', () => {

0 commit comments

Comments
 (0)