Просмотр исходного кода

fix selecting profile on two sub domains

Fixes https://github.com/lesspass/lesspass/issues/285
pull/342/head
Guillaume Vincent 7 лет назад
Родитель
Сommit
c64173e05b
2 измененных файлов: 44 добавлений и 5 удалений
  1. +10
    -4
      src/store/mutations.js
  2. +34
    -1
      test/unit/store.mutations.js

+ 10
- 4
src/store/mutations.js Просмотреть файл

@@ -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 Просмотреть файл

@@ -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: {


Загрузка…
Отмена
Сохранить