TestNew should not double wrap a querier.
(t *testing.T)
| 127 | |
| 128 | // TestNew should not double wrap a querier. |
| 129 | func 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 | |
| 158 | func TestChatFilesAllowLinkedChatReads(t *testing.T) { |
| 159 | t.Parallel() |
nothing calls this directly
no test coverage detected