forked from baron/baron-sso
- Add `ValidateLoginID` to enforce ID collision and security rules (prevents phone number collision, email format usage, and reserved words). - Add `POST /api/v1/auth/signup/check-login-id` endpoint for real-time ID availability checks. - Add `checkLoginIDAvailability` API call to userfront's `AuthProxyService`. - Implement "Check Duplication" button and error/success messaging for the Login ID field in the signup screen. - Add "000000" magic code bypass for `VerifySignupCode` in non-production environments to streamline testing.
41 lines
1.6 KiB
Go
41 lines
1.6 KiB
Go
package domain
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateLoginID(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
loginID string
|
|
email string
|
|
phone string
|
|
wantErr bool
|
|
}{
|
|
{"Empty", "", "test@email.com", "01012345678", false},
|
|
{"Valid alphanumeric", "user123", "test@email.com", "01012345678", false},
|
|
{"Too short", "us", "test@email.com", "01012345678", true},
|
|
{"Too long", "thisisaverylongloginidthatiswayoverthirtycharacters", "test@email.com", "01012345678", true},
|
|
{"Email format", "user@domain.com", "test@email.com", "01012345678", true},
|
|
{"Exact email match", "Test@Email.Com", "test@email.com", "01012345678", true},
|
|
{"Phone number match", "010-1234-5678", "test@email.com", "01012345678", true},
|
|
{"Phone number match +82", "+821012345678", "test@email.com", "01012345678", true},
|
|
{"Phone number match digits", "01012345678", "test@email.com", "01012345678", true},
|
|
{"Phone format (11 digits)", "01098765432", "test@email.com", "01012345678", true},
|
|
{"Valid pure digits (employee ID)", "20230001", "test@email.com", "01012345678", false},
|
|
{"Valid pure digits long", "123456789", "test@email.com", "01012345678", false},
|
|
{"Valid pure digits 10 chars", "1234567890", "test@email.com", "01012345678", false},
|
|
{"Reserved word admin", "ADMIN", "test@email.com", "01012345678", true},
|
|
{"Reserved word root", "root", "test@email.com", "01012345678", true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := ValidateLoginID(tt.loginID, tt.email, tt.phone)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("ValidateLoginID() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|