From cfa9b4a3f36f7fd781d3177a03e79e2671e0dcc9 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Thu, 30 Jul 2020 17:03:59 -0400 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20improve=20test=20coverag?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/core/app/routes/scopes.js | 7 +++---- .../tests/acceptance/authentication-test.js | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ui/core/app/routes/scopes.js b/ui/core/app/routes/scopes.js index 337b319c9..4f53d4955 100644 --- a/ui/core/app/routes/scopes.js +++ b/ui/core/app/routes/scopes.js @@ -5,14 +5,13 @@ export default class ScopesRoute extends Route { // =methods /** - * Attempt to load the specified scope from the API. This is allowed + * Attempt to load all scopes from the API. This is allowed * to fail, since in some cases the user may not have permission to read a * scope directly, but may have permission to read resources under it. - * If the scope fails to load, we still proceed using a temporary scope object - * consisting of only the specified ID. + * If scopes fails to load, we still proceed using an empty array. * @param {object} params * @param {string} params.scope_id - * @return {Promise{ScopeModel}} + * @return {Promise{[ScopeModel]}} */ model() { // NOTE: In the absence of a `scope_id` query parameter, this endpoint is diff --git a/ui/core/tests/acceptance/authentication-test.js b/ui/core/tests/acceptance/authentication-test.js index 3481337bb..f16a531bb 100644 --- a/ui/core/tests/acceptance/authentication-test.js +++ b/ui/core/tests/acceptance/authentication-test.js @@ -2,6 +2,7 @@ import { module, test } from 'qunit'; import { visit, currentURL, fillIn, click, find } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; import a11yAudit from 'ember-a11y-testing/test-support/audit'; import { currentSession, @@ -56,6 +57,26 @@ module('Acceptance | authentication', function (hooks) { assert.equal(currentURL(), authMethodAuthenticateURL); }); + test('visiting auth method when the scope cannot be loaded is still allowed', async function (assert) { + assert.expect(1); + orgScope.destroy(); + this.server.get('/scopes', ({ scopes }, { queryParams: { scope_id } }) => { + // Default parent scope is global + if (!scope_id) scope_id = 'global'; + const results = scopes.where(scope => { + return scope.scope ? scope.scope.id === scope_id : false + }); + if (!results.length) { + return new Response(404); + } else { + return results; + } + }); + await visit(authMethodAuthenticateURL); + await a11yAudit(); + assert.equal(currentURL(), authMethodAuthenticateURL); + }); + test('visiting any authentication parent route while unauthenticated redirects to first authenticate method', async function (assert) { assert.expect(3); await visit(indexURL);