-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirectory_service_test.go
More file actions
96 lines (80 loc) · 3.63 KB
/
Copy pathdirectory_service_test.go
File metadata and controls
96 lines (80 loc) · 3.63 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import "testing"
func attributeValue(commands [][]string, key string) (string, bool) {
for _, arguments := range commands {
if len(arguments) == 5 && arguments[3] == key {
return arguments[4], true
}
}
return "", false
}
func requireAttribute(t *testing.T, commands [][]string, key string, expected string) {
t.Helper()
value, isPresent := attributeValue(commands, key)
if !isPresent {
t.Fatalf("expected %s to be set, got commands %v", key, commands)
}
if value != expected {
t.Fatalf("expected %s to be %q, got %q", key, expected, value)
}
}
func TestCreateUserCommandsCarryTheAllocatedIdentity(testInstance *testing.T) {
commands := createUserCommands("bc_person_a1b2c3", "/workspace/private/people/a1b2c3", 100007, 100008)
if commands[0][2] != "/Users/bc_person_a1b2c3" {
testInstance.Fatalf("expected the record to be created first, got %v", commands[0])
}
requireAttribute(testInstance, commands, "UniqueID", "100007")
requireAttribute(testInstance, commands, "PrimaryGroupID", "100008")
requireAttribute(testInstance, commands, "NFSHomeDirectory", "/workspace/private/people/a1b2c3")
}
func TestCreateUserCommandsHideProjectedPeopleFromTheLoginWindow(testInstance *testing.T) {
commands := createUserCommands("bc_person_a1b2c3", "/home/a1b2c3", 100007, 100008)
requireAttribute(testInstance, commands, "IsHidden", "1")
}
func TestCreateUserCommandsUseAShellThatExistsOnMacOS(testInstance *testing.T) {
commands := createUserCommands("bc_person_a1b2c3", "/home/a1b2c3", 100007, 100008)
requireAttribute(testInstance, commands, "UserShell", "/usr/bin/false")
if macOSServiceAccountShell == "/usr/sbin/nologin" {
testInstance.Fatal("macOS ships no /usr/sbin/nologin; a user created with it cannot be used")
}
}
func TestCreateGroupCommandsCarryTheAllocatedIdentity(testInstance *testing.T) {
commands := createGroupCommands("bc_circle_member", 100004)
if commands[0][2] != "/Groups/bc_circle_member" {
testInstance.Fatalf("expected the record to be created first, got %v", commands[0])
}
requireAttribute(testInstance, commands, "PrimaryGroupID", "100004")
}
func TestParseDirectoryServiceListReadsNameAndIdentity(testInstance *testing.T) {
identities := parseDirectoryServiceList("_amavisd 83\nlee 501\nbc_person_a1b2c3 100007\n")
if len(identities) != 3 {
testInstance.Fatalf("expected three identities, got %+v", identities)
}
if identities[1].name != "lee" || identities[1].identityID != 501 {
testInstance.Fatalf("expected lee at 501, got %+v", identities[1])
}
if identities[2].name != "bc_person_a1b2c3" || identities[2].identityID != 100007 {
testInstance.Fatalf("expected the projected person to be readable back, got %+v", identities[2])
}
}
func TestParseDirectoryServiceListSkipsLinesWithoutAnIdentity(testInstance *testing.T) {
identities := parseDirectoryServiceList("\nname only\n_ftp 98\ntrailing\n")
if len(identities) != 1 || identities[0].identityID != 98 {
testInstance.Fatalf("expected only the record carrying a numeric identity, got %+v", identities)
}
}
func TestParseDirectoryServiceValueReadsTheThreeShapesDsclEmits(testInstance *testing.T) {
for _, shape := range []struct {
name string
output string
value string
}{
{"standard attribute", "UserShell: /bin/zsh\n", "/bin/zsh"},
{"native attribute carries a type prefix", "dsAttrTypeNative:IsHidden: 1\n", "1"},
{"a value containing a space moves to the next line", "RealName:\n dongha lee\n", "dongha lee"},
} {
if parsed := parseDirectoryServiceValue(shape.output); parsed != shape.value {
testInstance.Fatalf("%s: expected %q, got %q", shape.name, shape.value, parsed)
}
}
}