Skip to content

chore: protect organization endpoints with license #14001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
linting
  • Loading branch information
Emyrk committed Jul 25, 2024
commit 66cd785aea8dc24fba8fcc2f010cd3c56676e92e
2 changes: 2 additions & 0 deletions enterprise/cli/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func TestEditOrganizationRoles(t *testing.T) {
}

func TestShowOrganizations(t *testing.T) {
t.Parallel()

t.Run("OnlyID", func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 1 addition & 0 deletions enterprise/coderd/organizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func TestOrganizationsByUser(t *testing.T) {

ctx := testutil.Context(t, testutil.WaitLong)

//nolint:gocritic // owner is required to make orgs
orgs, err := client.OrganizationsByUser(ctx, codersdk.Me)
require.NoError(t, err)
require.NotNil(t, orgs)
Expand Down
8 changes: 1 addition & 7 deletions enterprise/coderd/roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,7 @@ func TestListRoles(t *testing.T) {
member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
orgAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.ScopedRoleOrgAdmin(owner.OrganizationID))

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
t.Cleanup(cancel)

otherOrg, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
Name: "other",
})
require.NoError(t, err, "create org")
otherOrg := coderdenttest.CreateOrganization(t, client, coderdenttest.CreateOrganizationOptions{})

const notFound = "Resource not found"
testCases := []struct {
Expand Down
7 changes: 4 additions & 3 deletions enterprise/coderd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ func TestTemplates(t *testing.T) {
t.Parallel()
dv := coderdtest.DeploymentValues(t)
dv.Experiments = []string{string(codersdk.ExperimentMultiOrganization)}
client, owner := coderdenttest.New(t, &coderdenttest.Options{
ownerClient, owner := coderdenttest.New(t, &coderdenttest.Options{
Options: &coderdtest.Options{
DeploymentValues: dv,
},
Expand All @@ -790,8 +790,9 @@ func TestTemplates(t *testing.T) {
},
})

org2 := coderdenttest.CreateOrganization(t, client, coderdenttest.CreateOrganizationOptions{})
user, _ := coderdtest.CreateAnotherUser(t, client, org2.ID)
client, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.RoleTemplateAdmin())
org2 := coderdenttest.CreateOrganization(t, ownerClient, coderdenttest.CreateOrganizationOptions{})
user, _ := coderdtest.CreateAnotherUser(t, ownerClient, org2.ID)

// 2 templates in first organization
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
Expand Down
10 changes: 2 additions & 8 deletions enterprise/coderd/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,6 @@ func TestGrantSiteRoles(t *testing.T) {
require.Equal(t, statusCode, e.StatusCode(), "correct status code")
}

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
t.Cleanup(cancel)
var err error

dv := coderdtest.DeploymentValues(t)
dv.Experiments = []string{string(codersdk.ExperimentMultiOrganization)}
admin, first := coderdenttest.New(t, &coderdenttest.Options{
Expand All @@ -331,10 +327,8 @@ func TestGrantSiteRoles(t *testing.T) {

member, _ := coderdtest.CreateAnotherUser(t, admin, first.OrganizationID)
orgAdmin, _ := coderdtest.CreateAnotherUser(t, admin, first.OrganizationID, rbac.ScopedRoleOrgAdmin(first.OrganizationID))
randOrg, err := admin.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
Name: "random",
})
require.NoError(t, err)
randOrg := coderdenttest.CreateOrganization(t, admin, coderdenttest.CreateOrganizationOptions{})

_, randOrgUser := coderdtest.CreateAnotherUser(t, admin, randOrg.ID, rbac.ScopedRoleOrgAdmin(randOrg.ID))
userAdmin, _ := coderdtest.CreateAnotherUser(t, admin, first.OrganizationID, rbac.RoleUserAdmin())

Expand Down
1 change: 1 addition & 0 deletions enterprise/coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,7 @@ func TestAdminViewAllWorkspaces(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

//nolint:gocritic // intentionally using owner
_, err := client.Workspace(ctx, workspace.ID)
require.NoError(t, err)

Expand Down
4 changes: 4 additions & 0 deletions enterprise/members_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
)

func TestEnterpriseMembers(t *testing.T) {
t.Parallel()

t.Run("PostUser", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -77,6 +79,7 @@ func TestEnterpriseMembers(t *testing.T) {

ctx := testutil.Context(t, testutil.WaitMedium)
// Add user to org
//nolint:gocritic // Using owner to ensure it's not a 404 error
_, err := owner.PostOrganizationMember(ctx, org.ID, uuid.NewString())
require.Error(t, err)
var apiErr *codersdk.Error
Expand All @@ -87,6 +90,7 @@ func TestEnterpriseMembers(t *testing.T) {
// Calling it from a user without the org access.
t.Run("ListNotInOrg", func(t *testing.T) {
t.Parallel()

dv := coderdtest.DeploymentValues(t)
dv.Experiments = []string{string(codersdk.ExperimentMultiOrganization)}
owner, first := coderdenttest.New(t, &coderdenttest.Options{
Expand Down
4 changes: 3 additions & 1 deletion enterprise/wsproxy/wsproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ func TestWorkspaceProxyWorkspaceApps_BlockDirect(t *testing.T) {
deploymentValues.Dangerous.AllowPathAppSiteOwnerAccess = serpent.Bool(opts.DangerousAllowPathAppSiteOwnerAccess)
deploymentValues.Experiments = []string{
"*",
string(codersdk.ExperimentMultiOrganization),
}

proxyStatsCollectorFlushCh := make(chan chan<- struct{}, 1)
Expand Down Expand Up @@ -1028,7 +1029,8 @@ func TestWorkspaceProxyWorkspaceApps_BlockDirect(t *testing.T) {
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureWorkspaceProxy: 1,
codersdk.FeatureWorkspaceProxy: 1,
codersdk.FeatureMultipleOrganizations: 1,
},
},
})
Expand Down