Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 3 additions & 8 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,12 @@ SHELLHUB_NETWORK=shellhub_network
# NOTICE: Format follows Go's cron package (https://pkg.go.dev/github.com/robfig/cron).
SHELLHUB_WORKER_SCHEDULE=@daily

# Internal setting for our cloud service.
SHELLHUB_CLOUD=false

# The URL for the session recording host.
SHELLHUB_RECORD_URL=api:8080

# Enable ShellHub Enterprise features.
# NOTICE: Requires a valid ShellHub Enterprise license. Enterprise-specific
# settings (admin credentials, SAML, web endpoints, object storage) live in
# .env.enterprise, loaded automatically by bin/docker-compose when this is true.
SHELLHUB_ENTERPRISE=false
# ShellHub edition: community (default), enterprise, or cloud.
# Enterprise-specific settings (admin credentials, SAML, web endpoints, object storage) live in .env.enterprise, loaded automatically by bin/docker-compose when edition is enterprise or cloud.
SHELLHUB_EDITION=community

# The URL for the Go modules proxy cache (development only).
# SHELLHUB_GOPROXY=http://localhost:3333
Expand Down
8 changes: 4 additions & 4 deletions .env.enterprise
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# PLEASE DO NOT EDIT THIS FILE; modify '.env.override' file instead
# This is in order to avoid conflict with upstream code when updating to a newer version
#
# This file is loaded by ./bin/docker-compose when SHELLHUB_ENTERPRISE=true.
# It declares enterprise-only environment variables consumed by the enterprise
# overlay (docker-compose.enterprise.yml).
# This file is loaded by ./bin/docker-compose when SHELLHUB_EDITION is
# enterprise or cloud. It declares enterprise-only environment variables
# consumed by the enterprise overlay (docker-compose.enterprise.yml).

SHELLHUB_ENTERPRISE=true
SHELLHUB_EDITION=enterprise

# The username for the ShellHub Enterprise Admin Console.
SHELLHUB_ENTERPRISE_ADMIN_USERNAME=
Expand Down
22 changes: 3 additions & 19 deletions api/routes/nsadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,14 @@ import (
"github.com/shellhub-io/shellhub/pkg/api/query"
"github.com/shellhub-io/shellhub/pkg/api/requests"
"github.com/shellhub-io/shellhub/pkg/envs"
envMocks "github.com/shellhub-io/shellhub/pkg/envs/mocks"
"github.com/shellhub-io/shellhub/pkg/envs/envstest"
"github.com/shellhub-io/shellhub/pkg/models"
"github.com/stretchr/testify/assert"
gomock "github.com/stretchr/testify/mock"
)

// withEnterpriseEnv points envs.DefaultBackend at a backend reporting the Enterprise edition so
// NewRouter registers the namespace-create route, which is dropped in Community. The previous
// backend is restored on cleanup.
func withEnterpriseEnv(t *testing.T) {
t.Helper()

prev := envs.DefaultBackend
t.Cleanup(func() { envs.DefaultBackend = prev })

envMock := envMocks.NewMockBackend(t)
envMock.On("Get", "SHELLHUB_ENTERPRISE").Return("true").Maybe()
envMock.On("Get", "SHELLHUB_CLOUD").Return("false").Maybe()
envMock.On("Get", gomock.Anything).Return("").Maybe()
envs.DefaultBackend = envMock
}

func TestCreateNamespace(t *testing.T) {
withEnterpriseEnv(t)
envstest.SetEdition(t, envs.Enterprise)

mock := mocks.NewMockService(t)

Expand Down Expand Up @@ -674,7 +658,7 @@ func TestGetNamespaceListBlocksAPIKey(t *testing.T) {
}

func TestCreateNamespaceBlocksAPIKey(t *testing.T) {
withEnterpriseEnv(t)
envstest.SetEdition(t, envs.Enterprise)

mock := mocks.NewMockService(t)

Expand Down
2 changes: 1 addition & 1 deletion api/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func NewRouter(service services.Service, opts ...Option) *echo.Echo {
// Community is single-namespace: the one namespace is created at setup and the store refuses
// any further one (once the instance is bound). Drop the create route so CE returns 404
// instead of a confusing error; Enterprise/Cloud keep it.
if !envs.IsCommunity() {
if envs.IsEnterpriseOrCloud() {
publicAPI.POST(CreateNamespaceURL, gateway.Handler(handler.CreateNamespace), routesmiddleware.BlockAPIKey)
}
publicAPI.GET(GetNamespaceURL, gateway.Handler(handler.GetNamespace), routesmiddleware.RequiresTenant(ParamNamespaceTenant))
Expand Down
10 changes: 2 additions & 8 deletions api/routes/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ import (
serviceMocks "github.com/shellhub-io/shellhub/api/services/mocks"
"github.com/shellhub-io/shellhub/pkg/api/requests"
"github.com/shellhub-io/shellhub/pkg/envs"
envMocks "github.com/shellhub-io/shellhub/pkg/envs/mocks"
"github.com/shellhub-io/shellhub/pkg/envs/envstest"
"github.com/shellhub-io/shellhub/pkg/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestSetup(t *testing.T) {
envMock := envMocks.NewMockBackend(t)
envs.DefaultBackend = envMock

envMock.On("Get", "SHELLHUB_CLOUD").Return("false")
envMock.On("Get", "SHELLHUB_ENTERPRISE").Return("false")
envstest.SetEdition(t, envs.Community)

servicesMock := serviceMocks.NewMockService(t)

Expand Down Expand Up @@ -107,6 +103,4 @@ func TestSetup(t *testing.T) {
assert.Equal(t, test.expected, result.StatusCode)
})
}

envMock.AssertExpectations(t)
}
Loading
Loading