48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
|
|
package services
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"veza-backend-api/internal/validators"
|
||
|
|
|
||
|
|
"go.uber.org/zap"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestPasswordServiceExpirationDisabled(t *testing.T) {
|
||
|
|
logger := zap.NewNop()
|
||
|
|
ps := &PasswordService{
|
||
|
|
logger: logger,
|
||
|
|
expirationDays: 0, // disabled
|
||
|
|
}
|
||
|
|
|
||
|
|
err := ps.CheckPasswordExpiration(nil, [16]byte{})
|
||
|
|
if err != nil {
|
||
|
|
t.Errorf("expected no error when expiration disabled, got %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestPasswordServiceExpirationNegative(t *testing.T) {
|
||
|
|
logger := zap.NewNop()
|
||
|
|
ps := &PasswordService{
|
||
|
|
logger: logger,
|
||
|
|
expirationDays: -1, // disabled
|
||
|
|
}
|
||
|
|
|
||
|
|
err := ps.CheckPasswordExpiration(nil, [16]byte{})
|
||
|
|
if err != nil {
|
||
|
|
t.Errorf("expected no error with negative expiration days, got %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestNewPasswordServiceWithPolicy(t *testing.T) {
|
||
|
|
logger := zap.NewNop()
|
||
|
|
policy := validators.DefaultPasswordPolicy()
|
||
|
|
ps := NewPasswordServiceWithPolicy(nil, logger, policy, 90)
|
||
|
|
if ps.expirationDays != 90 {
|
||
|
|
t.Errorf("expected expirationDays=90, got %d", ps.expirationDays)
|
||
|
|
}
|
||
|
|
if ps.passwordValidator == nil {
|
||
|
|
t.Error("expected non-nil passwordValidator")
|
||
|
|
}
|
||
|
|
}
|