Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion strategies/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const passport = require('passport'),
* @param {function} done
*/
function apiCallback(apikey, done) {
if (apikey === process.env.CLAY_ACCESS_KEY) {
if (apikey === process.env.CLAY_ACCESS_KEY ||
apikey === process.env.PREVIOUS_CLAY_ACCESS_KEY) {
// If we're using an API Key then we're assuming the user is
// has admin privileges by defining the auth level in the next line
done(null, { provider: 'apikey', auth: 'admin' });
Expand Down
20 changes: 19 additions & 1 deletion strategies/key.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,33 @@ describe(_startCase(filename), function () {
});
});

it('disallows api key that does not match CLAY_ACCESS_KEY', function (done) {
it('allows an api key that matches PREVIOUS_CLAY_ACCESS_KEY', function (done) {
const oldKey = process.env.CLAY_ACCESS_KEY;
const olderKey = process.env.PREVIOUS_CLAY_ACCESS_KEY;

process.env.CLAY_ACCESS_KEY = '123';
process.env.PREVIOUS_CLAY_ACCESS_KEY = '789';
fn('789', function (err, data) {
expect(err).toEqual(null);
expect(data).toEqual({ provider: 'apikey', auth: 'admin' });
process.env.CLAY_ACCESS_KEY = oldKey;
process.env.PREVIOUS_CLAY_ACCESS_KEY = olderKey;
done();
});
});

it('disallows api key that does not match CLAY_ACCESS_KEY or PREVIOUS_CLAY_ACCESS_KEY', function (done) {
const oldKey = process.env.CLAY_ACCESS_KEY;
const olderKey = process.env.PREVIOUS_CLAY_ACCESS_KEY;

process.env.CLAY_ACCESS_KEY = '123';
process.env.PREVIOUS_CLAY_ACCESS_KEY = '789';
fn('456', function (err, data, status) {
expect(err).toEqual(null);
expect(data).toEqual(false);
expect(status.message).toEqual('Unknown apikey: 456');
process.env.CLAY_ACCESS_KEY = oldKey;
process.env.PREVIOUS_CLAY_ACCESS_KEY = olderKey;
done();
});
});
Expand Down