From 74b399b122ef830ad93c8d45dfe1fd7b3f068a19 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Tue, 18 Aug 2020 16:49:45 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20all=20top=20level=20route?= =?UTF-8?q?s=20should=20redirect=20in=20unauthenticated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/core/app/routes/scopes/scope/auth-methods.js | 8 ++++++++ ui/core/app/routes/scopes/scope/groups.js | 8 ++++++++ ui/core/app/routes/scopes/scope/orgs.js | 8 ++++++++ ui/core/app/routes/scopes/scope/roles.js | 8 ++++++++ ui/core/app/routes/scopes/scope/users.js | 8 ++++++++ ui/core/tests/unit/authenticators/password-test.js | 6 ------ 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/ui/core/app/routes/scopes/scope/auth-methods.js b/ui/core/app/routes/scopes/scope/auth-methods.js index ffad801fa..0e35b2c28 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods.js +++ b/ui/core/app/routes/scopes/scope/auth-methods.js @@ -7,9 +7,17 @@ export default class ScopesScopeAuthMethodsRoute extends Route { @service intl; @service notify; + @service session; // =methods + /** + * If arriving here unauthenticated, redirect to index for further processing. + */ + beforeModel() { + if (!this.session.isAuthenticated) this.transitionTo('index'); + } + /** * Load all auth-methods under current scope * @return {Promise[AuthMethodModel]} diff --git a/ui/core/app/routes/scopes/scope/groups.js b/ui/core/app/routes/scopes/scope/groups.js index 7eed4406e..c2c75c8fb 100644 --- a/ui/core/app/routes/scopes/scope/groups.js +++ b/ui/core/app/routes/scopes/scope/groups.js @@ -7,9 +7,17 @@ export default class ScopesScopeGroupsRoute extends Route { @service intl; @service notify; + @service session; // =methods + /** + * If arriving here unauthenticated, redirect to index for further processing. + */ + beforeModel() { + if (!this.session.isAuthenticated) this.transitionTo('index'); + } + /** * Load all groups under current scope * @return {Promise[GroupModel]} diff --git a/ui/core/app/routes/scopes/scope/orgs.js b/ui/core/app/routes/scopes/scope/orgs.js index f25a91cf9..c2fa56ffc 100644 --- a/ui/core/app/routes/scopes/scope/orgs.js +++ b/ui/core/app/routes/scopes/scope/orgs.js @@ -8,9 +8,17 @@ export default class ScopesScopeOrgsRoute extends Route { @service intl; @service notify; + @service session; // =methods + /** + * If arriving here unauthenticated, redirect to index for further processing. + */ + beforeModel() { + if (!this.session.isAuthenticated) this.transitionTo('index'); + } + /** * Loads all scopes under the global scope. * @return {Promise{[ScopeModel]}} diff --git a/ui/core/app/routes/scopes/scope/roles.js b/ui/core/app/routes/scopes/scope/roles.js index 84cf2ae0f..b0418e399 100644 --- a/ui/core/app/routes/scopes/scope/roles.js +++ b/ui/core/app/routes/scopes/scope/roles.js @@ -7,9 +7,17 @@ export default class ScopesScopeRolesRoute extends Route { @service intl; @service notify; + @service session; // =methods + /** + * If arriving here unauthenticated, redirect to index for further processing. + */ + beforeModel() { + if (!this.session.isAuthenticated) this.transitionTo('index'); + } + /** * Load all roles under current scope. * @return {Promise{[RoleModel]}} diff --git a/ui/core/app/routes/scopes/scope/users.js b/ui/core/app/routes/scopes/scope/users.js index f1982b769..20731c90f 100644 --- a/ui/core/app/routes/scopes/scope/users.js +++ b/ui/core/app/routes/scopes/scope/users.js @@ -7,9 +7,17 @@ export default class ScopesScopeUsersRoute extends Route { @service intl; @service notify; + @service session; // =methods + /** + * If arriving here unauthenticated, redirect to index for further processing. + */ + beforeModel() { + if (!this.session.isAuthenticated) this.transitionTo('index'); + } + /** * Load all users under current scope. * @return {Promise{[UserModel]}} diff --git a/ui/core/tests/unit/authenticators/password-test.js b/ui/core/tests/unit/authenticators/password-test.js index 21786ec86..8bf59c9ee 100644 --- a/ui/core/tests/unit/authenticators/password-test.js +++ b/ui/core/tests/unit/authenticators/password-test.js @@ -23,12 +23,6 @@ module('Unit | Authenticator | password', function (hooks) { session.invalidate(); }); - test('it does not add an authorization header to application adapter on restore if no token is present', async function (assert) { - assert.expect(1); - authenticator.restore({ token: null }); - assert.notOk(applicationAdapter?.headers?.Authorization); - }); - test('it adds an authorization header to application adapter on restore', async function (assert) { assert.expect(1); authenticator.restore({ token: 'token1234' });