-
Notifications
You must be signed in to change notification settings - Fork 3
/
authorization_information_test.go
65 lines (56 loc) · 1.47 KB
/
authorization_information_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
package gcs
import (
"testing"
)
func TestValidAuthorizationInformationObject(t *testing.T) {
authInfo := &AuthorizationInformation{
AuthorizationDecision: "allow",
Policy: &Policy{
Description: "test desc",
Name: "test_name",
UniqueID: "123",
Version: "1",
Group: &Group{Name: "test_name"},
},
}
authInfo, err := ValidateAuthorizationInformation(authInfo)
if err != nil {
t.Fatalf("Unable to create and validate Group: %v", err)
}
t.Logf("Name = %v", authInfo.AuthorizationDecision)
}
func TestErrorInvalidAuthorizationInformationObject(t *testing.T) {
authInfo := &AuthorizationInformation{
AuthorizationDecision: "allow",
Policy: &Policy{
Description: "test desc",
Name: "",
UniqueID: "123",
Version: "1",
Group: &Group{Name: "test_name"},
},
}
_, err := ValidateAuthorizationInformation(authInfo)
if err == nil {
t.Fatalf("Validator should have flagged this as an error: %v", err)
}
}
func BenchmarkAuthorizationInformationValidation(b *testing.B) {
b.ReportAllocs()
authInfo := &AuthorizationInformation{
AuthorizationDecision: "allow",
Policy: &Policy{
Description: "test desc",
Name: "test_name",
UniqueID: "123",
Version: "1",
Group: &Group{Name: "test_name"},
},
}
for n := 0; n < b.N; n++ {
_, err := ValidateAuthorizationInformation(authInfo)
if err != nil {
b.Fatalf("AuthorizationInformation object is invalid: %v", err)
}
}
}