chore: fixup quotas to only include groups you are a member of (#14271)

* chore: fixup quotas to only include groups you are a member of

Before all everyone groups were included in the allowance.

* chore: add unit test to execercise the bug
* add unit test to add rows into the everyone group
This commit is contained in:
Steven Masley
2024-08-15 13:27:50 -05:00
committed by GitHub
parent f619500833
commit 83ccdaa755
5 changed files with 159 additions and 21 deletions

View File

@ -233,6 +233,51 @@ func TestWorkspaceQuota(t *testing.T) {
verifyQuota(ctx, t, client, 4, 4)
require.Equal(t, codersdk.WorkspaceStatusRunning, build.Status)
})
// Ensures allowance from everyone groups only counts if you are an org member.
// This was a bug where the group "Everyone" was being counted for all users,
// regardless of membership.
t.Run("AllowanceEveryone", func(t *testing.T) {
t.Parallel()
dv := coderdtest.DeploymentValues(t)
dv.Experiments = []string{string(codersdk.ExperimentMultiOrganization)}
owner, first := coderdenttest.New(t, &coderdenttest.Options{
Options: &coderdtest.Options{
DeploymentValues: dv,
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureTemplateRBAC: 1,
codersdk.FeatureMultipleOrganizations: 1,
},
},
})
member, _ := coderdtest.CreateAnotherUser(t, owner, first.OrganizationID)
// Create a second organization
second := coderdenttest.CreateOrganization(t, owner, coderdenttest.CreateOrganizationOptions{})
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
// update everyone quotas
//nolint:gocritic // using owner for simplicity
_, err := owner.PatchGroup(ctx, first.OrganizationID, codersdk.PatchGroupRequest{
QuotaAllowance: ptr.Ref(30),
})
require.NoError(t, err)
_, err = owner.PatchGroup(ctx, second.ID, codersdk.PatchGroupRequest{
QuotaAllowance: ptr.Ref(15),
})
require.NoError(t, err)
verifyQuota(ctx, t, member, 0, 30)
// This currently reports the total site wide quotas. We might want to
// org scope this api call in the future.
verifyQuota(ctx, t, owner, 0, 45)
})
}
func planWithCost(cost int32) []*proto.Response {