forked from vmware/govmomi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.bats
executable file
·121 lines (85 loc) · 2.06 KB
/
role.bats
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bats
load test_helper
@test "permissions" {
vcsim_env
perm=$(govc permissions.ls /DC0)
run govc permissions.ls -json
assert_success
run govc permissions.set -principal root -role Admin /DC0
assert_success
run govc permissions.ls /DC0
refute_line "$perm"
run govc permissions.remove -principal root /DC0
assert_success
run govc permissions.ls /DC0
assert_success "$perm"
}
@test "role.ls" {
vcsim_env
run govc role.ls
assert_success
run govc role.ls -json
assert_success
run govc role.ls Admin
assert_success
run govc role.ls -json Admin
assert_success
run govc role.ls enoent
assert_failure
}
@test "role.usage" {
vcsim_env
run govc role.usage
assert_success
run govc role.usage -json
assert_success
run govc role.usage Admin
assert_success
run govc role.usage -json Admin
assert_success
run govc role.usage enoent
assert_failure
}
@test "role.create" {
vcsim_env
id=$(new_id)
run govc role.create "$id"
assert_success
run govc role.ls "$id"
assert_success
priv=$(govc role.ls "$id" | wc -l)
[ "$priv" -eq 3 ]
vm_priv=($(govc role.ls Admin | grep VirtualMachine.))
# Test set
run govc role.update "$id" "${vm_priv[@]}"
assert_success
# invalid priv id
run govc role.update "$id" enoent
assert_failure
npriv=$(govc role.ls "$id" | wc -l)
[ "$npriv" -gt "$priv" ]
priv=$npriv
op_priv=($(govc role.ls "$id" | grep VirtualMachine.GuestOperations.))
# Test remove
run govc role.update -r "$id" "${op_priv[@]}"
assert_success
npriv=$(govc role.ls "$id" | wc -l)
[ "$npriv" -lt "$priv" ]
priv=$npriv
# Test add
run govc role.update -a "$id" "${op_priv[@]}"
assert_success
npriv=$(govc role.ls "$id" | wc -l)
[ "$npriv" -gt "$priv" ]
priv=$npriv
# Test rename
run govc role.update -name "${id}-N" "$id"
assert_success
id="${id}-N"
# Test we didn't drop any privileges during rename
[ "$priv" -eq "$(govc role.ls "$id" | wc -l)" ]
run govc role.remove "${id}"
assert_success
run govc role.ls "$id"
assert_failure
}