Skip to content

Commit

Permalink
Reset the system and refetch namespaces with every token change
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Jul 10, 2020
1 parent e8a8d08 commit 4d7a51e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ui/app/controllers/settings/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();

Expand Down
1 change: 1 addition & 0 deletions ui/app/services/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,6 @@ export default class SystemService extends Service {

reset() {
this.set('activeNamespace', null);
this.notifyPropertyChange('namespaces');
}
}
2 changes: 1 addition & 1 deletion ui/app/templates/settings/tokens.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<p>Tokens are stored client-side in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage">local storage</a>. This will persist your token across sessions. You can manually clear your token here.</p>
</div>
<div class="column is-centered is-minimum">
<button class="button is-info" {{action "clearTokenProperties"}} type="button">Clear Token</button>
<button data-test-token-clear class="button is-info" {{action "clearTokenProperties"}} type="button">Clear Token</button>
</div>
</div>
</div>
Expand Down
17 changes: 17 additions & 0 deletions ui/tests/acceptance/token-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions ui/tests/pages/settings/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]'),
Expand Down

0 comments on commit 4d7a51e

Please sign in to comment.