axe/internal/auth/password_test.go
2026-10-18 22:07:25 +03:00

35 lines
989 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package auth
import (
"errors"
"strings"
"testing"
)
func TestValidatePassword(t *testing.T) {
cases := []struct {
name string
pw string
want error
}{
{"нормальный", "Password123", nil},
{"ровно минимум (10)", "abcdefg123", nil},
{"с кириллицей", "пароль1234", nil},
{"слишком короткий", "Password1", ErrPasswordShort},
{"ровно 9", "short1234"[:9], ErrPasswordShort},
{"пустой", "", ErrPasswordShort},
{"только буквы", "verylongpassword", ErrPasswordWeak},
{"только цифры", "1234567890", ErrPasswordWeak},
{"без цифры в середине", "abcdefghij1", nil},
{"длиннее 72 байт", strings.Repeat("a1", 40), ErrPasswordLong},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
err := ValidatePassword(tc.pw)
if !errors.Is(err, tc.want) {
t.Errorf("ValidatePassword(%q) = %v, want %v", tc.pw, err, tc.want)
}
})
}
}