This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.go
136 lines (113 loc) · 2.5 KB
/
user_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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package goh4
import (
"fmt"
"testing"
)
func testUserSetup(h *H4) (*Scope, *Role, error) {
id := 424242
vrfName := "TestVRF42"
scopeName := "ScopeVRF42"
tenant := 0
roleName := "TestVRF42"
v := VRF{
ID: id,
Name: vrfName,
TenantID: tenant,
}
err := h.AddVRF(&v)
if err != nil {
return nil, nil, fmt.Errorf("Error in AddVRF: %s", err.Error())
}
f0 := Filter{
Type: "eq",
Field: "ip",
Value: "1.2.3.4",
}
s := Scope{
VRF: v.ID,
Name: scopeName,
Query: &QueryFilter{
Type: "and",
Filters: []interface{}{&f0},
},
Parent: v.Scope.ID,
}
err = h.AddScope(&s)
if err != nil {
return nil, nil, fmt.Errorf("Error in AddScope: %s", err.Error())
}
r := new(Role)
r.Scope = s.GetParent()
r.Name = roleName
// Add a role, make sure it succeeds before we do anything else
err = h.AddRole(r)
if err != nil {
return nil, nil, fmt.Errorf("Error in AddRole: %s", err.Error())
}
c1 := Capability{
Scope: &s,
Ability: AbilityRead,
}
err = r.AddCapability(c1)
if err != nil {
return nil, nil, fmt.Errorf("Error in AddCapability c1: %s", err.Error())
}
return &s, r, nil
}
func testUserTeardown(h *H4, scopeID string, vrfID int) error {
err := h.DeleteScope(scopeID)
if err != nil {
return fmt.Errorf("Error in DeleteScope: %s", err.Error())
}
err = h.DeleteVRF(vrfID)
if err != nil {
return fmt.Errorf("Error in DeleteVRF: %s", err.Error())
}
return nil
}
func TestGetUser(t *testing.T) {
t.Log("Starting TestGetUser Test")
testID := "5aa6ee0a497d4f46d9e7fe9b"
h := setupH4()
//TODO update this, UUID is not static
u, err := h.GetUser(testID)
if err != nil {
t.Errorf("Error in GetUser: %s", err.Error())
return
}
if u.ID != testID {
t.Errorf("Error ID is invalid, expecting %s got %s", testID, u.ID)
}
if len(u.Roles) != 2 {
t.Errorf("Error not enough roles, expecting %d got %d", 2, len(u.Roles))
}
}
func TestAddUser(t *testing.T) {
return
// t.Log("Starting TestAddUser Test")
// h := setupH4()
//
// s, r, err := testUserSetup(h)
// if err != nil {
// t.Errorf("Test setup failed - %s", err.Error())
// return
// }
//
// u := User{
// FirstName: "Bob",
// LastName: "Sponge",
// Email: "bobby2@sponge.com",
// Scope: s.GetParent(),
// Roles: []*Role{r},
// }
//
// err = h.AddUser(&u)
// if err != nil {
// t.Errorf("Error in AddUser: %s", err.Error())
// }
//
// err = testUserTeardown(h, s.ID, s.VRF)
// if err != nil {
// t.Errorf("Test teardown failed - %s", err.Error())
// }
}