@@ -32,6 +32,7 @@ func TestDynamicParametersOwnerGroups(t *testing.T) {
3232 },
3333 )
3434 templateAdmin , templateAdminUser := coderdtest .CreateAnotherUser (t , ownerClient , owner .OrganizationID , rbac .RoleTemplateAdmin ())
35+ _ , noGroupUser := coderdtest .CreateAnotherUser (t , ownerClient , owner .OrganizationID )
3536
3637 // Create the group to be asserted
3738 group := coderdtest .CreateGroup (t , ownerClient , owner .OrganizationID , "bloob" , templateAdminUser )
@@ -57,7 +58,24 @@ func TestDynamicParametersOwnerGroups(t *testing.T) {
5758 _ = coderdtest .CreateTemplate (t , templateAdmin , owner .OrganizationID , version .ID )
5859
5960 ctx := testutil .Context (t , testutil .WaitShort )
60- stream , err := templateAdmin .TemplateVersionDynamicParameters (ctx , version .ID )
61+
62+ // First check with a no group admin user, that they do not see the extra group
63+ // Use the admin client, as the user might not have access to the template.
64+ // Also checking that the admin can see the form for the other user.
65+ noGroupStream , err := templateAdmin .TemplateVersionDynamicParameters (ctx , noGroupUser .ID .String (), version .ID )
66+ require .NoError (t , err )
67+ defer noGroupStream .Close (websocket .StatusGoingAway )
68+ noGroupPreviews := noGroupStream .Chan ()
69+ noGroupPreview := testutil .RequireReceive (ctx , t , noGroupPreviews )
70+ require .Equal (t , - 1 , noGroupPreview .ID )
71+ require .Empty (t , noGroupPreview .Diagnostics )
72+ require .Equal (t , "group" , noGroupPreview .Parameters [0 ].Name )
73+ require .Equal (t , database .EveryoneGroup , noGroupPreview .Parameters [0 ].Value .Value )
74+ require .Equal (t , 1 , len (noGroupPreview .Parameters [0 ].Options )) // Only 1 group
75+ noGroupStream .Close (websocket .StatusGoingAway )
76+
77+ // Now try with a user with more than 1 group
78+ stream , err := templateAdmin .TemplateVersionDynamicParameters (ctx , codersdk .Me , version .ID )
6179 require .NoError (t , err )
6280 defer stream .Close (websocket .StatusGoingAway )
6381
0 commit comments