Browse Source

fix selecting profile on two sub domains

Fixes https://github.com/lesspass/lesspass/issues/285
pull/342/head
Guillaume Vincent 7 years ago
parent
commit
c64173e05b
2 changed files with 44 additions and 5 deletions
  1. +10
    -4
      src/store/mutations.js
  2. +34
    -1
      test/unit/store.mutations.js

+ 10
- 4
src/store/mutations.js View File

@@ -39,17 +39,23 @@ export default {
state.password.site = site;
},
[types.LOAD_PASSWORD_PROFILE](state, { site }) {
const siteDontMatch = site && !site.endsWith(state.password.site);
if (siteDontMatch) {
state.password = { ...state.defaultPassword };
}
let siteMatch = false;
const passwords = state.passwords || [];
const siteWithoutWWW = site.replace(/^www./g, "");
for (let i = 0; i < passwords.length; i++) {
const password = passwords[i];
if (site.endsWith(password.site)) {
state.password = { ...password };
siteMatch = true;
break;
} else if (password.site.endsWith(siteWithoutWWW)) {
state.password = { ...password };
siteMatch = true;
}
}
if (site && !siteMatch) {
state.password = { ...state.defaultPassword };
}
},
[types.SET_MESSAGE](state, { message }) {
state.message = message;


+ 34
- 1
test/unit/store.mutations.js View File

@@ -256,7 +256,10 @@ test("LOAD_PASSWORD_PROFILE no passwords", t => {
password: {
site: ""
},
passwords: []
passwords: [],
defaultPassword: {
site: ""
}
};
const LOAD_PASSWORD_PROFILE = mutations[types.LOAD_PASSWORD_PROFILE];
LOAD_PASSWORD_PROFILE(state, { site: "account.google.com" });
@@ -280,6 +283,36 @@ test("LOAD_PASSWORD_PROFILE multiple accounts matching criteria", t => {
t.is(state.password.site, "www.google.com");
});

test("LOAD_PASSWORD_PROFILE multiple accounts matching criteria order doesn't matter", t => {
const state = {
password: {
site: ""
},
passwords: [
{ id: "1", site: "www.example.org" },
{ id: "2", site: "account.google.com" },
{ id: "3", site: "www.google.com" }
]
};
const LOAD_PASSWORD_PROFILE = mutations[types.LOAD_PASSWORD_PROFILE];
LOAD_PASSWORD_PROFILE(state, { site: "www.google.com" });
t.is(state.password.id, "3");
t.is(state.password.site, "www.google.com");
});

test("LOAD_PASSWORD_PROFILE ends matching criteria nrt #285", t => {
const state = {
password: {
site: ""
},
passwords: [{ id: "1", site: "account.google.com" }]
};
const LOAD_PASSWORD_PROFILE = mutations[types.LOAD_PASSWORD_PROFILE];
LOAD_PASSWORD_PROFILE(state, { site: "www.google.com" });
t.is(state.password.id, "1");
t.is(state.password.site, "account.google.com");
});

test("LOAD_PASSWORD_PROFILE without www", t => {
const state = {
password: {


Loading…
Cancel
Save