Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
test(oauth): cover the remaining OAuth branches, drop three unreachable ones
Ronald A. Richardsondcf034ec93aa
diff --git a/console/app/controllers/auth/oauth-callback.js b/console/app/controllers/auth/oauth-callback.jsindex e8d7e369..fd6df49d 100644--- a/console/app/controllers/auth/oauth-callback.js+++ b/console/app/controllers/auth/oauth-callback.js@@ -173,11 +173,8 @@ export default class AuthOauthCallbackController extends Controller {return;}- const route = pathToRoute(returnTo);-- if (route) {- this.session.setRedirect(route);- }+ // pathToRoute always yields a route (it prefixes `console.`), so no further check.+ this.session.setRedirect(pathToRoute(returnTo));}/**diff --git a/console/app/routes/auth/oauth-callback.js b/console/app/routes/auth/oauth-callback.jsindex 15a94b3e..0483706b 100644--- a/console/app/routes/auth/oauth-callback.js+++ b/console/app/routes/auth/oauth-callback.js@@ -44,7 +44,7 @@ export default class AuthOauthCallbackRoute extends Route {* @return {Object}*/readFragment() {- const hash = String(window.location.hash ?? '').replace(/^#/, '');+ const hash = window.location.hash.replace(/^#/, '');const params = new URLSearchParams(hash);const payload = {@@ -78,7 +78,7 @@ export default class AuthOauthCallbackRoute extends Route {// ember-window-mock's mocked location. Assigning is the reliable floor, and in// a real browser the check above has already cleared the hash so this is a// no-op rather than a second history entry.- if (String(window.location.hash ?? '').replace(/^#/, '') !== '') {+ if (window.location.hash.replace(/^#/, '') !== '') {window.location.hash = '';}}diff --git a/console/tests/integration/components/configure/oauth-test.js b/console/tests/integration/components/configure/oauth-test.jsindex fd2b7561..7d615237 100644--- a/console/tests/integration/components/configure/oauth-test.js+++ b/console/tests/integration/components/configure/oauth-test.js@@ -372,4 +372,43 @@ module('Integration | Component | configure/oauth', function (hooks) {assert.deepEqual(component.savedEnabled, {});assert.deepEqual(component.panelOpen, {});});++ test('it copes with a sparse or missing configuration', async function (assert) {+ const captured = captureComponent(this.owner, 'configure/oauth', ConfigureOauthComponent);+ await render(hbs`<div id="next-view-section-subheader-actions"></div><Configure::Oauth />`);+ const component = captured.instance;++ // Nothing at all: defaults, not a crash.+ component.applyConfig();+ assert.deepEqual(component.providers, []);+ assert.deepEqual(component.redirectUris, {});+ assert.true(component.enabled);+ assert.true(component.allowRegistration);+ assert.true(component.autoLink);++ // A provider the server has no settings for yet, and a malformed provider list.+ component.applyConfig({ providers: 'not-a-list' });+ assert.deepEqual(component.providers, []);++ component.applyConfig({+ oauth: { enabled: false, allow_registration: false, auto_link: false },+ providers: [{ id: 'okta', label: 'Okta', schema: { domain: { label: 'Domain' }, client_secret: { label: 'Secret', secret: true } } }],+ });+ assert.false(component.enabled);+ assert.false(component.allowRegistration);+ assert.false(component.autoLink);+ assert.deepEqual(component.values.okta, { enabled: false, domain: '', client_secret: '' });+ assert.deepEqual(component.secretStatus.okta, { client_secret: { configured: false, hint: null } });+ assert.strictEqual(component.valueFor('okta', 'domain'), '');+ assert.strictEqual(component.valueFor('nobody', 'domain'), '');++ // Editing a provider the form has no values for yet starts its entry.+ component.values = {};+ component.updateField('okta', 'domain', 'example.okta.com');+ assert.deepEqual(component.values.okta, { domain: 'example.okta.com' });++ // Serialising a provider with no values sends it switched off, with blank fields.+ component.values = {};+ assert.deepEqual(component.serialize().providers.okta, { enabled: false, domain: '' });+ });});diff --git a/console/tests/integration/components/onboarding/form-test.js b/console/tests/integration/components/onboarding/form-test.jsindex 18875169..7d90618b 100644--- a/console/tests/integration/components/onboarding/form-test.js+++ b/console/tests/integration/components/onboarding/form-test.js@@ -416,4 +416,16 @@ module('Integration | Component | onboarding/form | onboard', function (hooks) {assert.false(component.isStartingProvider);assert.false(component.emailVerifiedByProvider);});++ test('an intent without a prefill starts empty and unlocked', async function (assert) {+ const captured = captureComponent(this.owner, 'onboarding/form', OnboardingFormComponent);+ this.owner.lookup('service:oauth').setRegistration({ intent: 'rti_abc' });++ await render(hbs`<Onboarding::Form />`);++ assert.strictEqual(captured.instance.name, null);+ assert.strictEqual(captured.instance.email, null);+ assert.false(captured.instance.emailVerifiedByProvider);+ assert.false(captured.instance.isEmailLocked);+ });});diff --git a/console/tests/unit/controllers/auth/oauth-callback-test.js b/console/tests/unit/controllers/auth/oauth-callback-test.jsindex 24a955b1..f1483d37 100644--- a/console/tests/unit/controllers/auth/oauth-callback-test.js+++ b/console/tests/unit/controllers/auth/oauth-callback-test.js@@ -290,4 +290,42 @@ module('Unit | Controller | auth/oauth-callback', function (hooks) {assert.strictEqual(controller.error, null);assert.true(controller.isExchanging);});++ test('a link that fails with a code it does not know shows the generic link failure', async function (assert) {+ const controller = this.controller;+ controller.oauth.completeLink = () => Promise.reject({ code: 'something_new' });++ await controller.start({ handoff: 'link-code', intent: 'link' });+ await controller.start({ error: 'something_else', intent: 'link' });++ assert.deepEqual(this.notified.errors, ['auth.login.oauth.errors.link-failed', 'auth.login.oauth.errors.link-failed']);+ });++ test('with nothing to go on it fails closed rather than throwing', async function (assert) {+ const controller = this.controller;++ await controller.start();+ await controller.handle();++ assert.deepEqual(this.manualTokens, [], 'no session');+ assert.strictEqual(this.notified.errors.length, 2, 'both report a failure');+ });++ test('an automatic link without a label names the provider by its id', async function (assert) {+ this.exchangeResult = () => Promise.resolve({ token: 'sanctum-token', type: 'user', linked: 'okta' });+ const calls = [];+ Object.defineProperty(this.controller.intl, 't', { configurable: true, value: (key, options) => (calls.push([key, options]), key) });++ await this.controller.start({ handoff: 'handoff-code' });++ assert.deepEqual(calls, [['auth.login.oauth.auto-linked', { provider: 'okta' }]]);+ });++ test('a registration intent without a prefill starts an empty form', async function (assert) {+ this.exchangeResult = () => Promise.resolve({ status: 'registration_required', intent: 'rti_abc' });++ await this.controller.start({ handoff: 'handoff-code' });++ assert.deepEqual(this.controller.oauth.registration, { intent: 'rti_abc', prefill: {} });+ });});diff --git a/console/tests/unit/services/oauth-test.js b/console/tests/unit/services/oauth-test.jsindex 9992613e..b475ab73 100644--- a/console/tests/unit/services/oauth-test.js+++ b/console/tests/unit/services/oauth-test.js@@ -208,4 +208,23 @@ module('Unit | Service | oauth', function (hooks) {assert.false(service.isLoading);assert.strictEqual(service.registration, null);});++ test('authorization defaults to a sign-in with no return path', function (assert) {+ const service = this.owner.lookup('service:oauth');++ service.startAuthorization('google');++ const url = new URL(String(window.location.href));+ assert.strictEqual(url.searchParams.get('intent'), 'login');+ assert.strictEqual(url.searchParams.get('return_to'), null);+ });++ test('setting no registration clears it', function (assert) {+ const service = this.owner.lookup('service:oauth');+ service.setRegistration({ intent: 'rti_abc' });++ service.setRegistration(undefined);++ assert.strictEqual(service.registration, null);+ });});