forked from philippschulte/fastly-promises
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fastly): Return undefined for dict values of write-only edge dicts
Getting the value of an edge dictionary value for a write-only dictionary results in an error 400 from the Fastly API, which is correct, but not helpful. Because `readDictItem` always gets the dictionary metadata before reading, we can guard against this error and return a proper response (status: 403, item_value: undefined) fixes #27
- Loading branch information
Showing
4 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
/* eslint-env mocha */ | ||
|
||
const nock = require('nock'); | ||
const expect = require('expect'); | ||
const config = require('../src/config'); | ||
const fastlyPromises = require('../src/index'); | ||
const response = require('./response/dictitem.response'); | ||
|
||
describe('#readDictItem', () => { | ||
const fastly = fastlyPromises('923b6bd5266a7f932e41962755bd4254', 'SU1Z0isxPaozGVKXdv0eY'); | ||
let res; | ||
|
||
nock(config.mainEntryPoint) | ||
// get the dictionary first | ||
.get('/service/SU1Z0isxPaozGVKXdv0eY/version/1/dictionary/my_dictionary') | ||
.reply(200, response.dict.get) | ||
// list | ||
.get('/service/SU1Z0isxPaozGVKXdv0eY/dictionary/5clCytcTJrnvPi8wjqPH0q/item/some_key') | ||
.reply(200, response.item.get); | ||
|
||
before(async () => { | ||
res = await fastly.readDictItem(1, 'my_dictionary', 'some_key'); | ||
}); | ||
|
||
it('response should be a status 200', () => { | ||
expect(res.status).toBe(200); | ||
}); | ||
|
||
it('response body should exist', () => { | ||
expect(res.data).toBeTruthy(); | ||
}); | ||
|
||
it('response body should be an object', () => { | ||
expect(typeof res.data).toBe('object'); | ||
}); | ||
|
||
it('response value should match', () => { | ||
expect(res.data.item_value).toBe('some_value'); | ||
}); | ||
|
||
it('response body should contain all properties', () => { | ||
[ | ||
'dictionary_id', | ||
'service_id', | ||
'item_key', | ||
'item_value', | ||
'created_at', | ||
'deleted_at', | ||
'updated_at', | ||
].forEach((e) => { | ||
expect(Object.keys(res.data)).toContain(e); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
/* eslint-env mocha */ | ||
|
||
const nock = require('nock'); | ||
const expect = require('expect'); | ||
const config = require('../src/config'); | ||
const fastlyPromises = require('../src/index'); | ||
const response = require('./response/dictitem.response'); | ||
|
||
describe('#readDictItem (write-only)', () => { | ||
const fastly = fastlyPromises('923b6bd5266a7f932e41962755bd4254', 'SU1Z0isxPaozGVKXdv0eY'); | ||
let res; | ||
|
||
nock(config.mainEntryPoint) | ||
// get the dictionary first | ||
.get('/service/SU1Z0isxPaozGVKXdv0eY/version/1/dictionary/secret_dictionary') | ||
.reply(200, response.dict.getsecret); | ||
|
||
before(async () => { | ||
res = await fastly.readDictItem(1, 'secret_dictionary', 'some_key'); | ||
}); | ||
|
||
it('response should be a status 200', () => { | ||
expect(res.status).toBe(403); | ||
}); | ||
|
||
it('response body should exist', () => { | ||
expect(res.data).toBeTruthy(); | ||
}); | ||
|
||
it('response body should be an object', () => { | ||
expect(typeof res.data).toBe('object'); | ||
}); | ||
|
||
it('response value should match', () => { | ||
expect(res.data.item_value).toBeUndefined(); | ||
expect(res.data.created_at).toBeUndefined(); | ||
expect(res.data.deleted_at).toBeUndefined(); | ||
expect(res.data.updated_at).toBeUndefined(); | ||
}); | ||
|
||
it('response body should contain all properties', () => { | ||
[ | ||
'dictionary_id', | ||
'service_id', | ||
'item_key', | ||
'item_value', | ||
'created_at', | ||
'deleted_at', | ||
'updated_at', | ||
].forEach((e) => { | ||
expect(Object.keys(res.data)).toContain(e); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters