Procházet zdrojové kódy

Fix can't save password options

fixes https://github.com/lesspass/lesspass/issues/403
pull/410/head
Guillaume Vincent před 5 roky
rodič
revize
83ddc2e4ce
6 změnil soubory, kde provedl 97 přidání a 50 odebrání
  1. +1
    -1
      mobile/package.json
  2. +7
    -1
      mobile/src/password/PasswordGeneratorScreen.js
  3. +11
    -2
      mobile/src/password/passwordGenerator.js
  4. +43
    -8
      mobile/src/password/passwordGenerator.test.js
  5. +11
    -6
      mobile/src/password/validations.js
  6. +24
    -32
      mobile/src/password/validations.test.js

+ 1
- 1
mobile/package.json Zobrazit soubor

@@ -1,6 +1,6 @@
{
"name": "lesspass-mobile",
"version": "3.1.3",
"version": "3.1.4",
"description": "LessPass mobile application",
"license": "(MPL-2.0 OR GPL-3.0)",
"author": {


+ 7
- 1
mobile/src/password/PasswordGeneratorScreen.js Zobrazit soubor

@@ -102,7 +102,13 @@ export class PasswordGeneratorScreen extends Component {
id,
site,
login,
options: { length, counter, lowercase, uppercase, digits, symbols }
lowercase,
uppercase,
number: digits,
digits,
symbols,
length,
counter
};
};



+ 11
- 2
mobile/src/password/passwordGenerator.js Zobrazit soubor

@@ -2,8 +2,17 @@ import { NativeModules } from "react-native";
import renderLessPassPassword from "lesspass-render-password";

export function generatePassword(masterPassword, passwordProfile) {
const { site, login, options } = passwordProfile;
const { counter } = options;
const {
site,
login,
length,
counter,
lowercase,
uppercase,
digits,
symbols
} = passwordProfile;
const options = { length, counter, lowercase, uppercase, digits, symbols };
return NativeModules.LessPass.calcEntropy(
site,
login,


+ 43
- 8
mobile/src/password/passwordGenerator.test.js Zobrazit soubor

@@ -3,21 +3,56 @@ import { generatePassword } from "./passwordGenerator";

describe("generatePassword", () => {
beforeEach(() => {
NativeModules.LessPass = { calcEntropy: jest.fn().mockResolvedValue("03948309b088a53cdea276fa32a05988e9a6f2b57ef80aec664f668789b37711") };
NativeModules.LessPass = {
calcEntropy: jest
.fn()
.mockResolvedValue(
"03948309b088a53cdea276fa32a05988e9a6f2b57ef80aec664f668789b37711"
)
};
});

it("should return the initial state", () => {
const passwordProfile = {
site: "lesspass.com",
login: "contact@lesspass.com",
options: {
counter: 1,
length: 16,
lowercase: true,
uppercase: true,
digits: true,
symbols: true
counter: 1,
length: 16,
lowercase: true,
uppercase: true,
digits: true,
symbols: true
};
return generatePassword("password", passwordProfile).then(
generatedPassword => {
expect(generatedPassword).toBe("\\g-A1-.OHEwrXjT#");
}
);
});
});

describe("generatePassword should not care about the extra number field used for the API", () => {
beforeEach(() => {
NativeModules.LessPass = {
calcEntropy: jest
.fn()
.mockResolvedValue(
"03948309b088a53cdea276fa32a05988e9a6f2b57ef80aec664f668789b37711"
)
};
});

it("should return the initial state", () => {
const passwordProfile = {
site: "lesspass.com",
login: "contact@lesspass.com",
counter: 1,
length: 16,
lowercase: true,
uppercase: true,
digits: true,
number: true,
symbols: true
};
return generatePassword("password", passwordProfile).then(
generatedPassword => {


+ 11
- 6
mobile/src/password/validations.js Zobrazit soubor

@@ -16,18 +16,23 @@ export function isCounterValid(value) {
return isValid;
}

export function areOptionsValid(options) {
const { lowercase, uppercase, digits, symbols } = options;
export function areOptionsValid({ lowercase, uppercase, digits, symbols }) {
return lowercase || uppercase || digits || symbols;
}

export function isProfileValid(profile) {
const { site, options } = profile;
const { length, counter } = options;
export function isProfileValid({
site,
length,
counter,
lowercase,
uppercase,
digits,
symbols
}) {
return (
isLengthValid(length) &&
isCounterValid(counter) &&
areOptionsValid(options) &&
areOptionsValid({ lowercase, uppercase, digits, symbols }) &&
site !== ""
);
}

+ 24
- 32
mobile/src/password/validations.test.js Zobrazit soubor

@@ -89,14 +89,12 @@ describe("validation", () => {
isProfileValid({
site: "",
login: "",
options: {
length: 16,
counter: 1,
lowercase: true,
uppercase: true,
digits: true,
symbols: true
}
length: 16,
counter: 1,
lowercase: true,
uppercase: true,
digits: true,
symbols: true
})
).toBe(false);
});
@@ -105,14 +103,12 @@ describe("validation", () => {
isProfileValid({
site: "lesspass",
login: "",
options: {
length: 16,
counter: 1,
lowercase: true,
uppercase: true,
digits: true,
symbols: true
}
length: 16,
counter: 1,
lowercase: true,
uppercase: true,
digits: true,
symbols: true
})
).toBe(true);
});
@@ -121,14 +117,12 @@ describe("validation", () => {
isProfileValid({
site: "",
login: "",
options: {
length: 16,
counter: 1,
lowercase: false,
uppercase: false,
digits: false,
symbols: false
}
length: 16,
counter: 1,
lowercase: false,
uppercase: false,
digits: false,
symbols: false
})
).toBe(false);
});
@@ -137,14 +131,12 @@ describe("validation", () => {
isProfileValid({
site: "",
login: "",
options: {
length: 40,
counter: 1,
lowercase: true,
uppercase: true,
digits: true,
symbols: true
}
length: 40,
counter: 1,
lowercase: true,
uppercase: true,
digits: true,
symbols: true
})
).toBe(false);
});


Načítá se…
Zrušit
Uložit