Skip to content

Commit

Permalink
Interpret any string in options as an API Key instead of using a regex (
Browse files Browse the repository at this point in the history
#660)

* Interpret any string in options as an API Key instead of using a regex

* Remove isAuthKey entirely
  • Loading branch information
rattrayalex-stripe committed Jul 24, 2019
1 parent 3c818df commit 3bda64c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ const OPTIONS_KEYS = [
];

const utils = (module.exports = {
isAuthKey: (key) => {
return typeof key == 'string' && /^(?:[a-z]{2}_)?[A-z0-9]{32}$/.test(key);
},

isOptionsHash: (o) => {
return isPlainObject(o) && OPTIONS_KEYS.some((key) => hasOwn.call(o, key));
},
Expand Down Expand Up @@ -121,7 +117,7 @@ const utils = (module.exports = {
};
if (args.length > 0) {
const arg = args[args.length - 1];
if (utils.isAuthKey(arg)) {
if (typeof arg === 'string') {
opts.auth = args.pop();
} else if (utils.isOptionsHash(arg)) {
const params = args.pop();
Expand Down
8 changes: 8 additions & 0 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ describe('utils', () => {
});
expect(args.length).to.equal(0);
});
it('assumes any string is an api key', () => {
const args = ['yolo'];
expect(utils.getOptionsFromArgs(args)).to.deep.equal({
auth: 'yolo',
headers: {},
});
expect(args.length).to.equal(0);
});
it('parses an idempotency key', () => {
const args = [{foo: 'bar'}, {idempotency_key: 'foo'}];
expect(utils.getOptionsFromArgs(args)).to.deep.equal({
Expand Down

0 comments on commit 3bda64c

Please sign in to comment.