Skip to content

Commit

Permalink
✅ Check for -admin in URL during init (#89)
Browse files Browse the repository at this point in the history
Resolves: OKTA-156927
  • Loading branch information
jmelberg-okta authored Jan 29, 2018
1 parent ccd7b2e commit 36b347f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/clientBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ function OktaAuthBuilder(args) {
'Required usage: new OktaAuth({url: "https://sample.okta.com"})');
}

if (args.url.indexOf('-admin.') !== -1) {
throw new AuthSdkError('URL passed to constructor contains "-admin" in subdomain. ' +
'Required usage: new OktaAuth({url: "https://dev-12345.okta.com})');
}

this.options = {
url: util.removeTrailingSlash(args.url),
clientId: args.clientId,
Expand Down
11 changes: 11 additions & 0 deletions test/spec/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,16 @@ define(function(require) {
'Required usage: new OktaAuth({url: "https://sample.okta.com"})');
});

it('throw an error if url contains "-admin" when passed to the constructor', function () {
var err;
try {
new OktaAuth({url: 'https://dev-12345-admin.oktapreview.com'}); // eslint-disable-line no-new
} catch (e) {
err = e;
}
expect(err.name).toEqual('AuthSdkError');
expect(err.errorSummary).toEqual('URL passed to constructor contains "-admin" in subdomain. ' +
'Required usage: new OktaAuth({url: "https://dev-12345.okta.com})');
});
});
});

0 comments on commit 36b347f

Please sign in to comment.