From 36b347f0fce633c94ff092f5c142cd58642f9cff Mon Sep 17 00:00:00 2001 From: Jordan Melberg Date: Mon, 29 Jan 2018 15:52:48 -0800 Subject: [PATCH] :white_check_mark: Check for -admin in URL during init (#89) Resolves: OKTA-156927 --- lib/clientBuilder.js | 5 +++++ test/spec/errors.js | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/clientBuilder.js b/lib/clientBuilder.js index f0304d9c7..f6650b1d6 100644 --- a/lib/clientBuilder.js +++ b/lib/clientBuilder.js @@ -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, diff --git a/test/spec/errors.js b/test/spec/errors.js index e86878714..d3b7cca9a 100644 --- a/test/spec/errors.js +++ b/test/spec/errors.js @@ -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})'); + }); }); });