Merge pull request #4628 from hashicorp/f-ui-use-ls-not-ss-for-tokens

UI: Use localStorage instead of sessionStorage to store ACL tokens
This commit is contained in:
Michael Lange 2018-08-28 15:27:09 -07:00 committed by GitHub
commit f641a22e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 12 deletions

View File

@ -9,13 +9,13 @@ export default Service.extend({
secret: computed({ secret: computed({
get() { get() {
return window.sessionStorage.nomadTokenSecret; return window.localStorage.nomadTokenSecret;
}, },
set(key, value) { set(key, value) {
if (value == null) { if (value == null) {
window.sessionStorage.removeItem('nomadTokenSecret'); window.localStorage.removeItem('nomadTokenSecret');
} else { } else {
window.sessionStorage.nomadTokenSecret = value; window.localStorage.nomadTokenSecret = value;
} }
return value; return value;

View File

@ -8,7 +8,7 @@
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<h3 class="title is-4">Token Storage</h3> <h3 class="title is-4">Token Storage</h3>
<p>To protect Secret IDs, tokens are stored client-side in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage">session storage</a>. Your ACL token is automatically cleared from storage upon closing your browser window. You can also manually clear your token instead.</p> <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>
<div class="column is-centered is-minimum"> <div class="column is-centered is-minimum">
<button class="button is-info" {{action "clearTokenProperties"}}>Clear Token</button> <button class="button is-info" {{action "clearTokenProperties"}}>Clear Token</button>

View File

@ -21,18 +21,18 @@ moduleForAcceptance('Acceptance | tokens', {
}, },
}); });
test('the token form sets the token in session storage', function(assert) { test('the token form sets the token in local storage', function(assert) {
const { secretId } = managementToken; const { secretId } = managementToken;
Tokens.visit(); Tokens.visit();
andThen(() => { andThen(() => {
assert.ok(window.sessionStorage.nomadTokenSecret == null, 'No token secret set'); assert.ok(window.localStorage.nomadTokenSecret == null, 'No token secret set');
Tokens.secret(secretId).submit(); Tokens.secret(secretId).submit();
andThen(() => { andThen(() => {
assert.equal(window.sessionStorage.nomadTokenSecret, secretId, 'Token secret was set'); assert.equal(window.localStorage.nomadTokenSecret, secretId, 'Token secret was set');
}); });
}); });
}); });
@ -91,7 +91,7 @@ test('an error message is shown when authenticating a token fails', function(ass
andThen(() => { andThen(() => {
assert.ok( assert.ok(
window.sessionStorage.nomadTokenSecret == null, window.localStorage.nomadTokenSecret == null,
'Token secret is discarded on failure' 'Token secret is discarded on failure'
); );
assert.ok(Tokens.errorMessage, 'Token error message is shown'); assert.ok(Tokens.errorMessage, 'Token error message is shown');

View File

@ -6,10 +6,7 @@ import destroyApp from '../helpers/destroy-app';
export default function(name, options = {}) { export default function(name, options = {}) {
module(name, { module(name, {
beforeEach() { beforeEach() {
// Clear session storage (a side effect of token storage) // Also clear local storage (a side effect of namespaces, regions, and tokens)
window.sessionStorage.clear();
// Also clear local storage (a side effect of namespaces and regions)
window.localStorage.clear(); window.localStorage.clear();
this.application = startApp(); this.application = startApp();