Files
hakurei/internal/app/username_test.go
Ophestra dd0bb0a391 internal/app: check username validation
This stuff should be hardcoded in libc, but check it anyway.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2025-10-03 16:42:42 +09:00

27 lines
503 B
Go

package app
import (
"strings"
"testing"
)
func TestIsValidUsername(t *testing.T) {
t.Run("long", func(t *testing.T) {
if isValidUsername(strings.Repeat("a", sysconf(_SC_LOGIN_NAME_MAX))) {
t.Errorf("isValidUsername unexpected true")
}
})
t.Run("regexp", func(t *testing.T) {
if isValidUsername("0") {
t.Errorf("isValidUsername unexpected true")
}
})
t.Run("valid", func(t *testing.T) {
if !isValidUsername("alice") {
t.Errorf("isValidUsername unexpected false")
}
})
}