-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity_test.go
53 lines (50 loc) · 1.09 KB
/
security_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"testing"
)
func TestIsValidUser(t *testing.T) {
tests := []struct {
name string
username string
expectedValue bool
}{
{
name: "Valid user (root)",
username: "root",
expectedValue: true,
},
{
name: "Valid user (nobody)",
username: "nobody",
expectedValue: true,
},
{
name: "Invalid user - starts with number",
username: "1kofabhhfsbf6krb",
expectedValue: false,
},
{
name: "Invalid user - contains uppercase letters",
username: "XD5hObIMZF2zKS7W",
expectedValue: false,
},
{
name: "Invalid user - too long",
username: "idfkjcacexia1dyji5iwcfweoliamzpn1",
expectedValue: false,
},
{
name: "Invalid user - contains invalid characters",
username: "moctcg!@",
expectedValue: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := isValidUser(test.username)
if result != test.expectedValue {
t.Errorf("Expected %v, got %v", test.expectedValue, result)
}
})
}
}