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

Function TestChatFilesAllowLinkedChatReads

coderd/database/dbauthz/dbauthz_test.go:158–209  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func TestChatFilesAllowLinkedChatReads(t *testing.T) {
159 t.Parallel()
160
161 ctx := dbauthz.As(context.Background(), rbac.Subject{
162 ID: uuid.NewString(),
163 Scope: rbac.ScopeAll,
164 })
165 authorizer := &coderdtest.FakeAuthorizer{
166 ConditionalReturn: func(_ context.Context, _ rbac.Subject, action policy.Action, object rbac.Object) error {
167 if action == policy.ActionRead && object.Type == rbac.ResourceChat.Type {
168 return xerrors.New("direct file auth denied")
169 }
170 return nil
171 },
172 }
173
174 t.Run("GetChatFileByID", func(t *testing.T) {
175 t.Parallel()
176
177 ctrl := gomock.NewController(t)
178 db := dbmock.NewMockStore(ctrl)
179 file := testutil.Fake(t, gofakeit.New(0), database.ChatFile{})
180
181 db.EXPECT().Wrappers().Return([]string{}).AnyTimes()
182 db.EXPECT().GetChatFileByID(gomock.Any(), file.ID).Return(file, nil)
183 db.EXPECT().GetAuthorizedChatsByChatFileID(gomock.Any(), file.ID, gomock.Any()).Return([]database.Chat{{ID: uuid.New()}}, nil)
184
185 q := dbauthz.New(db, authorizer, slogtest.Make(t, nil), coderdtest.AccessControlStorePointer())
186 got, err := q.GetChatFileByID(ctx, file.ID)
187
188 require.NoError(t, err)
189 require.Equal(t, file, got)
190 })
191
192 t.Run("GetChatFilesByIDs", func(t *testing.T) {
193 t.Parallel()
194
195 ctrl := gomock.NewController(t)
196 db := dbmock.NewMockStore(ctrl)
197 file := testutil.Fake(t, gofakeit.New(0), database.ChatFile{})
198
199 db.EXPECT().Wrappers().Return([]string{}).AnyTimes()
200 db.EXPECT().GetChatFilesByIDs(gomock.Any(), []uuid.UUID{file.ID}).Return([]database.ChatFile{file}, nil)
201 db.EXPECT().GetAuthorizedChatsByChatFileID(gomock.Any(), file.ID, gomock.Any()).Return([]database.Chat{{ID: uuid.New()}}, nil)
202
203 q := dbauthz.New(db, authorizer, slogtest.Make(t, nil), coderdtest.AccessControlStorePointer())
204 got, err := q.GetChatFilesByIDs(ctx, []uuid.UUID{file.ID})
205
206 require.NoError(t, err)
207 require.Equal(t, []database.ChatFile{file}, got)
208 })
209}
210
211//nolint:tparallel,paralleltest // It toggles the global chat ACL flag.
212func TestUpdateChatACLByIDGuards(t *testing.T) {

Callers

nothing calls this directly

Calls 13

EXPECTMethod · 0.95
AsFunction · 0.92
NewMockStoreFunction · 0.92
FakeFunction · 0.92
NewFunction · 0.92
NewMethod · 0.65
RunMethod · 0.65
WrappersMethod · 0.65
GetChatFileByIDMethod · 0.65
GetChatFilesByIDsMethod · 0.65

Tested by

no test coverage detected