- Add new test files for auth, service, and handler modules - Improve test organization and coverage - Refactor code for better maintainability - Add captcha, settings, stats, and theme handler tests - Add auth module tests (CAS, OAuth, password, SSO, state) - Add service layer tests for auth, export, permissions, roles - All Go tests pass (exit code 0) - All frontend tests pass (325 tests in 59 files)
83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
package service_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/user-management-system/internal/service"
|
|
)
|
|
|
|
// =============================================================================
|
|
// Auth Password Tests
|
|
// =============================================================================
|
|
|
|
func TestGetPasswordStrength(t *testing.T) {
|
|
t.Run("Get password strength - strong", func(t *testing.T) {
|
|
info := service.GetPasswordStrength("StrongP@ss123")
|
|
if info.Score < 4 {
|
|
t.Errorf("Expected strength score >= 4, got %d", info.Score)
|
|
}
|
|
})
|
|
|
|
t.Run("Get password strength - weak", func(t *testing.T) {
|
|
info := service.GetPasswordStrength("123")
|
|
if info.Score > 2 {
|
|
t.Errorf("Expected low strength score for weak password, got %d", info.Score)
|
|
}
|
|
})
|
|
|
|
t.Run("Get password strength - empty", func(t *testing.T) {
|
|
info := service.GetPasswordStrength("")
|
|
if info.Length != 0 {
|
|
t.Errorf("Expected length 0 for empty password, got %d", info.Length)
|
|
}
|
|
})
|
|
|
|
t.Run("Get password strength with all character types", func(t *testing.T) {
|
|
info := service.GetPasswordStrength("Abcd1234!@#")
|
|
if !info.HasUpper {
|
|
t.Error("Expected HasUpper to be true")
|
|
}
|
|
if !info.HasLower {
|
|
t.Error("Expected HasLower to be true")
|
|
}
|
|
if !info.HasDigit {
|
|
t.Error("Expected HasDigit to be true")
|
|
}
|
|
if !info.HasSpecial {
|
|
t.Error("Expected HasSpecial to be true")
|
|
}
|
|
})
|
|
|
|
t.Run("Get password strength with only lowercase", func(t *testing.T) {
|
|
info := service.GetPasswordStrength("abcdefghij")
|
|
if !info.HasLower {
|
|
t.Error("Expected HasLower to be true")
|
|
}
|
|
if info.HasUpper {
|
|
t.Error("Expected HasUpper to be false")
|
|
}
|
|
if info.HasDigit {
|
|
t.Error("Expected HasDigit to be false")
|
|
}
|
|
if info.HasSpecial {
|
|
t.Error("Expected HasSpecial to be false")
|
|
}
|
|
})
|
|
|
|
t.Run("Get password strength with only digits", func(t *testing.T) {
|
|
info := service.GetPasswordStrength("1234567890")
|
|
if info.HasLower {
|
|
t.Error("Expected HasLower to be false")
|
|
}
|
|
if info.HasUpper {
|
|
t.Error("Expected HasUpper to be false")
|
|
}
|
|
if !info.HasDigit {
|
|
t.Error("Expected HasDigit to be true")
|
|
}
|
|
if info.HasSpecial {
|
|
t.Error("Expected HasSpecial to be false")
|
|
}
|
|
})
|
|
}
|