@@ -30,18 +30,68 @@ func (w fakeObject) RBACObject() Object {
30
30
}
31
31
}
32
32
33
+ // objectBomb is a wrapper around an Objecter that calls a function when
34
+ // RBACObject is called.
35
+ type objectBomb struct {
36
+ Objecter
37
+ bomb func ()
38
+ }
39
+
40
+ func (o * objectBomb ) RBACObject () Object {
41
+ o .bomb ()
42
+ return o .Objecter .RBACObject ()
43
+ }
44
+
33
45
func TestFilterError (t * testing.T ) {
34
46
t .Parallel ()
35
- auth := NewAuthorizer (prometheus .NewRegistry ())
36
- subject := Subject {
37
- ID : uuid .NewString (),
38
- Roles : RoleNames {},
39
- Groups : []string {},
40
- Scope : ScopeAll ,
41
- }
47
+ _ = objectBomb {}
42
48
43
- _ , err := Filter (context .Background (), auth , subject , ActionRead , []Object {ResourceUser , ResourceWorkspace })
44
- require .ErrorContains (t , err , "object types must be uniform" )
49
+ t .Run ("DifferentResourceTypes" , func (t * testing.T ) {
50
+ t .Parallel ()
51
+
52
+ auth := NewAuthorizer (prometheus .NewRegistry ())
53
+ subject := Subject {
54
+ ID : uuid .NewString (),
55
+ Roles : RoleNames {},
56
+ Groups : []string {},
57
+ Scope : ScopeAll ,
58
+ }
59
+
60
+ _ , err := Filter (context .Background (), auth , subject , ActionRead , []Object {ResourceUser , ResourceWorkspace })
61
+ require .ErrorContains (t , err , "object types must be uniform" )
62
+ })
63
+
64
+ t .Run ("CancelledContext" , func (t * testing.T ) {
65
+ t .Parallel ()
66
+ t .Skipf ("This test is racy as rego eval checks the ctx canceled in a go routine. " +
67
+ "It is a coin flip if the query finishes before the 'cancel' is checked. " +
68
+ "So sometimes the 'Authorize' call succeeds even if ctx is canceled." )
69
+
70
+ auth := NewAuthorizer (prometheus .NewRegistry ())
71
+ subject := Subject {
72
+ ID : uuid .NewString (),
73
+ Roles : RoleNames {
74
+ RoleOwner (),
75
+ },
76
+ Groups : []string {},
77
+ Scope : ScopeAll ,
78
+ }
79
+
80
+ ctx , cancel := context .WithCancel (context .Background ())
81
+ defer cancel ()
82
+ objects := []Objecter {
83
+ ResourceUser ,
84
+ ResourceUser ,
85
+ & objectBomb {
86
+ Objecter : ResourceUser ,
87
+ bomb : cancel ,
88
+ },
89
+ ResourceUser ,
90
+ }
91
+
92
+ _ , err := Filter (ctx , auth , subject , ActionRead , objects )
93
+ require .ErrorIs (t , err , context .Canceled )
94
+ })
45
95
}
46
96
47
97
// TestFilter ensures the filter acts the same as an individual authorize.
@@ -170,7 +220,7 @@ func TestFilter(t *testing.T) {
170
220
localObjects := make ([]fakeObject , len (objects ))
171
221
copy (localObjects , objects )
172
222
173
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
223
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitMedium )
174
224
defer cancel ()
175
225
auth := NewAuthorizer (prometheus .NewRegistry ())
176
226
0 commit comments