@@ -3,20 +3,12 @@ package authzquery_test
3
3
import (
4
4
"context"
5
5
"testing"
6
- "time"
7
6
8
- "github.com/moby/moby/pkg/namesgenerator"
9
-
10
- "github.com/coder/coder/coderd/rbac"
11
-
12
- "github.com/google/uuid"
13
7
"github.com/stretchr/testify/require"
14
8
15
- "github.com/coder/coder/coderd/database"
16
-
17
9
"github.com/coder/coder/coderd/authzquery"
18
- "github.com/coder/coder/coderd/coderdtest "
19
- "github.com/coder/coder/coderd/database/databasefake "
10
+ "github.com/coder/coder/coderd/database "
11
+ "github.com/coder/coder/coderd/rbac "
20
12
)
21
13
22
14
func TestWorkspaceFunctions (t * testing.T ) {
@@ -92,75 +84,7 @@ func TestWorkspaceFunctions(t *testing.T) {
92
84
tc := tc
93
85
t .Run (tc .Name , func (t * testing.T ) {
94
86
t .Parallel ()
95
-
96
87
testAuthorizeFunction (t , tc .Config )
97
88
})
98
89
}
99
-
100
- }
101
-
102
- func TestWorkspace (t * testing.T ) {
103
- // GetWorkspaceByID
104
- var (
105
- db = databasefake .New ()
106
- // TODO: Recorder should record all authz calls
107
- rec = & coderdtest.RecordingAuthorizer {}
108
- q = authzquery .NewAuthzQuerier (db , rec )
109
- actor = rbac.Subject {
110
- ID : uuid .New ().String (),
111
- Roles : rbac.RoleNames {rbac .RoleOwner ()},
112
- Groups : []string {},
113
- Scope : rbac .ScopeAll ,
114
- }
115
- ctx = authzquery .WithAuthorizeContext (context .Background (), actor )
116
- )
117
-
118
- workspace := insertRandomWorkspace (t , db )
119
-
120
- // Test recorder
121
- _ , err := q .GetWorkspaceByID (ctx , workspace .ID )
122
- require .NoError (t , err )
123
-
124
- _ , err = q .UpdateWorkspace (ctx , database.UpdateWorkspaceParams {
125
- ID : workspace .ID ,
126
- Name : "new-name" ,
127
- })
128
- require .NoError (t , err )
129
-
130
- rec .AssertActor (t , actor ,
131
- rec .Pair (rbac .ActionRead , workspace ),
132
- rec .Pair (rbac .ActionUpdate , workspace ),
133
- )
134
- require .NoError (t , rec .AllAsserted ())
135
- }
136
-
137
- func insertRandomWorkspace (t * testing.T , db database.Store , opts ... func (w * database.Workspace )) database.Workspace {
138
- workspace := & database.Workspace {
139
- ID : uuid .New (),
140
- CreatedAt : time .Now ().Add (time .Hour * - 1 ),
141
- UpdatedAt : time .Now (),
142
- OwnerID : uuid .New (),
143
- OrganizationID : uuid .New (),
144
- TemplateID : uuid .New (),
145
- Deleted : false ,
146
- Name : namesgenerator .GetRandomName (1 ),
147
- LastUsedAt : time .Now (),
148
- }
149
- for _ , opt := range opts {
150
- opt (workspace )
151
- }
152
-
153
- newWorkspace , err := db .InsertWorkspace (context .Background (), database.InsertWorkspaceParams {
154
- ID : workspace .ID ,
155
- CreatedAt : workspace .CreatedAt ,
156
- UpdatedAt : workspace .UpdatedAt ,
157
- OwnerID : workspace .OwnerID ,
158
- OrganizationID : workspace .OrganizationID ,
159
- TemplateID : workspace .TemplateID ,
160
- Name : workspace .Name ,
161
- AutostartSchedule : workspace .AutostartSchedule ,
162
- Ttl : workspace .Ttl ,
163
- })
164
- require .NoError (t , err , "insert workspace" )
165
- return newWorkspace
166
90
}
0 commit comments