From 21cc3a9d4fae8fd72424da924390686586e6fa89 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 2 Feb 2017 16:24:00 +0100 Subject: [PATCH] simplify password getter --- src/store/getters.js | 10 ++------- test/store.getters.js | 61 --------------------------------------------------- 2 files changed, 2 insertions(+), 69 deletions(-) diff --git a/src/store/getters.js b/src/store/getters.js index b9b3295..ba4acc6 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -1,19 +1,13 @@ export const passwords = state => state.passwords; +export const password = state => state.password; + export const isAuthenticated = state => state.authenticated; export const isGuest = state => !state.authenticated; export const passwordStatus = state => state.passwordStatus; -export const password = state => { - const tenMinutesAgo = new Date().getTime() - 10 * 60 * 1000; - if (state.lastUse < tenMinutesAgo) { - return Object.assign({}, state.defaultPassword); - } - return Object.assign({}, state.defaultPassword, state.password); -}; - export const version = state => { if(state.password === null){ return state.defaultPassword.version; diff --git a/test/store.getters.js b/test/store.getters.js index 8bcdb4d..76ec04e 100644 --- a/test/store.getters.js +++ b/test/store.getters.js @@ -1,67 +1,6 @@ import test from 'ava'; -import timekeeper from 'timekeeper'; - import * as getters from '../src/store/getters'; -test('password 5 minutes after last use', t => { - const now = 1485989236; - const time = new Date(now * 1000); - timekeeper.freeze(time); - const fiveMinutesBefore = (now - 5 * 60) * 1000; - const state = { - lastUse: fiveMinutesBefore, - password: { - login: 'test@example.org', - length: 30 - }, - defaultPassword: { - site: '', - login: '', - uppercase: true, - lowercase: true, - numbers: true, - symbols: true, - length: 16, - counter: 1, - version: 2 - } - }; - const password = getters.password(state); - t.is(password.login, 'test@example.org'); - t.is(password.length, 30); - timekeeper.reset(); -}); - -test('password more than 10 minutes after last use', t => { - const now = 1485989236; - const time = new Date(now * 1000); - timekeeper.freeze(time); - const fifteenMinutesBefore = (now - 15 * 60) * 1000; - const state = { - lastUse: fifteenMinutesBefore, - password: { - login: 'test@example.org', - length: 30 - }, - defaultPassword: { - site: '', - login: '', - uppercase: true, - lowercase: true, - numbers: true, - symbols: true, - length: 16, - counter: 1, - version: 2 - } - }; - const password = getters.password(state); - t.is('', password.login); - t.is('', password.site); - t.is(16, password.length); - timekeeper.reset(); -}); - test('version', t => { const state = { password: {version: 2},