TestAgentGitSSHKeyCustomRoles tests that the agent can fetch its git ssh key when the user has a custom role in a second workspace.
(t *testing.T)
| 20 | // TestAgentGitSSHKeyCustomRoles tests that the agent can fetch its git ssh key when |
| 21 | // the user has a custom role in a second workspace. |
| 22 | func TestAgentGitSSHKeyCustomRoles(t *testing.T) { |
| 23 | t.Parallel() |
| 24 | |
| 25 | owner, _ := coderdenttest.New(t, &coderdenttest.Options{ |
| 26 | Options: &coderdtest.Options{ |
| 27 | IncludeProvisionerDaemon: true, |
| 28 | }, |
| 29 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 30 | Features: license.Features{ |
| 31 | codersdk.FeatureCustomRoles: 1, |
| 32 | codersdk.FeatureMultipleOrganizations: 1, |
| 33 | codersdk.FeatureExternalProvisionerDaemons: 1, |
| 34 | }, |
| 35 | }, |
| 36 | }) |
| 37 | |
| 38 | // When custom roles exist in a second organization |
| 39 | org := coderdenttest.CreateOrganization(t, owner, coderdenttest.CreateOrganizationOptions{ |
| 40 | IncludeProvisionerDaemon: true, |
| 41 | }) |
| 42 | |
| 43 | ctx := testutil.Context(t, testutil.WaitShort) |
| 44 | //nolint:gocritic // required to make orgs |
| 45 | newRole, err := owner.CreateOrganizationRole(ctx, codersdk.Role{ |
| 46 | Name: "custom", |
| 47 | OrganizationID: org.ID.String(), |
| 48 | DisplayName: "", |
| 49 | SitePermissions: nil, |
| 50 | OrganizationPermissions: codersdk.CreatePermissions(map[codersdk.RBACResource][]codersdk.RBACAction{ |
| 51 | codersdk.ResourceTemplate: {codersdk.ActionRead, codersdk.ActionCreate, codersdk.ActionUpdate}, |
| 52 | }), |
| 53 | UserPermissions: nil, |
| 54 | }) |
| 55 | require.NoError(t, err) |
| 56 | |
| 57 | // Create the new user |
| 58 | client, _ := coderdtest.CreateAnotherUser(t, owner, org.ID, rbac.RoleIdentifier{Name: newRole.Name, OrganizationID: org.ID}) |
| 59 | |
| 60 | // Create the workspace + agent |
| 61 | authToken := uuid.NewString() |
| 62 | version := coderdtest.CreateTemplateVersion(t, client, org.ID, &echo.Responses{ |
| 63 | Parse: echo.ParseComplete, |
| 64 | ProvisionPlan: echo.PlanComplete, |
| 65 | ProvisionGraph: echo.ProvisionGraphWithAgent(authToken), |
| 66 | }) |
| 67 | project := coderdtest.CreateTemplate(t, client, org.ID, version.ID) |
| 68 | coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 69 | workspace := coderdtest.CreateWorkspace(t, client, project.ID) |
| 70 | coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) |
| 71 | |
| 72 | agentClient := agentsdk.New(client.URL, agentsdk.WithFixedToken(authToken)) |
| 73 | |
| 74 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 75 | defer cancel() |
| 76 | |
| 77 | agentKey, err := agentClient.GitSSHKey(ctx) |
| 78 | require.NoError(t, err) |
| 79 | require.NotEmpty(t, agentKey.PrivateKey) |
nothing calls this directly
no test coverage detected