Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosen host check #47

Merged
merged 1 commit into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Note that all calls must be authenticated using the API Key. However, if you pre
1. `args` _(Object)_: the required arguments object.
2. `args.key` _(string)_: The private API key obtained from the [Authy Dashboard](https://dashboard.authy.com/).
3. `[options]` _(Object)_: The options object.
4. `[options.host=https://api.authy.com]` _(string)_: The target endpoint (`https://api.authy.com` or `https://sandbox-api.authy.com`).
4. `[options.host=https://api.authy.com]` _(string)_: The target API endpoint.
5. `[options.timeout=5000]` _(number)_: The maximum request time, in milliseconds.

##### Example
Expand Down
2 changes: 1 addition & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function source(...args) {
export default class Client {
constructor({ key } = {}, { host = 'https://api.authy.com', timeout = 5000 } = {}) {
validate({ host, key, timeout }, {
host: [is.string(), is.choice(['https://api.authy.com', 'https://sandbox-api.authy.com'])],
host: is.string(),
key: [is.required(), is.notBlank()],
timeout: [is.integer(), is.greaterThanOrEqual(0)]
});
Expand Down
5 changes: 2 additions & 3 deletions test/client_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ describe('Client', () => {

it('should throw an error if `host` is invalid', () => {
try {
new Client({ key: 'foo' }, { host: 'https://foo.bar' });
new Client({ key: 'foo' }, { host: 123 });

should.fail();
} catch (e) {
e.should.be.instanceOf(ValidationFailedError);
e.errors.host[0].show().assert.should.equal('Choice');
e.errors.host[0].show().violation.choices.should.eql(['https://api.authy.com', 'https://sandbox-api.authy.com']);
e.errors.host[0].show().assert.should.equal('IsString');
}
});

Expand Down