(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func TestDynamicParametersOwnerGroups(t *testing.T) { |
| 22 | t.Parallel() |
| 23 | |
| 24 | ownerClient, owner := coderdenttest.New(t, |
| 25 | &coderdenttest.Options{ |
| 26 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 27 | Features: license.Features{ |
| 28 | codersdk.FeatureTemplateRBAC: 1, |
| 29 | }, |
| 30 | }, |
| 31 | Options: &coderdtest.Options{IncludeProvisionerDaemon: true}, |
| 32 | }, |
| 33 | ) |
| 34 | templateAdmin, templateAdminUser := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.ScopedRoleOrgTemplateAdmin(owner.OrganizationID)) |
| 35 | _, noGroupUser := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID) |
| 36 | |
| 37 | // Create the group to be asserted |
| 38 | // Make the group name something after "Everyone" when sorted alphabetically. |
| 39 | // The test wants to check that `Everyone` is the default, which is the first alphabetical group in the test. |
| 40 | group := coderdtest.CreateGroup(t, ownerClient, owner.OrganizationID, "zebra", templateAdminUser) |
| 41 | |
| 42 | dynamicParametersTerraformSource, err := os.ReadFile("testdata/parameters/groups/main.tf") |
| 43 | require.NoError(t, err) |
| 44 | dynamicParametersTerraformPlan, err := os.ReadFile("testdata/parameters/groups/plan.json") |
| 45 | require.NoError(t, err) |
| 46 | |
| 47 | files := echo.WithExtraFiles(map[string][]byte{ |
| 48 | "main.tf": dynamicParametersTerraformSource, |
| 49 | }) |
| 50 | files.ProvisionPlan = []*proto.Response{{ |
| 51 | Type: &proto.Response_Plan{ |
| 52 | Plan: &proto.PlanComplete{ |
| 53 | Plan: dynamicParametersTerraformPlan, |
| 54 | }, |
| 55 | }, |
| 56 | }} |
| 57 | |
| 58 | version := coderdtest.CreateTemplateVersion(t, templateAdmin, owner.OrganizationID, files) |
| 59 | coderdtest.AwaitTemplateVersionJobCompleted(t, templateAdmin, version.ID) |
| 60 | _ = coderdtest.CreateTemplate(t, templateAdmin, owner.OrganizationID, version.ID) |
| 61 | |
| 62 | ctx := testutil.Context(t, testutil.WaitShort) |
| 63 | |
| 64 | // First check with a no group admin user, that they do not see the extra group |
| 65 | // Use the admin client, as the user might not have access to the template. |
| 66 | // Also checking that the admin can see the form for the other user. |
| 67 | noGroupStream, err := templateAdmin.TemplateVersionDynamicParameters(ctx, noGroupUser.ID.String(), version.ID) |
| 68 | require.NoError(t, err) |
| 69 | defer noGroupStream.Close(websocket.StatusGoingAway) |
| 70 | noGroupPreviews := noGroupStream.Chan() |
| 71 | noGroupPreview := testutil.RequireReceive(ctx, t, noGroupPreviews) |
| 72 | require.Equal(t, -1, noGroupPreview.ID) |
| 73 | require.Empty(t, noGroupPreview.Diagnostics) |
| 74 | require.Equal(t, "group", noGroupPreview.Parameters[0].Name) |
| 75 | require.Equal(t, database.EveryoneGroup, noGroupPreview.Parameters[0].Value.Value) |
| 76 | require.Equal(t, 1, len(noGroupPreview.Parameters[0].Options)) // Only 1 group |
| 77 | noGroupStream.Close(websocket.StatusGoingAway) |
| 78 |
nothing calls this directly
no test coverage detected