Increase limits
This commit is contained in:
parent
59fba524bc
commit
780a0ee687
|
@ -1,20 +1,20 @@
|
|||
const MIN_LENGTH = 8
|
||||
const MAX_LENGTH = 100
|
||||
export const PASSWORD_MIN_LENGTH = 8
|
||||
export const PASSWORD_MAX_LENGTH = 512
|
||||
|
||||
export function validatePassword(
|
||||
password: string
|
||||
): { valid: true } | { valid: false; error: string } {
|
||||
if (!password || password.length < MIN_LENGTH) {
|
||||
if (!password || password.length < PASSWORD_MIN_LENGTH) {
|
||||
return {
|
||||
valid: false,
|
||||
error: "Password invalid. Minimum eight characters.",
|
||||
}
|
||||
}
|
||||
|
||||
if (password.length > MAX_LENGTH) {
|
||||
if (password.length > PASSWORD_MAX_LENGTH) {
|
||||
return {
|
||||
valid: false,
|
||||
error: "Password invalid. Maximum hundred characters.",
|
||||
error: `Password invalid. Maximum ${PASSWORD_MAX_LENGTH} characters.`,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { generator } from "../../../tests"
|
||||
import { validatePassword } from "../auth"
|
||||
import { PASSWORD_MAX_LENGTH, validatePassword } from "../auth"
|
||||
|
||||
describe("auth", () => {
|
||||
describe("validatePassword", () => {
|
||||
|
@ -19,12 +19,24 @@ describe("auth", () => {
|
|||
})
|
||||
|
||||
it.each([
|
||||
generator.word({ length: 101 }),
|
||||
generator.paragraph().substring(0, 101),
|
||||
generator.word({ length: PASSWORD_MAX_LENGTH }),
|
||||
generator.paragraph().substring(0, PASSWORD_MAX_LENGTH),
|
||||
])(
|
||||
`can use passwords up to ${PASSWORD_MAX_LENGTH} characters in length`,
|
||||
password => {
|
||||
expect(validatePassword(password as string)).toEqual({
|
||||
valid: true,
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
it.each([
|
||||
generator.word({ length: PASSWORD_MAX_LENGTH + 1 }),
|
||||
generator.paragraph().substring(0, PASSWORD_MAX_LENGTH + 1),
|
||||
])("limit password length", password => {
|
||||
expect(validatePassword(password as string)).toEqual({
|
||||
valid: false,
|
||||
error: "Password invalid. Maximum hundred characters.",
|
||||
error: "Password invalid. Maximum 512 characters.",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue