Skip to content

Commit fd002a7

Browse files
authored
settings/tokens: Delete plaintext tokens from memory after leaving API tokens settings page (#6363)
1 parent d9f5541 commit fd002a7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

app/routes/settings/tokens.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,16 @@ export default class TokenSettingsRoute extends AuthenticatedRoute {
1111
let apiTokens = await this.store.findAll('api-token');
1212
return TrackedArray.from(apiTokens.slice());
1313
}
14+
15+
/**
16+
* Ensure that all plaintext tokens are deleted from memory after leaving
17+
* the API tokens settings page.
18+
*/
19+
resetController(controller) {
20+
for (let token of controller.model) {
21+
if (token.token) {
22+
token.token = undefined;
23+
}
24+
}
25+
}
1426
}

tests/acceptance/api-token-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,25 @@ module('Acceptance | api-tokens', function (hooks) {
133133
assert.dom('[data-test-token]').hasText(token.token);
134134
});
135135

136+
test('API tokens are only visible in plaintext until the page is left', async function (assert) {
137+
prepare(this);
138+
139+
await visit('/settings/tokens');
140+
await click('[data-test-new-token-button]');
141+
await fillIn('[data-test-focused-input]', 'the new token');
142+
await click('[data-test-save-token-button]');
143+
144+
let token = this.server.schema.apiTokens.findBy({ name: 'the new token' });
145+
assert.dom('[data-test-token]').hasText(token.token);
146+
147+
// leave the API tokens page
148+
await visit('/settings');
149+
150+
// and visit it again
151+
await visit('/settings/tokens');
152+
assert.dom('[data-test-token]').doesNotExist();
153+
});
154+
136155
test('navigating away while creating a token does not keep it in the list', async function (assert) {
137156
prepare(this);
138157

0 commit comments

Comments
 (0)