(t *testing.T)
| 3388 | } |
| 3389 | |
| 3390 | func TestGetAuthorizedConnectionLogsOffset(t *testing.T) { |
| 3391 | t.Parallel() |
| 3392 | |
| 3393 | var allLogs []database.ConnectionLog |
| 3394 | db, _ := dbtestutil.NewDB(t) |
| 3395 | authz := rbac.NewAuthorizer(prometheus.NewRegistry()) |
| 3396 | authDb := dbauthz.New(db, authz, slogtest.Make(t, &slogtest.Options{}), coderdtest.AccessControlStorePointer()) |
| 3397 | |
| 3398 | orgA := dbfake.Organization(t, db).Do() |
| 3399 | orgB := dbfake.Organization(t, db).Do() |
| 3400 | |
| 3401 | user := dbgen.User(t, db, database.User{}) |
| 3402 | |
| 3403 | tpl := dbgen.Template(t, db, database.Template{ |
| 3404 | OrganizationID: orgA.Org.ID, |
| 3405 | CreatedBy: user.ID, |
| 3406 | }) |
| 3407 | |
| 3408 | wsID := uuid.New() |
| 3409 | createTemplateVersion(t, db, tpl, tvArgs{ |
| 3410 | WorkspaceTransition: database.WorkspaceTransitionStart, |
| 3411 | Status: database.ProvisionerJobStatusSucceeded, |
| 3412 | CreateWorkspace: true, |
| 3413 | WorkspaceID: wsID, |
| 3414 | }) |
| 3415 | |
| 3416 | // This map is a simple way to insert a given number of organizations |
| 3417 | // and audit logs for each organization. |
| 3418 | // map[orgID][]ConnectionLogID |
| 3419 | orgConnectionLogs := map[uuid.UUID][]uuid.UUID{ |
| 3420 | orgA.Org.ID: {uuid.New(), uuid.New()}, |
| 3421 | orgB.Org.ID: {uuid.New(), uuid.New()}, |
| 3422 | } |
| 3423 | orgIDs := make([]uuid.UUID, 0, len(orgConnectionLogs)) |
| 3424 | for orgID := range orgConnectionLogs { |
| 3425 | orgIDs = append(orgIDs, orgID) |
| 3426 | } |
| 3427 | for orgID, ids := range orgConnectionLogs { |
| 3428 | for _, id := range ids { |
| 3429 | allLogs = append(allLogs, dbgen.ConnectionLog(t, authDb, database.UpsertConnectionLogParams{ |
| 3430 | WorkspaceID: wsID, |
| 3431 | WorkspaceOwnerID: user.ID, |
| 3432 | ID: id, |
| 3433 | OrganizationID: orgID, |
| 3434 | })) |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | // Now fetch all the logs |
| 3439 | auditorRole, err := rbac.RoleByName(rbac.RoleAuditor()) |
| 3440 | require.NoError(t, err) |
| 3441 | |
| 3442 | memberRole, err := rbac.RoleByName(rbac.RoleMember()) |
| 3443 | require.NoError(t, err) |
| 3444 | |
| 3445 | orgAuditorRoles := func(t *testing.T, orgID uuid.UUID) rbac.Role { |
| 3446 | t.Helper() |
| 3447 |
nothing calls this directly
no test coverage detected