Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: moved harness test to seperate
=b8899758c1e0
diff --git a/tests/Makefile b/tests/Makefileindex bc55ecdf82..e8f6dd481e 100644--- a/tests/Makefile+++ b/tests/Makefile@@ -25,7 +25,7 @@ lint:# because a hand-written list silently stops covering a package the day someone adds# one -- which is exactly what happened when fixture/, provider/ and stub/ appeared.test-unit:- go test $$(go list ./... | grep -v '/suites/') -count=1+ go test $$(go list ./... | grep -vE '/(suites|harnesstest)/') -count=1test: lint test-unit@@ -43,7 +43,7 @@ test-docker:## The recipe's exit status is still `go test`'s, so a failure stays a failure.test-suites: up- @trap '$(MAKE) --no-print-directory down' EXIT; go test ./suites/... -count=1+ @trap '$(MAKE) --no-print-directory down' EXIT; go test ./suites/... ./harnesstest/... -count=1up:go run ./cmd/inf updiff --git a/tests/harnesstest/isolated/main_test.go b/tests/harnesstest/isolated/main_test.gonew file mode 100644index 0000000000..3379a7f81d--- /dev/null+++ b/tests/harnesstest/isolated/main_test.go@@ -0,0 +1,11 @@+// Package harnesstest proves the parts of the harness that need a package of their+// own: the Isolated profile and everything that follows from it.+package harnesstest_test++import (+ "testing"++ "github.com/Infisical/infisical/tests/harness"+)++func TestMain(m *testing.M) { harness.Main(m, harness.Isolated) }diff --git a/tests/harnesstest/isolated/principals_test.go b/tests/harnesstest/isolated/principals_test.gonew file mode 100644index 0000000000..ad62815097--- /dev/null+++ b/tests/harnesstest/isolated/principals_test.go@@ -0,0 +1,49 @@+package harnesstest_test++import (+ "net/http"+ "testing"++ "github.com/Infisical/infisical/tests/clients/api"+ "github.com/Infisical/infisical/tests/harness"+ "github.com/Infisical/infisical/tests/internal/spec"+)++func TestAdminPrincipals_AreSeparate(t *testing.T) {+ spec.Why(t, `The harness hands out two administrators and the whole Shared profile+ rests on them being different things. If a tenant administrator could write+ instance configuration, one test could disable signup or rotate the root key+ under every other package in the run, and the damage would surface somewhere+ else entirely.++ This has been wrong once: while the tenant administrator was the bootstrap root+ wearing an organization claim, the second case below failed.++ Isolated because the first case really does write instance configuration.`)++ h := harness.From(t)++ t.Run("ok/the instance admin can write instance configuration", func(t *testing.T) {+ res, err := h.InstanceAdmin(t).API.UpdateAdminConfigWithResponse(t.Context(),+ api.UpdateAdminConfigJSONRequestBody{AllowSignUp: new(true)})+ if err != nil {+ t.Fatalf("writing instance config: %v", err)+ }+ if res.StatusCode() != http.StatusOK {+ t.Fatalf("the instance admin was refused instance config: %d: %s", res.StatusCode(), res.Body)+ }+ })++ t.Run("forbidden/a tenant admin cannot", func(t *testing.T) {+ tn := h.NewTenant(t)++ res, err := tn.Admin.API.UpdateAdminConfigWithResponse(t.Context(),+ api.UpdateAdminConfigJSONRequestBody{AllowSignUp: new(true)})+ if err != nil {+ t.Fatalf("writing instance config as a tenant admin: %v", err)+ }+ if res.StatusCode() == http.StatusOK {+ t.Fatal("a tenant administrator wrote instance configuration")+ }+ })+}diff --git a/tests/harnesstest/isolated/profile_test.go b/tests/harnesstest/isolated/profile_test.gonew file mode 100644index 0000000000..1d78f95ce5--- /dev/null+++ b/tests/harnesstest/isolated/profile_test.go@@ -0,0 +1,25 @@+package harnesstest_test++import (+ "testing"++ "github.com/Infisical/infisical/tests/fixture/appconnection"+ "github.com/Infisical/infisical/tests/harness"+ "github.com/Infisical/infisical/tests/internal/spec"+ "github.com/Infisical/infisical/tests/provider"+)++func TestIsolated_OwnsItsStubbing(t *testing.T) {+ spec.Why(t, `The only thing unique to this profile that the harness itself owns. An+ Isolated package runs its own WireMock, and a host alias belongs to the network+ rather than the container. Before the profile took a network of its own, both+ WireMocks claimed api.github.com on one network and Docker DNS round-robined+ between them, so a stub registered here was missed by requests landing on the+ shared one. This is the regression test for that.`)++ conn := appconnection.New(t, harness.From(t).NewTenant(t), provider.GitHub)++ if n := conn.Stub(t).Received(t, "GET", "/user"); n != 1 {+ t.Fatalf("the credential check reached this package's stub %d times, want 1", n)+ }+}diff --git a/tests/harnesstest/shared/licensing_test.go b/tests/harnesstest/shared/licensing_test.gonew file mode 100644index 0000000000..792acb017b--- /dev/null+++ b/tests/harnesstest/shared/licensing_test.go@@ -0,0 +1,37 @@+package harnesstest_test++import (+ "testing"++ "github.com/Infisical/infisical/tests/harness"+ "github.com/Infisical/infisical/tests/harness/license"+ "github.com/Infisical/infisical/tests/internal/spec"+)++func TestLicense_PlanOptionReachesTheInstance(t *testing.T) {+ t.Parallel()+ spec.Why(t, `Whether WithPlan registers a stub the application actually resolves.+ Verify reads the plan back with refreshCache=true, so a stub that was never+ reached, or was keyed on the wrong feature name, fails here rather than later as+ an unexplained 403 in a test about something else.`)++ tn := harness.From(t).NewTenant(t, harness.WithPlan(license.Enterprise().Without(license.RBAC)))+ tn.Verify(t, license.Enterprise().Without(license.RBAC))+}++func TestLicense_ResolvesPerTenant(t *testing.T) {+ t.Parallel()+ spec.Why(t, `This one is a product behaviour the harness depends on rather than+ something the harness owns: getPlan resolves per organization only in Cloud+ instance type, and every other type short-circuits to one instance-wide feature+ set. It lives here because if it ever changes, per-tenant licensing stops being+ possible and the design has to change with it -- which is a harness problem, not+ a failing product test.`)++ h := harness.From(t)+ narrowed := h.NewTenant(t, harness.WithPlan(license.Enterprise().Without(license.RBAC)))+ untouched := h.NewTenant(t)++ untouched.Verify(t, license.Enterprise())+ narrowed.Verify(t, license.Enterprise().Without(license.RBAC))+}diff --git a/tests/harnesstest/shared/main_test.go b/tests/harnesstest/shared/main_test.gonew file mode 100644index 0000000000..78ef1e8c22--- /dev/null+++ b/tests/harnesstest/shared/main_test.go@@ -0,0 +1,16 @@+// Package harnesstest proves the harness, not Infisical.+//+// Separate from suites/ because a failure here means a different thing. A red suite+// says the product is broken; a red harness test says our tooling is. They also have+// different lifetimes: when the API is rewritten in Go the suites are the contract+// and must pass unchanged, while these are about machinery that the rewrite does not+// touch.+package harnesstest_test++import (+ "testing"++ "github.com/Infisical/infisical/tests/harness"+)++func TestMain(m *testing.M) { harness.Main(m, harness.Shared) }diff --git a/tests/harnesstest/shared/principal_test.go b/tests/harnesstest/shared/principal_test.gonew file mode 100644index 0000000000..eaaac7365c--- /dev/null+++ b/tests/harnesstest/shared/principal_test.go@@ -0,0 +1,78 @@+package harnesstest_test++import (+ "net/http"+ "testing"++ "github.com/Infisical/infisical/tests/clients/api"+ "github.com/Infisical/infisical/tests/harness"+ "github.com/Infisical/infisical/tests/internal/spec"+)++func TestIdentity_HonoursItsOrgRole(t *testing.T) {+ t.Parallel()+ spec.Why(t, `Not a claim about Infisical's RBAC, which has its own tests: this is+ whether the fixture's option is applied at all. An ignored OrgRole would make+ every identity an admin, and every authorization test written on top of one would+ pass without meaning anything. That has happened once already, with ProjectRole.++ Project creation rather than a read, because reading the plan only proves+ membership and no-access still has that.`)++ tn := harness.From(t).NewTenant(t)+ id := tn.NewIdentity(t, harness.OrgRole("no-access"))++ res, err := id.API.CreateProjectWithResponse(t.Context(), api.CreateProjectJSONRequestBody{+ ProjectName: "should-not-exist",+ })+ if err != nil {+ t.Fatalf("creating a project as a no-access identity: %v", err)+ }+ if res.StatusCode() == http.StatusOK {+ t.Fatal("an identity created with OrgRole(no-access) could create a project")+ }+}++func TestUser_IsInvitedThroughMail(t *testing.T) {+ t.Parallel()+ h := harness.From(t)++ t.Run("ok/an invited user becomes a member", func(t *testing.T) {+ t.Parallel()+ spec.Why(t, `Also the only proof that the harness can read a mailbox at all. The+ invite link comes back in the response only when SMTP is unconfigured, and the+ harness configures it on purpose, so the link has to be pulled out of Mailpit.+ Every email-driven flow rests on this working.`)++ tn := h.NewTenant(t)+ alice := tn.NewUser(t, harness.WithName("alice"))++ if alice.Email != tn.Address("alice") {+ t.Errorf("user got mailbox %q, want %q", alice.Email, tn.Address("alice"))+ }+ res, err := alice.API.GetOrganizationPlanWithResponse(t.Context(), tn.OrgID.String(), nil)+ if err != nil {+ t.Fatalf("reading the plan as the invited user: %v", err)+ }+ if res.StatusCode() != http.StatusOK {+ t.Fatalf("an invited user cannot reach the organization they joined: %d", res.StatusCode())+ }+ })++ t.Run("cross-tenant/two tenants can invite the same local part", func(t *testing.T) {+ t.Parallel()+ spec.Why(t, `Mail isolation is by address, not by server: one Mailpit serves the+ whole run. If the domains did not differ, two parallel tests inviting "alice"+ would read each other's invitation and both would pass or fail at random.`)++ a, b := h.NewTenant(t), h.NewTenant(t)+ ua, ub := a.NewUser(t, harness.WithName("alice")), b.NewUser(t, harness.WithName("alice"))++ if ua.Email == ub.Email {+ t.Fatalf("both tenants issued %s", ua.Email)+ }+ if ua.Token == ub.Token {+ t.Fatal("two separately invited users share a session token")+ }+ })+}diff --git a/tests/suites/integrations/app_connection_test.go b/tests/harnesstest/shared/stubbing_test.gosimilarity index 65%rename from tests/suites/integrations/app_connection_test.gorename to tests/harnesstest/shared/stubbing_test.goindex a11fc64c73..8e7eab926d 100644--- a/tests/suites/integrations/app_connection_test.go+++ b/tests/harnesstest/shared/stubbing_test.go@@ -1,4 +1,4 @@-package integrations_test+package harnesstest_testimport ("net/http"@@ -10,19 +10,18 @@ import ("github.com/Infisical/infisical/tests/provider")-func TestAppConnection_Create(t *testing.T) {+func TestOutbound_IsIntercepted(t *testing.T) {t.Parallel()h := harness.From(t)- t.Run("ok/an outbound call is intercepted", func(t *testing.T) {+ t.Run("ok/an outbound call reaches the stub", func(t *testing.T) {t.Parallel()spec.Why(t, `The one test the whole stubbing design rests on. The connection iscreated with no host, so GitHub's client resolves api.github.com, and the onlyway that request can reach WireMock is the forward proxy and the injected CA.- If it stops passing, no integration test below it is testing anything real.`)+ If it stops passing, no integration test anywhere is testing anything real.`)- tn := h.NewTenant(t)- conn := appconnection.New(t, tn, provider.GitHub)+ conn := appconnection.New(t, h.NewTenant(t), provider.GitHub)if n := conn.Stub(t).Received(t, "GET", "/user"); n != 1 {t.Fatalf("the credential check reached the stub %d times, want 1", n)@@ -47,17 +46,17 @@ func TestAppConnection_Create(t *testing.T) {}})- t.Run("invalid/a rejected credential fails the create", func(t *testing.T) {+ t.Run("invalid/what the stub answers is load bearing", func(t *testing.T) {t.Parallel()- spec.Why(t, `Proves the stub is load bearing rather than incidental: if creating a- connection succeeded whatever the provider answered, the interception above- would not be evidence of anything.`)+ spec.Why(t, `The interception test above proves a request arrived. On its own that+ is not enough: if the application ignored the response, every stubbed value a+ test asserts on would be decoration. Changing the answer has to change the+ outcome.`)- tn := h.NewTenant(t)-- _, err := appconnection.Try(t, tn, provider.GitHub, appconnection.RejectCredentials(http.StatusUnauthorized))+ _, err := appconnection.Try(t, h.NewTenant(t), provider.GitHub,+ appconnection.RejectCredentials(http.StatusUnauthorized))if err == nil {- t.Fatal("a connection was created against a provider that rejected the credential")+ t.Fatal("the connection was created even though the stub rejected the credential")}})}diff --git a/tests/harnesstest/shared/tenancy_test.go b/tests/harnesstest/shared/tenancy_test.gonew file mode 100644index 0000000000..0f80dcc1b2--- /dev/null+++ b/tests/harnesstest/shared/tenancy_test.go@@ -0,0 +1,25 @@+package harnesstest_test++import (+ "testing"++ "github.com/Infisical/infisical/tests/harness"+ "github.com/Infisical/infisical/tests/internal/spec"+)++func TestTenant_IsIsolated(t *testing.T) {+ t.Parallel()+ spec.Why(t, `Slugs matter as much as ids here. A tenant's mail domain is derived from+ its slug, so two tenants sharing one would read each other's invitations, and the+ address-based isolation every email flow relies on would silently stop working.`)++ h := harness.From(t)+ a, b := h.NewTenant(t), h.NewTenant(t)++ if a.OrgID == b.OrgID {+ t.Fatal("two tenants share an organization, so nothing is isolated")+ }+ if a.OrgSlug == b.OrgSlug {+ t.Errorf("two tenants share a slug (%s), so their mail domains collide", a.OrgSlug)+ }+}diff --git a/tests/suites/instance/admin_test.go b/tests/suites/instance/admin_test.godeleted file mode 100644index 8fceaf0f5d..0000000000--- a/tests/suites/instance/admin_test.go+++ /dev/null@@ -1,65 +0,0 @@-package instance_test--import (- "net/http"- "testing"-- "github.com/Infisical/infisical/tests/clients/api"- "github.com/Infisical/infisical/tests/fixture/appconnection"- "github.com/Infisical/infisical/tests/harness"- "github.com/Infisical/infisical/tests/internal/spec"- "github.com/Infisical/infisical/tests/provider"-)--func TestInstanceAdmin_Config(t *testing.T) {- h := harness.From(t)-- t.Run("ok/the instance admin can write instance configuration", func(t *testing.T) {- spec.Why(t, `The reason this package is Isolated at all. Instance configuration is- global, so proving it is writable has to happen somewhere that owns its own- instance -- doing it from a Shared package would change the instance every- other package is using.`)-- res, err := h.InstanceAdmin(t).API.UpdateAdminConfigWithResponse(t.Context(),- api.UpdateAdminConfigJSONRequestBody{AllowSignUp: new(true)})- if err != nil {- t.Fatalf("writing instance config: %v", err)- }- if res.StatusCode() != http.StatusOK {- t.Fatalf("the instance admin was refused instance config: %d: %s", res.StatusCode(), res.Body)- }- })-- t.Run("forbidden/an organization admin is not an instance admin", func(t *testing.T) {- spec.Why(t, `The Shared profile hands every test an organization admin, and this is- what makes that safe: the server refuses it instance-wide routes. If this ever- passed, a Shared test could reconfigure the instance under every other package- in the run.`)-- tn := h.NewTenant(t)-- res, err := tn.Admin.API.UpdateAdminConfigWithResponse(t.Context(),- api.UpdateAdminConfigJSONRequestBody{AllowSignUp: new(true)})- if err != nil {- t.Fatalf("writing instance config as an org admin: %v", err)- }- if res.StatusCode() == http.StatusOK {- t.Fatal("an organization admin wrote instance configuration")- }- })-}--func TestOutboundStubbing_UnderIsolation(t *testing.T) {- spec.Why(t, `An Isolated package runs its own WireMock, and a host alias belongs to- the network rather than the container. Before this had its own network, both- WireMocks claimed api.github.com on one network and Docker DNS round-robined- between them, so a stub registered here was missed by requests landing on the- shared one. This is the regression test for that.`)-- tn := harness.From(t).NewTenant(t)- conn := appconnection.New(t, tn, provider.GitHub)-- if n := conn.Stub(t).Received(t, "GET", "/user"); n != 1 {- t.Fatalf("the credential check reached this package's stub %d times, want 1", n)- }-}diff --git a/tests/suites/instance/main_test.go b/tests/suites/instance/main_test.godeleted file mode 100644index b8ab14f123..0000000000--- a/tests/suites/instance/main_test.go+++ /dev/null@@ -1,13 +0,0 @@-package instance_test--import (- "testing"-- "github.com/Infisical/infisical/tests/harness"-)--// Isolated: this package writes instance-wide configuration, so it takes its own-// Postgres, Redis and Infisical rather than sharing the run's. Tests here do not-// call t.Parallel(); across packages they still run concurrently, because each test-// binary gets its own containers.-func TestMain(m *testing.M) { harness.Main(m, harness.Isolated) }diff --git a/tests/suites/integrations/main_test.go b/tests/suites/organization/main_test.gosimilarity index 84%rename from tests/suites/integrations/main_test.gorename to tests/suites/organization/main_test.goindex 495132787b..26def664f6 100644--- a/tests/suites/integrations/main_test.go+++ b/tests/suites/organization/main_test.go@@ -1,4 +1,4 @@-package integrations_test+package organization_testimport ("testing"diff --git a/tests/suites/organization/organization_test.go b/tests/suites/organization/organization_test.gonew file mode 100644index 0000000000..29773a8742--- /dev/null+++ b/tests/suites/organization/organization_test.go@@ -0,0 +1,45 @@+package organization_test++import (+ "net/http"+ "testing"++ "github.com/Infisical/infisical/tests/harness"+ "github.com/Infisical/infisical/tests/internal/spec"+ "github.com/google/uuid"+)++func TestOrganization_Create(t *testing.T) {+ t.Parallel()+ h := harness.From(t)++ t.Run("cross-tenant/another tenant's organization is not readable", func(t *testing.T) {+ t.Parallel()+ spec.Why(t, `The claim the whole Shared profile rests on. If one tenant can reach+ another's organization, running tests in parallel against one instance is unsound+ and every result is suspect.`)++ mine, theirs := h.NewTenant(t), h.NewTenant(t)++ res, err := mine.Admin.API.GetOrganizationPlanWithResponse(t.Context(), theirs.OrgID.String(), nil)+ if err != nil {+ t.Fatalf("reading another organization: %v", err)+ }+ if res.StatusCode() == http.StatusOK {+ t.Fatalf("tenant %s read tenant %s's plan", mine.OrgSlug, theirs.OrgSlug)+ }+ })++ t.Run("notfound/an organization that never existed", func(t *testing.T) {+ t.Parallel()+ tn := h.NewTenant(t)++ res, err := tn.Admin.API.GetOrganizationPlanWithResponse(t.Context(), uuid.NewString(), nil)+ if err != nil {+ t.Fatalf("reading an absent organization: %v", err)+ }+ if res.StatusCode() == http.StatusOK {+ t.Fatal("an organization that does not exist returned a plan")+ }+ })+}diff --git a/tests/suites/platform/organization_test.go b/tests/suites/platform/organization_test.godeleted file mode 100644index 0ee254e1af..0000000000--- a/tests/suites/platform/organization_test.go+++ /dev/null@@ -1,128 +0,0 @@-package platform_test--import (- "net/http"- "testing"-- "github.com/Infisical/infisical/tests/clients/api"- "github.com/Infisical/infisical/tests/harness"- "github.com/Infisical/infisical/tests/harness/license"- "github.com/Infisical/infisical/tests/internal/spec"- "github.com/google/uuid"-)--func TestOrganization_Create(t *testing.T) {- t.Parallel()- h := harness.From(t)-- t.Run("ok/a tenant gets its own organization", func(t *testing.T) {- t.Parallel()- a, b := h.NewTenant(t), h.NewTenant(t)-- if a.OrgID == b.OrgID {- t.Fatal("two tenants share an organization, so nothing is isolated")- }- if a.OrgSlug == b.OrgSlug {- t.Errorf("two tenants share a slug (%s), so their mail domains collide", a.OrgSlug)- }- })-- t.Run("ok/the admin is scoped to its own organization", func(t *testing.T) {- t.Parallel()- spec.Why(t, `A login token carries no organization; selectOrganization binds it. An- unbound token reaches no org-scoped route, so this is what every other test- depends on without saying so.`)-- tn := h.NewTenant(t)- res, err := tn.Admin.API.GetOrganizationPlanWithResponse(t.Context(), tn.OrgID.String(), nil)- if err != nil {- t.Fatalf("reading the plan: %v", err)- }- if res.StatusCode() != http.StatusOK {- t.Fatalf("admin cannot read its own organization: %d", res.StatusCode())- }- })-- t.Run("cross-tenant/another tenant's organization is not readable", func(t *testing.T) {- t.Parallel()- spec.Why(t, `The claim the whole Shared profile rests on. If one tenant can reach- another's organization, running tests in parallel against one instance is unsound- and every result is suspect.`)-- mine, theirs := h.NewTenant(t), h.NewTenant(t)-- res, err := mine.Admin.API.GetOrganizationPlanWithResponse(t.Context(), theirs.OrgID.String(), nil)- if err != nil {- t.Fatalf("reading another organization: %v", err)- }- if res.StatusCode() == http.StatusOK {- t.Fatalf("tenant %s read tenant %s's plan", mine.OrgSlug, theirs.OrgSlug)- }- })-- t.Run("notfound/an organization that never existed", func(t *testing.T) {- t.Parallel()- tn := h.NewTenant(t)-- res, err := tn.Admin.API.GetOrganizationPlanWithResponse(t.Context(), uuid.NewString(), nil)- if err != nil {- t.Fatalf("reading an absent organization: %v", err)- }- if res.StatusCode() == http.StatusOK {- t.Fatal("an organization that does not exist returned a plan")- }- })-}--func TestOrganization_Entitlements(t *testing.T) {- t.Parallel()- h := harness.From(t)-- t.Run("ok/a tenant is entitled by default", func(t *testing.T) {- t.Parallel()- spec.Why(t, `Entitlements resolve per organization, which needs Cloud instance type:- every other type short-circuits to one instance-wide feature set. If this fails,- the license stub is not reaching the application at all.`)-- h.NewTenant(t).Verify(t, license.Enterprise())- })-- t.Run("ok/a tenant can be given a narrower plan", func(t *testing.T) {- t.Parallel()- tn := h.NewTenant(t, harness.WithPlan(license.Enterprise().Without(license.RBAC)))- tn.Verify(t, license.Enterprise().Without(license.RBAC))- })-- t.Run("ok/entitlements are per tenant, not per instance", func(t *testing.T) {- t.Parallel()- spec.Why(t, `This is what lets a downgrade be asserted under a live organization- without a dedicated stack. If plans leaked across tenants, every licensing test- would need its own instance.`)-- narrowed := h.NewTenant(t, harness.WithPlan(license.Enterprise().Without(license.RBAC)))- untouched := h.NewTenant(t)-- untouched.Verify(t, license.Enterprise())- narrowed.Verify(t, license.Enterprise().Without(license.RBAC))- })-}--func TestProject_Create(t *testing.T) {- t.Parallel()- h := harness.From(t)-- t.Run("ok/creates a project in the tenant's organization", func(t *testing.T) {- t.Parallel()- tn := h.NewTenant(t)-- res, err := tn.Admin.API.CreateProjectWithResponse(t.Context(), api.CreateProjectJSONRequestBody{- ProjectName: "app",- })- if err != nil {- t.Fatalf("creating a project: %v", err)- }- if res.JSON200 == nil {- t.Fatalf("creating a project returned %d: %s", res.StatusCode(), res.Body)- }- })-}diff --git a/tests/suites/platform/principal_test.go b/tests/suites/platform/principal_test.godeleted file mode 100644index c7eba89ef5..0000000000--- a/tests/suites/platform/principal_test.go+++ /dev/null@@ -1,187 +0,0 @@-package platform_test--import (- "net/http"- "testing"-- "github.com/Infisical/infisical/tests/clients/api"- "github.com/Infisical/infisical/tests/fixture/project"- "github.com/Infisical/infisical/tests/harness"- "github.com/Infisical/infisical/tests/internal/spec"-)--func TestIdentity_Create(t *testing.T) {- t.Parallel()- h := harness.From(t)-- t.Run("ok/an identity can act in its own organization", func(t *testing.T) {- t.Parallel()- tn := h.NewTenant(t)- id := tn.NewIdentity(t, harness.OrgRole("admin"))-- if id.Token == "" {- t.Fatal("identity has no access token, so nothing below it can authenticate")- }- res, err := id.API.GetOrganizationPlanWithResponse(t.Context(), tn.OrgID.String(), nil)- if err != nil {- t.Fatalf("reading the plan as an identity: %v", err)- }- if res.StatusCode() != http.StatusOK {- t.Fatalf("identity cannot read its own organization: %d", res.StatusCode())- }- })-- t.Run("forbidden/a no-access identity cannot create a project", func(t *testing.T) {- t.Parallel()- spec.Why(t, `The org role on the identity has to reach the permission layer. If it- did not, every identity would behave like an admin and no authorization test- below this one would mean anything.-- Project creation rather than a read: reading the plan only proves membership,- which no-access still has.`)-- tn := h.NewTenant(t)- id := tn.NewIdentity(t, harness.OrgRole("no-access"))-- res, err := id.API.CreateProjectWithResponse(t.Context(), api.CreateProjectJSONRequestBody{- ProjectName: "should-not-exist",- })- if err != nil {- t.Fatalf("creating a project as a no-access identity: %v", err)- }- if res.StatusCode() == http.StatusOK {- t.Fatal("a no-access identity created a project")- }- })-- t.Run("cross-tenant/an identity cannot reach another organization", func(t *testing.T) {- t.Parallel()- mine, theirs := h.NewTenant(t), h.NewTenant(t)- id := mine.NewIdentity(t, harness.OrgRole("admin"))-- res, err := id.API.GetOrganizationPlanWithResponse(t.Context(), theirs.OrgID.String(), nil)- if err != nil {- t.Fatalf("reading another organization: %v", err)- }- if res.StatusCode() == http.StatusOK {- t.Fatalf("identity in %s read %s's plan", mine.OrgSlug, theirs.OrgSlug)- }- })-}--func TestUser_Invite(t *testing.T) {- t.Parallel()- h := harness.From(t)-- t.Run("ok/an invited user becomes a member", func(t *testing.T) {- t.Parallel()- spec.Why(t, `The invite link only comes back in the response when SMTP is- unconfigured, and the harness configures it. So this is also the proof that- the harness can read a mailbox at all: every email-driven flow depends on it.`)-- tn := h.NewTenant(t)- alice := tn.NewUser(t, harness.WithName("alice"))-- if alice.Email != tn.Address("alice") {- t.Errorf("user got mailbox %q, want %q", alice.Email, tn.Address("alice"))- }- res, err := alice.API.GetOrganizationPlanWithResponse(t.Context(), tn.OrgID.String(), nil)- if err != nil {- t.Fatalf("reading the plan as the invited user: %v", err)- }- if res.StatusCode() != http.StatusOK {- t.Fatalf("invited user cannot read the organization they joined: %d", res.StatusCode())- }- })-- t.Run("cross-tenant/two tenants can invite the same local part", func(t *testing.T) {- t.Parallel()- spec.Why(t, `Mail isolation is by address, not by server: one Mailpit serves the- whole run. If the domains did not differ, two parallel tests inviting "alice"- would read each other's invitation and both would pass or fail at random.`)-- a, b := h.NewTenant(t), h.NewTenant(t)- ua, ub := a.NewUser(t, harness.WithName("alice")), b.NewUser(t, harness.WithName("alice"))-- if ua.Email == ub.Email {- t.Fatalf("both tenants issued %s", ua.Email)- }- res, err := ua.API.GetOrganizationPlanWithResponse(t.Context(), b.OrgID.String(), nil)- if err != nil {- t.Fatalf("reading the other organization: %v", err)- }- if res.StatusCode() == http.StatusOK {- t.Fatalf("%s read %s's plan", ua.Email, b.OrgSlug)- }- })-}--func TestProject_Access(t *testing.T) {- t.Parallel()- h := harness.From(t)-- t.Run("ok/an identity created in a project can read it", func(t *testing.T) {- t.Parallel()- tn := h.NewTenant(t)- proj := project.New(t, tn)- id := proj.NewIdentity(t, project.Role("admin"))-- res, err := id.API.ListProjectMachineIdentitiesWithResponse(t.Context(), proj.ID, nil)- if err != nil {- t.Fatalf("listing project identities: %v", err)- }- if res.StatusCode() != http.StatusOK {- t.Fatalf("identity created in the project cannot read it: %d: %s", res.StatusCode(), res.Body)- }- })-- t.Run("forbidden/an org identity outside the project is refused", func(t *testing.T) {- t.Parallel()- spec.Why(t, `Organization membership is not project membership. Conflating them is- the mistake that would make every project-scoped authorization test vacuous.`)-- tn := h.NewTenant(t)- proj := project.New(t, tn)- outsider := tn.NewIdentity(t, harness.OrgRole("member"))-- res, err := outsider.API.ListProjectMachineIdentitiesWithResponse(t.Context(), proj.ID, nil)- if err != nil {- t.Fatalf("listing project identities: %v", err)- }- if res.StatusCode() == http.StatusOK {- t.Fatal("an identity with no project membership read the project")- }- })-- t.Run("ok/granting an existing identity opens the project", func(t *testing.T) {- t.Parallel()- tn := h.NewTenant(t)- proj := project.New(t, tn)- id := tn.NewIdentity(t, harness.OrgRole("member"))-- proj.Grant(t, id, "admin")-- res, err := id.API.ListProjectMachineIdentitiesWithResponse(t.Context(), proj.ID, nil)- if err != nil {- t.Fatalf("listing project identities: %v", err)- }- if res.StatusCode() != http.StatusOK {- t.Fatalf("identity granted project access still refused: %d: %s", res.StatusCode(), res.Body)- }- })-- t.Run("ok/a user can be added to a project", func(t *testing.T) {- t.Parallel()- tn := h.NewTenant(t)- proj := project.New(t, tn)- bob := proj.NewUser(t, project.Name("bob"), project.Role("admin"))-- res, err := bob.API.ListProjectMachineIdentitiesWithResponse(t.Context(), proj.ID, nil)- if err != nil {- t.Fatalf("listing project identities: %v", err)- }- if res.StatusCode() != http.StatusOK {- t.Fatalf("user added to the project cannot read it: %d: %s", res.StatusCode(), res.Body)- }- })-}diff --git a/tests/suites/platform/main_test.go b/tests/suites/project/main_test.gosimilarity index 86%rename from tests/suites/platform/main_test.gorename to tests/suites/project/main_test.goindex 7b3423bee5..9e82125f78 100644--- a/tests/suites/platform/main_test.go+++ b/tests/suites/project/main_test.go@@ -1,4 +1,4 @@-package platform_test+package project_testimport ("testing"diff --git a/tests/suites/project/project_test.go b/tests/suites/project/project_test.gonew file mode 100644index 0000000000..a72b97ddc4--- /dev/null+++ b/tests/suites/project/project_test.go@@ -0,0 +1,47 @@+package project_test++import (+ "slices"+ "testing"++ "github.com/Infisical/infisical/tests/clients/api"+ "github.com/Infisical/infisical/tests/harness"+)++func TestProject_Create(t *testing.T) {+ t.Parallel()+ h := harness.From(t)++ t.Run("ok/creates a project in the tenant's organization", func(t *testing.T) {+ t.Parallel()+ tn := h.NewTenant(t)++ res, err := tn.Admin.API.CreateProjectWithResponse(t.Context(), api.CreateProjectJSONRequestBody{+ ProjectName: "app",+ })+ if err != nil {+ t.Fatalf("creating a project: %v", err)+ }+ if res.JSON200 == nil {+ t.Fatalf("creating a project returned %d: %s", res.StatusCode(), res.Body)+ }++ proj := res.JSON200.Project+ if proj.OrgId != tn.OrgID {+ t.Errorf("project landed in organization %s, want the caller's %s", proj.OrgId, tn.OrgID)+ }++ // Creating a project provisions its environments. A project without them is+ // not usable for anything, and the response is the only place a caller learns+ // what the slugs are.+ var envs []string+ for _, e := range proj.Environments {+ envs = append(envs, e.Slug)+ }+ for _, want := range []string{"dev", "staging", "prod"} {+ if !slices.Contains(envs, want) {+ t.Errorf("new project has environments %v, missing %q", envs, want)+ }+ }+ })+}