MCPcopy Index your code
hub / github.com/coder/coder / TestNew

Function TestNew

coderd/database/dbauthz/dbauthz_test.go:129–156  ·  view source on GitHub ↗

TestNew should not double wrap a querier.

(t *testing.T)

Source from the content-addressed store, hash-verified

127
128// TestNew should not double wrap a querier.
129func TestNew(t *testing.T) {
130 t.Parallel()
131
132 var (
133 ctrl = gomock.NewController(t)
134 db = dbmock.NewMockStore(ctrl)
135 faker = gofakeit.New(0)
136 rec = &coderdtest.RecordingAuthorizer{
137 Wrapped: &coderdtest.FakeAuthorizer{},
138 }
139 subj = rbac.Subject{}
140 ctx = dbauthz.As(context.Background(), rbac.Subject{})
141 )
142 db.EXPECT().Wrappers().Times(1).Return([]string{}).Times(2) // two calls to New()
143 exp := testutil.Fake(t, faker, database.Workspace{})
144 db.EXPECT().GetWorkspaceByID(gomock.Any(), exp.ID).Times(1).Return(exp, nil)
145 // Double wrap should not cause an actual double wrap. So only 1 rbac call
146 // should be made.
147 az := dbauthz.New(db, rec, slog.Make(), coderdtest.AccessControlStorePointer())
148 az = dbauthz.New(az, rec, slog.Make(), coderdtest.AccessControlStorePointer())
149
150 w, err := az.GetWorkspaceByID(ctx, exp.ID)
151 require.NoError(t, err, "must not error")
152 require.Equal(t, exp, w, "must be equal")
153
154 rec.AssertActor(t, subj, rec.Pair(policy.ActionRead, exp))
155 require.NoError(t, rec.AllAsserted(), "should only be 1 rbac call")
156}
157
158func TestChatFilesAllowLinkedChatReads(t *testing.T) {
159 t.Parallel()

Callers

nothing calls this directly

Calls 13

NewMockStoreFunction · 0.92
AsFunction · 0.92
FakeFunction · 0.92
NewFunction · 0.92
AssertActorMethod · 0.80
PairMethod · 0.80
AllAssertedMethod · 0.80
NewMethod · 0.65
WrappersMethod · 0.65
GetWorkspaceByIDMethod · 0.65
EXPECTMethod · 0.45

Tested by

no test coverage detected