@@ -2,11 +2,12 @@ package coderd_test
2
2
3
3
import (
4
4
"context"
5
- "fmt"
6
5
"net/http"
7
6
"strings"
8
7
"testing"
9
8
9
+ "golang.org/x/xerrors"
10
+
10
11
"github.com/go-chi/chi/v5"
11
12
"github.com/stretchr/testify/assert"
12
13
"github.com/stretchr/testify/require"
@@ -43,7 +44,7 @@ func TestAuthorizeAllEndpoints(t *testing.T) {
43
44
require .NoError (t , err , "fetch org" )
44
45
45
46
// Always fail auth from this point forward
46
- authorizer .AlwaysReturn = rbac .ForbiddenWithInternal (fmt . Errorf ("fake implementation" ), nil , nil )
47
+ authorizer .AlwaysReturn = rbac .ForbiddenWithInternal (xerrors . New ("fake implementation" ), nil , nil )
47
48
48
49
// skipRoutes allows skipping routes from being checked.
49
50
type routeCheck struct {
@@ -123,13 +124,16 @@ func TestAuthorizeAllEndpoints(t *testing.T) {
123
124
"GET:/api/v2/workspaces/{workspace}/builds" : {NoAuthorize : true },
124
125
"POST:/api/v2/workspaces/{workspace}/builds" : {NoAuthorize : true },
125
126
127
+ "POST:/api/v2/files" : {NoAuthorize : true },
128
+ "GET:/api/v2/files/{hash}" : {NoAuthorize : true },
129
+
126
130
// These endpoints have more assertions. This is good, add more endpoints to assert if you can!
127
131
"GET:/api/v2/organizations/{organization}" : {AssertObject : rbac .ResourceOrganization .InOrg (admin .OrganizationID )},
128
132
"GET:/api/v2/users/{user}/organizations" : {StatusCode : http .StatusOK , AssertObject : rbac .ResourceOrganization },
129
133
"GET:/api/v2/users/{user}/workspaces" : {StatusCode : http .StatusOK , AssertObject : rbac .ResourceWorkspace },
130
134
}
131
135
132
- c := srv .Config .Handler .(* chi.Mux )
136
+ c , _ := srv .Config .Handler .(* chi.Mux )
133
137
err = chi .Walk (c , func (method string , route string , handler http.Handler , middlewares ... func (http.Handler ) http.Handler ) error {
134
138
name := method + ":" + route
135
139
t .Run (name , func (t * testing.T ) {
@@ -188,7 +192,7 @@ type fakeAuthorizer struct {
188
192
AlwaysReturn error
189
193
}
190
194
191
- func (f * fakeAuthorizer ) AuthorizeByRoleName (ctx context.Context , subjectID string , roleNames []string , action rbac.Action , object rbac.Object ) error {
195
+ func (f * fakeAuthorizer ) AuthorizeByRoleName (_ context.Context , subjectID string , roleNames []string , action rbac.Action , object rbac.Object ) error {
192
196
f .Called = & authCall {
193
197
SubjectID : subjectID ,
194
198
Roles : roleNames ,
0 commit comments