From d5b54ad84c029a36f8c8c60a851ec623fdc4c78a Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 9 Jul 2020 20:34:44 -0700 Subject: [PATCH 1/2] Reset the system and refetch namespaces with every token change --- ui/app/controllers/settings/tokens.js | 5 +++-- ui/app/services/system.js | 1 + ui/app/templates/settings/tokens.hbs | 2 +- ui/tests/acceptance/token-test.js | 17 +++++++++++++++++ ui/tests/pages/settings/tokens.js | 1 + 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ui/app/controllers/settings/tokens.js b/ui/app/controllers/settings/tokens.js index 956268374..541431fb4 100644 --- a/ui/app/controllers/settings/tokens.js +++ b/ui/app/controllers/settings/tokens.js @@ -31,6 +31,8 @@ export default class Tokens extends Controller { tokenIsValid: false, tokenIsInvalid: false, }); + // Clear out all data to ensure only data the anonymous token is privileged to see is shown + this.system.reset(); this.resetStore(); this.token.reset(); } @@ -44,8 +46,7 @@ export default class Tokens extends Controller { TokenAdapter.findSelf().then( () => { - // Clear out all data to ensure only data the new token is privileged to - // see is shown + // Clear out all data to ensure only data the new token is privileged to see is shown this.system.reset(); this.resetStore(); diff --git a/ui/app/services/system.js b/ui/app/services/system.js index 3b293d5c4..1730777b5 100644 --- a/ui/app/services/system.js +++ b/ui/app/services/system.js @@ -128,5 +128,6 @@ export default class SystemService extends Service { reset() { this.set('activeNamespace', null); + this.notifyPropertyChange('namespaces'); } } diff --git a/ui/app/templates/settings/tokens.hbs b/ui/app/templates/settings/tokens.hbs index df600d93d..ef429db2e 100644 --- a/ui/app/templates/settings/tokens.hbs +++ b/ui/app/templates/settings/tokens.hbs @@ -12,7 +12,7 @@

Tokens are stored client-side in local storage. This will persist your token across sessions. You can manually clear your token here.

- +
diff --git a/ui/tests/acceptance/token-test.js b/ui/tests/acceptance/token-test.js index cba90e6a2..7109f5b72 100644 --- a/ui/tests/acceptance/token-test.js +++ b/ui/tests/acceptance/token-test.js @@ -141,6 +141,23 @@ module('Acceptance | tokens', function(hooks) { assert.notOk(find('[data-test-job-row]'), 'No jobs found'); }); + test('when namespaces are enabled, setting or clearing a token refetches namespaces available with new permissions', async function(assert) { + const { secretId } = clientToken; + + server.createList('namespace', 2); + await Tokens.visit(); + + const requests = server.pretender.handledRequests; + + assert.equal(requests.filter(req => req.url === '/v1/namespaces').length, 1); + + await Tokens.secret(secretId).submit(); + assert.equal(requests.filter(req => req.url === '/v1/namespaces').length, 2); + + await Tokens.clear(); + assert.equal(requests.filter(req => req.url === '/v1/namespaces').length, 3); + }); + function getHeader({ requestHeaders }, name) { // Headers are case-insensitive, but object property look up is not return ( diff --git a/ui/tests/pages/settings/tokens.js b/ui/tests/pages/settings/tokens.js index 925d739d8..998c7cd1f 100644 --- a/ui/tests/pages/settings/tokens.js +++ b/ui/tests/pages/settings/tokens.js @@ -13,6 +13,7 @@ export default create({ secret: fillable('[data-test-token-secret]'), submit: clickable('[data-test-token-submit]'), + clear: clickable('[data-test-token-clear]'), errorMessage: isVisible('[data-test-token-error]'), successMessage: isVisible('[data-test-token-success]'), From 069d67cbbfca016983368949c3333bae7dae71e9 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 10 Jul 2020 15:20:25 -0700 Subject: [PATCH 2/2] Changelog additions --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba4e110c8..3884aec86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ BUG FIXES: * ui: Fixed order of column headers in client allocations table. [[GH-8409](https://github.com/hashicorp/nomad/pull/8409)] + * ui: Fixed stale namespaces after changing acl tokens. [[GH-8413](https://github.com/hashicorp/nomad/issues/8413)] + * ui: Fixed missing namespace query param after changing acl tokens [[GH-8413](https://github.com/hashicorp/nomad/issues/8413)] * vault: Fixed a bug where vault identity policies not considered in permissions check [[GH-7732](https://github.com/hashicorp/nomad/issues/7732)] ## 0.12.0 (July 9, 2020)