1
- package authzquery_test
1
+ package dbauthz_test
2
2
3
3
import (
4
4
"context"
@@ -12,9 +12,9 @@ import (
12
12
13
13
"cdr.dev/slog"
14
14
"cdr.dev/slog/sloggers/slogtest"
15
- "github.com/coder/coder/coderd/authzquery"
16
15
"github.com/coder/coder/coderd/coderdtest"
17
16
"github.com/coder/coder/coderd/database"
17
+ "github.com/coder/coder/coderd/database/dbauthz"
18
18
"github.com/coder/coder/coderd/database/dbfake"
19
19
"github.com/coder/coder/coderd/database/dbgen"
20
20
"github.com/coder/coder/coderd/rbac"
@@ -28,31 +28,31 @@ func TestNotAuthorizedError(t *testing.T) {
28
28
29
29
testErr := xerrors .New ("custom error" )
30
30
31
- err := authzquery .LogNotAuthorizedError (context .Background (), slogtest .Make (t , nil ), testErr )
31
+ err := dbauthz .LogNotAuthorizedError (context .Background (), slogtest .Make (t , nil ), testErr )
32
32
require .ErrorIs (t , err , sql .ErrNoRows , "must be a sql.ErrNoRows" )
33
33
34
- var authErr authzquery .NotAuthorizedError
34
+ var authErr dbauthz .NotAuthorizedError
35
35
require .ErrorAs (t , err , & authErr , "must be a NotAuthorizedError" )
36
36
require .ErrorIs (t , authErr .Err , testErr , "internal error must match" )
37
37
})
38
38
39
39
t .Run ("MissingActor" , func (t * testing.T ) {
40
40
t .Parallel ()
41
- q := authzquery .New (dbfake .New (), & coderdtest.RecordingAuthorizer {
41
+ q := dbauthz .New (dbfake .New (), & coderdtest.RecordingAuthorizer {
42
42
Wrapped : & coderdtest.FakeAuthorizer {AlwaysReturn : nil },
43
43
}, slog .Make ())
44
44
// This should fail because the actor is missing.
45
45
_ , err := q .GetWorkspaceByID (context .Background (), uuid .New ())
46
- require .ErrorIs (t , err , authzquery .NoActorError , "must be a NoActorError" )
46
+ require .ErrorIs (t , err , dbauthz .NoActorError , "must be a NoActorError" )
47
47
})
48
48
}
49
49
50
- // TestAuthzQueryRecursive is a simple test to search for infinite recursion
50
+ // TestdbauthzRecursive is a simple test to search for infinite recursion
51
51
// bugs. It isn't perfect, and only catches a subset of the possible bugs
52
52
// as only the first db call will be made. But it is better than nothing.
53
- func TestAuthzQueryRecursive (t * testing.T ) {
53
+ func TestdbauthzRecursive (t * testing.T ) {
54
54
t .Parallel ()
55
- q := authzquery .New (dbfake .New (), & coderdtest.RecordingAuthorizer {
55
+ q := dbauthz .New (dbfake .New (), & coderdtest.RecordingAuthorizer {
56
56
Wrapped : & coderdtest.FakeAuthorizer {AlwaysReturn : nil },
57
57
}, slog .Make ())
58
58
actor := rbac.Subject {
@@ -63,7 +63,7 @@ func TestAuthzQueryRecursive(t *testing.T) {
63
63
}
64
64
for i := 0 ; i < reflect .TypeOf (q ).NumMethod (); i ++ {
65
65
var ins []reflect.Value
66
- ctx := authzquery .WithAuthorizeContext (context .Background (), actor )
66
+ ctx := dbauthz .WithAuthorizeContext (context .Background (), actor )
67
67
68
68
ins = append (ins , reflect .ValueOf (ctx ))
69
69
method := reflect .TypeOf (q ).Method (i )
@@ -84,7 +84,7 @@ func TestAuthzQueryRecursive(t *testing.T) {
84
84
func TestPing (t * testing.T ) {
85
85
t .Parallel ()
86
86
87
- q := authzquery .New (dbfake .New (), & coderdtest.RecordingAuthorizer {}, slog .Make ())
87
+ q := dbauthz .New (dbfake .New (), & coderdtest.RecordingAuthorizer {}, slog .Make ())
88
88
_ , err := q .Ping (context .Background ())
89
89
require .NoError (t , err , "must not error" )
90
90
}
@@ -94,7 +94,7 @@ func TestInTX(t *testing.T) {
94
94
t .Parallel ()
95
95
96
96
db := dbfake .New ()
97
- q := authzquery .New (db , & coderdtest.RecordingAuthorizer {
97
+ q := dbauthz .New (db , & coderdtest.RecordingAuthorizer {
98
98
Wrapped : & coderdtest.FakeAuthorizer {AlwaysReturn : xerrors .New ("custom error" )},
99
99
}, slog .Make ())
100
100
actor := rbac.Subject {
@@ -105,14 +105,14 @@ func TestInTX(t *testing.T) {
105
105
}
106
106
107
107
w := dbgen .Workspace (t , db , database.Workspace {})
108
- ctx := authzquery .WithAuthorizeContext (context .Background (), actor )
108
+ ctx := dbauthz .WithAuthorizeContext (context .Background (), actor )
109
109
err := q .InTx (func (tx database.Store ) error {
110
110
// The inner tx should use the parent's authz
111
111
_ , err := tx .GetWorkspaceByID (ctx , w .ID )
112
112
return err
113
113
}, nil )
114
114
require .Error (t , err , "must error" )
115
- require .ErrorAs (t , err , & authzquery .NotAuthorizedError {}, "must be an authorized error" )
115
+ require .ErrorAs (t , err , & dbauthz .NotAuthorizedError {}, "must be an authorized error" )
116
116
}
117
117
118
118
func must [T any ](value T , err error ) T {
0 commit comments