-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
115 lines (86 loc) · 2.59 KB
/
Copy pathbenchmark_test.go
File metadata and controls
115 lines (86 loc) · 2.59 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package hyperacc
import (
"testing"
)
func BenchmarkCheckAccess_SingleRule(b *testing.B) {
ctxMock, identityMock := setupMocks()
identityMock.On("GetMSPID").Return("Org1MSP", nil)
rule := RequireMSPID("Org1MSP")
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = rule.Check(ctxMock)
}
ctxMock.AssertExpectations(b)
identityMock.AssertExpectations(b)
}
func BenchmarkCheckAccess_AndCombinator(b *testing.B) {
ctxMock, identityMock := setupMocks()
identityMock.On("GetAttributeValue", "role").Return("admin", true, nil)
identityMock.On("GetMSPID").Return("Org1MSP", nil)
rule := All(RequireRole("admin"), RequireMSPID("Org1MSP"))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = rule.Check(ctxMock)
}
ctxMock.AssertExpectations(b)
identityMock.AssertExpectations(b)
}
func BenchmarkCheckAccess_OrCombinator(b *testing.B) {
ctxMock, identityMock := setupMocks()
identityMock.On("GetMSPID").Return("Org2MSP", nil)
rule := Any(RequireMSPID("Org1MSP"), RequireMSPID("Org2MSP"))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = rule.Check(ctxMock)
}
ctxMock.AssertExpectations(b)
identityMock.AssertExpectations(b)
}
func BenchmarkCheckAccess_ComplexNested(b *testing.B) {
ctxMock, identityMock := setupMocks()
identityMock.On("GetAttributeValue", "role").Return("admin", true, nil)
identityMock.On("GetMSPID").Return("Org1MSP", nil)
rule := All(
Any(RequireRole("admin"), RequireRole("superuser")),
RequireMSPID("Org1MSP"),
)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = rule.Check(ctxMock)
}
ctxMock.AssertExpectations(b)
identityMock.AssertExpectations(b)
}
func BenchmarkCheckAccess_Controller(b *testing.B) {
ctxMock, identityMock := setupMocks()
identityMock.On("GetMSPID").Return("Org1MSP", nil)
controller := New(RequireMSPID("Org1MSP"))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = controller.Check(ctxMock)
}
ctxMock.AssertExpectations(b)
identityMock.AssertExpectations(b)
}
func BenchmarkCheckAccess_Helper(b *testing.B) {
ctxMock, identityMock := setupMocks()
identityMock.On("GetMSPID").Return("Org1MSP", nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = CheckAccess(ctxMock, RequireMSPID("Org1MSP"))
}
ctxMock.AssertExpectations(b)
identityMock.AssertExpectations(b)
}
func BenchmarkCheckAccess_PolicySet(b *testing.B) {
ctxMock, identityMock := setupMocks()
identityMock.On("GetAttributeValue", "role").Return("admin", true, nil)
ps := NewPolicySet()
ps.AddPolicy("CreateAsset", RequireRole("admin"))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = ps.Check(ctxMock, "CreateAsset")
}
ctxMock.AssertExpectations(b)
identityMock.AssertExpectations(b)
}