internal/app: check username validation
All checks were successful
Test / Create distribution (push) Successful in 38s
Test / Sandbox (push) Successful in 2m13s
Test / Hakurei (push) Successful in 3m6s
Test / Hpkg (push) Successful in 3m59s
Test / Sandbox (race detector) (push) Successful in 4m36s
Test / Hakurei (race detector) (push) Successful in 5m18s
Test / Flake checks (push) Successful in 1m25s
All checks were successful
Test / Create distribution (push) Successful in 38s
Test / Sandbox (push) Successful in 2m13s
Test / Hakurei (push) Successful in 3m6s
Test / Hpkg (push) Successful in 3m59s
Test / Sandbox (race detector) (push) Successful in 4m36s
Test / Hakurei (race detector) (push) Successful in 5m18s
Test / Flake checks (push) Successful in 1m25s
This stuff should be hardcoded in libc, but check it anyway. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
d16da6da8c
commit
dd0bb0a391
15
internal/app/sysconf_test.go
Normal file
15
internal/app/sysconf_test.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
const (
|
||||||
|
_POSIX_LOGIN_NAME_MAX = 9
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSysconf(t *testing.T) {
|
||||||
|
t.Run("LOGIN_NAME_MAX", func(t *testing.T) {
|
||||||
|
if got := sysconf(_SC_LOGIN_NAME_MAX); got < _POSIX_LOGIN_NAME_MAX {
|
||||||
|
t.Errorf("sysconf(_SC_LOGIN_NAME_MAX): %d < _POSIX_LOGIN_NAME_MAX", got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
26
internal/app/username_test.go
Normal file
26
internal/app/username_test.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user