thread-master/apps/backend/internal/module/member/usecase/password_test.go

41 lines
1008 B
Go
Raw Normal View History

2026-07-10 12:54:45 +00:00
package usecase
import (
"testing"
"apps/backend/internal/module/member/domain"
)
func TestValidatePasswordPolicy(t *testing.T) {
cases := []struct {
pw string
want error
}{
{"short", domain.ErrWeakPassword},
{"alllowercase1!", domain.ErrWeakPassword}, // no upper
{"ALLUPPERCASE1!", domain.ErrWeakPassword}, // no lower
{"NoDigitsHere!!", domain.ErrWeakPassword}, // no digit
{"NoSymbolHere12", domain.ErrWeakPassword}, // no symbol
{"Admin123!@#x", nil}, // 12 ok
{"GoodPassw0rd!", nil},
}
for _, c := range cases {
err := ValidatePasswordPolicy(c.pw)
if c.want == nil && err != nil {
t.Fatalf("%q: unexpected %v", c.pw, err)
}
if c.want != nil && err != c.want {
t.Fatalf("%q: got %v want %v", c.pw, err, c.want)
}
}
}
func TestGenerateTempPasswordMeetsPolicy(t *testing.T) {
for i := 0; i < 20; i++ {
pw := GenerateTempPassword()
if err := ValidatePasswordPolicy(pw); err != nil {
t.Fatalf("temp %q: %v", pw, err)
}
}
}