(t *testing.T)
| 6711 | } |
| 6712 | |
| 6713 | func TestGetWorkspaceAgentByID_FastPath(t *testing.T) { |
| 6714 | t.Parallel() |
| 6715 | |
| 6716 | agentID := uuid.New() |
| 6717 | ownerID := uuid.New() |
| 6718 | wsID := uuid.New() |
| 6719 | orgID := uuid.New() |
| 6720 | |
| 6721 | agent := database.WorkspaceAgent{ |
| 6722 | ID: agentID, |
| 6723 | Name: "test-agent", |
| 6724 | } |
| 6725 | |
| 6726 | workspace := database.Workspace{ |
| 6727 | ID: wsID, |
| 6728 | OwnerID: ownerID, |
| 6729 | OrganizationID: orgID, |
| 6730 | } |
| 6731 | |
| 6732 | wsIdentity := database.WorkspaceIdentity{ |
| 6733 | ID: wsID, |
| 6734 | OwnerID: ownerID, |
| 6735 | OrganizationID: orgID, |
| 6736 | } |
| 6737 | |
| 6738 | actor := rbac.Subject{ |
| 6739 | ID: ownerID.String(), |
| 6740 | Roles: rbac.RoleIdentifiers{rbac.RoleOwner()}, |
| 6741 | Groups: []string{orgID.String()}, |
| 6742 | Scope: rbac.ScopeAll, |
| 6743 | } |
| 6744 | |
| 6745 | authorizer := &coderdtest.RecordingAuthorizer{ |
| 6746 | Wrapped: (&coderdtest.FakeAuthorizer{}).AlwaysReturn(nil), |
| 6747 | } |
| 6748 | |
| 6749 | t.Run("WithWorkspaceRBAC", func(t *testing.T) { |
| 6750 | t.Parallel() |
| 6751 | |
| 6752 | ctx := dbauthz.As(context.Background(), actor) |
| 6753 | ctrl := gomock.NewController(t) |
| 6754 | mockDB := dbmock.NewMockStore(ctrl) |
| 6755 | |
| 6756 | rbacObj := wsIdentity.RBACObject() |
| 6757 | ctx, err := dbauthz.WithWorkspaceRBAC(ctx, rbacObj) |
| 6758 | require.NoError(t, err) |
| 6759 | |
| 6760 | mockDB.EXPECT().Wrappers().Return([]string{}) |
| 6761 | // GetWorkspaceByAgentID should NOT be called |
| 6762 | mockDB.EXPECT().GetWorkspaceAgentByID(gomock.Any(), agentID).Return(agent, nil) |
| 6763 | |
| 6764 | q := dbauthz.New(mockDB, authorizer, slogtest.Make(t, nil), coderdtest.AccessControlStorePointer()) |
| 6765 | |
| 6766 | result, err := q.GetWorkspaceAgentByID(ctx, agentID) |
| 6767 | require.NoError(t, err) |
| 6768 | require.Equal(t, agent, result) |
| 6769 | }) |
| 6770 |
nothing calls this directly
no test coverage detected