From 83ddc2e4ce0d5396171a194ff754147996463aeb Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 21 Mar 2019 20:55:01 +0100 Subject: [PATCH] Fix can't save password options fixes https://github.com/lesspass/lesspass/issues/403 --- mobile/package.json | 2 +- mobile/src/password/PasswordGeneratorScreen.js | 8 +++- mobile/src/password/passwordGenerator.js | 13 +++++- mobile/src/password/passwordGenerator.test.js | 51 +++++++++++++++++++---- mobile/src/password/validations.js | 17 +++++--- mobile/src/password/validations.test.js | 56 +++++++++++--------------- 6 files changed, 97 insertions(+), 50 deletions(-) diff --git a/mobile/package.json b/mobile/package.json index 865f3e5..36b53bc 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -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": { diff --git a/mobile/src/password/PasswordGeneratorScreen.js b/mobile/src/password/PasswordGeneratorScreen.js index 69b38ca..1f90b39 100644 --- a/mobile/src/password/PasswordGeneratorScreen.js +++ b/mobile/src/password/PasswordGeneratorScreen.js @@ -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 }; }; diff --git a/mobile/src/password/passwordGenerator.js b/mobile/src/password/passwordGenerator.js index 230c46f..6795168 100644 --- a/mobile/src/password/passwordGenerator.js +++ b/mobile/src/password/passwordGenerator.js @@ -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, diff --git a/mobile/src/password/passwordGenerator.test.js b/mobile/src/password/passwordGenerator.test.js index 67495e4..1723030 100644 --- a/mobile/src/password/passwordGenerator.test.js +++ b/mobile/src/password/passwordGenerator.test.js @@ -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 => { diff --git a/mobile/src/password/validations.js b/mobile/src/password/validations.js index 8ef887a..0eeca68 100644 --- a/mobile/src/password/validations.js +++ b/mobile/src/password/validations.js @@ -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 !== "" ); } diff --git a/mobile/src/password/validations.test.js b/mobile/src/password/validations.test.js index 1ef5847..276dbcd 100644 --- a/mobile/src/password/validations.test.js +++ b/mobile/src/password/validations.test.js @@ -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); });