fixes https://github.com/lesspass/lesspass/issues/403pull/410/head
@@ -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": { | |||
@@ -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 | |||
}; | |||
}; | |||
@@ -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, | |||
@@ -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 => { | |||
@@ -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 !== "" | |||
); | |||
} |
@@ -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); | |||
}); | |||