@@ -18,6 +18,36 @@ import (
18
18
"github.com/coder/coder/coderd/rbac"
19
19
)
20
20
21
+ func TestAsNoActor (t * testing.T ) {
22
+ t .Parallel ()
23
+
24
+ t .Run ("AsRemoveActor" , func (t * testing.T ) {
25
+ t .Parallel ()
26
+ _ , ok := dbauthz .ActorFromContext (context .Background ())
27
+ require .False (t , ok , "no actor should be present" )
28
+ })
29
+
30
+ t .Run ("AsActor" , func (t * testing.T ) {
31
+ t .Parallel ()
32
+ ctx := dbauthz .As (context .Background (), coderdtest .RandomRBACSubject ())
33
+ _ , ok := dbauthz .ActorFromContext (ctx )
34
+ require .True (t , ok , "actor present" )
35
+ })
36
+
37
+ t .Run ("DeleteActor" , func (t * testing.T ) {
38
+ t .Parallel ()
39
+ // First set an actor
40
+ ctx := dbauthz .As (context .Background (), coderdtest .RandomRBACSubject ())
41
+ _ , ok := dbauthz .ActorFromContext (ctx )
42
+ require .True (t , ok , "actor present" )
43
+
44
+ // Delete the actor
45
+ ctx = dbauthz .As (ctx , dbauthz .AsRemoveActor )
46
+ _ , ok = dbauthz .ActorFromContext (ctx )
47
+ require .False (t , ok , "actor should be deleted" )
48
+ })
49
+ }
50
+
21
51
func TestPing (t * testing.T ) {
22
52
t .Parallel ()
23
53
0 commit comments