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 integration test to top folder
=4f6b7c1a17b4
diff --git a/backend-go/CLAUDE.md b/backend-go/CLAUDE.mdindex 01c85902d8..e4b6773344 100644--- a/backend-go/CLAUDE.md+++ b/backend-go/CLAUDE.md@@ -5,12 +5,15 @@ Partial Go rewrite of the Node.js backend using chi + oapi-codegen + raw pgx que## Commands```-make build # build binary-make dev # hot-reload via docker-compose + air-make test # integration tests (testcontainers, -race)-make lint # must pass before submission-make lint-fix # auto-fix linting issues-make generate # run go generate ./... for oapi-codegen+make build # build binary+make dev # hot-reload via docker-compose + air+make test # run all tests (unit + integration)+make test-unit # unit tests only (./internal/...)+make test-integration # integration tests only (./tests/..., testcontainers)+make test-hsm # HSM tests (requires Docker, builds test container)+make lint # must pass before submission+make lint-fix # auto-fix linting issues+make generate # run go generate ./... for oapi-codegen```## Code Rules@@ -49,8 +52,19 @@ internal/│ │ └── secretmanager/ # Secret manager handlers│ └── middlewares/ # HTTP middlewares (RequireAuth, etc.)├── services/ # Shared business logic (auth, permission, kms, ...)-├── keystore/ # Redis key-value operations-└── testutil/ # Test infra (testcontainers)+└── keystore/ # Redis key-value operations+tests/ # Integration tests (external test packages)+├── infra/ # Test infrastructure (testcontainers, helpers)+├── platform/ # Platform service tests+│ ├── auth/ # Authentication handler tests+│ ├── externalkms/ # External KMS (AWS/GCP) tests+│ ├── hsm/ # HSM tests (container-based)+│ ├── kms/ # KMS service tests+│ ├── permission/ # Permission system tests+│ ├── projects/ # Projects handler tests+│ └── ratelimit/ # Rate limiting tests+└── secretmanager/+ └── secrets/ # Secrets API tests (list, get, permissions)```**Two tiers:**diff --git a/backend-go/Makefile b/backend-go/Makefileindex 59ff6ce0dd..d5c91cfa5e 100644--- a/backend-go/Makefile+++ b/backend-go/Makefile@@ -1,4 +1,4 @@-.PHONY: lint lint-fix test test-integration test-all dev build generate test-hsm-image test-hsm+.PHONY: lint lint-fix test test-unit test-integration dev build generate test-hsm-image test-hsm# Run linterslint:@@ -7,12 +7,16 @@ lint:lint-fix:go fix ./... && golangci-lint run --build-tags integration --fix+# Run unit tests only (no testcontainers)test-unit:go test -v ./internal/... -count=1 -race -timeout 120s-# Run integration tests — testcontainers spins up isolated containers per package-test:- go test -v -tags integration ./internal/... -count=1 -race -timeout 300s+# Run integration tests only — testcontainers spins up isolated containers per package+test-integration:+ go test -v -tags integration ./tests/... -count=1 -race -timeout 300s++# Run all tests (unit + integration)+test: test-unit test-integration# Start Go backend with hot-reload (uses root docker-compose.dev.yml)dev:@@ -32,4 +36,4 @@ test-hsm-image:# Run HSM integration tests (requires test-hsm-image to be built first)test-hsm: test-hsm-image- INFISICAL_RUN_HSM_CONTAINER_TEST=1 go test -v -tags integration ./internal/ee/services/hsm/... -count=1 -timeout 300s+ INFISICAL_RUN_HSM_CONTAINER_TEST=1 go test -v -tags integration ./tests/platform/hsm/... -count=1 -timeout 300sdiff --git a/backend-go/internal/testutil/infra/builder.go b/backend-go/tests/infra/builder.gosimilarity index 100%rename from backend-go/internal/testutil/infra/builder.gorename to backend-go/tests/infra/builder.godiff --git a/backend-go/internal/testutil/infra/constants.go b/backend-go/tests/infra/constants.gosimilarity index 100%rename from backend-go/internal/testutil/infra/constants.gorename to backend-go/tests/infra/constants.godiff --git a/backend-go/internal/testutil/infra/container.go b/backend-go/tests/infra/container.gosimilarity index 100%rename from backend-go/internal/testutil/infra/container.gorename to backend-go/tests/infra/container.godiff --git a/backend-go/internal/testutil/infra/infisical_secrets.go b/backend-go/tests/infra/infisical_secrets.gosimilarity index 100%rename from backend-go/internal/testutil/infra/infisical_secrets.gorename to backend-go/tests/infra/infisical_secrets.godiff --git a/backend-go/internal/testutil/logger.go b/backend-go/tests/infra/logger.gosimilarity index 80%rename from backend-go/internal/testutil/logger.gorename to backend-go/tests/infra/logger.goindex e0e5c28a58..67bd3db7db 100644--- a/backend-go/internal/testutil/logger.go+++ b/backend-go/tests/infra/logger.go@@ -1,4 +1,6 @@-package testutil+//go:build integration++package infraimport ("log/slog"diff --git a/backend-go/internal/testutil/infra/nodejs.go b/backend-go/tests/infra/nodejs.gosimilarity index 100%rename from backend-go/internal/testutil/infra/nodejs.gorename to backend-go/tests/infra/nodejs.godiff --git a/backend-go/internal/testutil/infra/nodejs_types.go b/backend-go/tests/infra/nodejs_types.gosimilarity index 100%rename from backend-go/internal/testutil/infra/nodejs_types.gorename to backend-go/tests/infra/nodejs_types.godiff --git a/backend-go/internal/testutil/infra/postgres.go b/backend-go/tests/infra/postgres.gosimilarity index 100%rename from backend-go/internal/testutil/infra/postgres.gorename to backend-go/tests/infra/postgres.godiff --git a/backend-go/internal/testutil/infra/redis.go b/backend-go/tests/infra/redis.gosimilarity index 100%rename from backend-go/internal/testutil/infra/redis.gorename to backend-go/tests/infra/redis.godiff --git a/backend-go/internal/testutil/infra/stack.go b/backend-go/tests/infra/stack.gosimilarity index 100%rename from backend-go/internal/testutil/infra/stack.gorename to backend-go/tests/infra/stack.godiff --git a/backend-go/internal/services/auth/handler_integration_test.go b/backend-go/tests/platform/auth/handler_test.gosimilarity index 86%rename from backend-go/internal/services/auth/handler_integration_test.gorename to backend-go/tests/platform/auth/handler_test.goindex 907aadb38b..145b09367f 100644--- a/backend-go/internal/services/auth/handler_integration_test.go+++ b/backend-go/tests/platform/auth/handler_test.go@@ -22,7 +22,7 @@ import ("github.com/infisical/api/internal/libs/errutil""github.com/infisical/api/internal/services/auth""github.com/infisical/api/internal/services/auth/apiauth"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")var (@@ -217,9 +217,6 @@ func TestValidateJWT_UserToken_Errors(t *testing.T) {}func TestValidateJWT_UserToken_StaleAccessVersion(t *testing.T) {- // This test requires DB manipulation to create a session with a different access version- // We create a valid token but modify the session's access version in DB-userID := uuid.MustParse(stack.NodeJS().UserID())sessionID := uuid.New()@@ -249,7 +246,6 @@ func TestValidateJWT_UserToken_StaleAccessVersion(t *testing.T) {}func TestValidateJWT_UserToken_UserLocked(t *testing.T) {- // Create a user that is permanently lockedlockedUserID := uuid.New()testEmail := "locked-" + uuid.New().String() + "@test.com"_, err := stack.DB().Primary().Exec(context.Background(), `@@ -263,7 +259,6 @@ func TestValidateJWT_UserToken_UserLocked(t *testing.T) {pgx.NamedArgs{"userID": lockedUserID})})- // Create a session for the locked usersessionID := uuid.New()_, err = stack.DB().Primary().Exec(context.Background(), `INSERT INTO auth_token_sessions (id, "userId", "accessVersion", "refreshVersion", ip, "userAgent", "lastUsed", "createdAt", "updatedAt")@@ -289,10 +284,9 @@ func TestValidateJWT_UserToken_UserLocked(t *testing.T) {}func TestValidateJWT_UserToken_UserTemporarilyLocked(t *testing.T) {- // Create a user that is temporarily locked (lock expires in the future)tempLockedUserID := uuid.New()testEmail := "templocked-" + uuid.New().String() + "@test.com"- lockEnd := time.Now().Add(time.Hour) // Locked for another hour+ lockEnd := time.Now().Add(time.Hour)_, err := stack.DB().Primary().Exec(context.Background(), `INSERT INTO users (id, email, username, "isAccepted", "temporaryLockDateEnd", "createdAt", "updatedAt")VALUES (@userID, @email, @username, true, @lockEnd, NOW(), NOW())@@ -304,7 +298,6 @@ func TestValidateJWT_UserToken_UserTemporarilyLocked(t *testing.T) {pgx.NamedArgs{"userID": tempLockedUserID})})- // Create a session for the temp-locked usersessionID := uuid.New()_, err = stack.DB().Primary().Exec(context.Background(), `INSERT INTO auth_token_sessions (id, "userId", "accessVersion", "refreshVersion", ip, "userAgent", "lastUsed", "createdAt", "updatedAt")@@ -330,7 +323,6 @@ func TestValidateJWT_UserToken_UserTemporarilyLocked(t *testing.T) {}func TestValidateJWT_UserToken_UserNotAccepted(t *testing.T) {- // Create a user that has not acceptednotAcceptedUserID := uuid.New()testEmail := "notaccepted-" + uuid.New().String() + "@test.com"_, err := stack.DB().Primary().Exec(context.Background(), `@@ -344,7 +336,6 @@ func TestValidateJWT_UserToken_UserNotAccepted(t *testing.T) {pgx.NamedArgs{"userID": notAcceptedUserID})})- // Create a session for the not-accepted usersessionID := uuid.New()_, err = stack.DB().Primary().Exec(context.Background(), `INSERT INTO auth_token_sessions (id, "userId", "accessVersion", "refreshVersion", ip, "userAgent", "lastUsed", "createdAt", "updatedAt")@@ -383,7 +374,6 @@ func TestValidateIdentityAccessToken_Valid(t *testing.T) {assert.Equal(t, auth.ActorTypeIdentity, identity.Actor)assert.NotEqual(t, uuid.Nil, identity.ActorID)assert.Equal(t, uuid.MustParse(stack.NodeJS().OrgID()), identity.OrgID)- // Verify identity-specific fieldsrequire.NotNil(t, identity.IdentityAuthInfo)assert.NotEqual(t, uuid.Nil, identity.IdentityAuthInfo.IdentityID)}@@ -451,7 +441,6 @@ func TestValidateIdentityAccessToken_Errors(t *testing.T) {func TestValidateIdentityAccessToken_CustomIdentity(t *testing.T) {nodejs := stack.NodeJS()- // Create unique project and identity for this testprojName := "test-" + uuid.New().String()[:8]proj := nodejs.CreateProject(t, projName)t.Cleanup(func() {@@ -475,7 +464,6 @@ func TestValidateIdentityAccessToken_CustomIdentity(t *testing.T) {func TestValidateIdentityAccessToken_Revoked(t *testing.T) {nodejs := stack.NodeJS()- // Create identity and get tokenprojName := "test-revoke-" + uuid.New().String()[:8]proj := nodejs.CreateProject(t, projName)t.Cleanup(func() {@@ -487,7 +475,6 @@ func TestValidateIdentityAccessToken_Revoked(t *testing.T) {token := nodejs.GetIdentityAccessToken(t, identity.ID)- // Revoke the token via Node.js APInodejs.RevokeAccessToken(t, token)_, err := authenticator.ValidateIdentityAccessToken(context.Background(), token, "")@@ -499,7 +486,6 @@ func TestValidateIdentityAccessToken_Revoked(t *testing.T) {func TestValidateIdentityAccessToken_IdentityDeleted(t *testing.T) {nodejs := stack.NodeJS()- // Create identity and get tokenprojName := "test-idelete-" + uuid.New().String()[:8]proj := nodejs.CreateProject(t, projName)t.Cleanup(func() {@@ -511,12 +497,10 @@ func TestValidateIdentityAccessToken_IdentityDeleted(t *testing.T) {token := nodejs.GetIdentityAccessToken(t, identity.ID)- // Delete the identity - this revokes all tokens for the identitynodejs.DeleteIdentity(t, identity.ID)_, err := authenticator.ValidateIdentityAccessToken(context.Background(), token, "")- // Token should fail - either as revoked or identity not foundrequire.Error(t, err)}@@ -564,14 +548,12 @@ func TestValidateServiceToken_Errors(t *testing.T) {func TestValidateServiceToken_Valid(t *testing.T) {nodejs := stack.NodeJS()- // Create a project with an environmentprojName := "test-st-valid-" + uuid.New().String()[:8]proj := nodejs.CreateProject(t, projName)t.Cleanup(func() {nodejs.DeleteProject(t, proj.ID)})- // Create a service token (no expiry)st := nodejs.CreateServiceToken(t, proj.ID, "dev", nil)t.Cleanup(func() {nodejs.DeleteServiceToken(t, st.ID)@@ -589,7 +571,6 @@ func TestValidateServiceToken_Valid(t *testing.T) {func TestValidateServiceToken_WrongSecret(t *testing.T) {nodejs := stack.NodeJS()- // Create a project and service tokenprojName := "test-st-wrongsec-" + uuid.New().String()[:8]proj := nodejs.CreateProject(t, projName)t.Cleanup(func() {@@ -601,8 +582,6 @@ func TestValidateServiceToken_WrongSecret(t *testing.T) {nodejs.DeleteServiceToken(t, st.ID)})- // Extract the token ID and use a wrong secret- // Token format: st.<id>.<secret>parts := strings.SplitN(st.Token, ".", 3)require.Len(t, parts, 3)wrongToken := "st." + parts[1] + ".wrong-secret-here"@@ -616,24 +595,19 @@ func TestValidateServiceToken_WrongSecret(t *testing.T) {func TestValidateServiceToken_Expired(t *testing.T) {nodejs := stack.NodeJS()- // Create a projectprojName := "test-st-expired-" + uuid.New().String()[:8]proj := nodejs.CreateProject(t, projName)t.Cleanup(func() {nodejs.DeleteProject(t, proj.ID)})- // Create a service token that expires in 1 secondexpiresIn := 1st := nodejs.CreateServiceToken(t, proj.ID, "dev", &expiresIn)- // No cleanup needed - token is auto-deleted when expired- // Wait for expirationtime.Sleep(2 * time.Second)_, err := authenticator.ValidateServiceToken(context.Background(), st.Token)- // Should fail - token is expired (and possibly deleted)require.Error(t, err)}@@ -644,7 +618,6 @@ func TestValidateServiceToken_Expired(t *testing.T) {func TestValidateIdentityAccessToken_NumUsesLimitExhausted(t *testing.T) {nodejs := stack.NodeJS()- // Create identity with numUsesLimitprojName := "test-numlimit-" + uuid.New().String()[:8]proj := nodejs.CreateProject(t, projName)t.Cleanup(func() {@@ -654,11 +627,8 @@ func TestValidateIdentityAccessToken_NumUsesLimitExhausted(t *testing.T) {identity := nodejs.CreateIdentity(t, "identity-numlimit-"+uuid.New().String()[:8])nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("admin"))- // Get token - this creates universal auth with default settings (no limit)- // We need to set up the limit in Redis manually since the token is already issuedtoken := nodejs.GetIdentityAccessToken(t, identity.ID)- // Parse to get token IDclaims := &apiauth.IdentityJWTClaims{}_, _ = jwt.ParseWithClaims(token, claims, func(_ *jwt.Token) (any, error) {return []byte(infra.AuthSecret), nil@@ -669,13 +639,10 @@ func TestValidateIdentityAccessToken_NumUsesLimitExhausted(t *testing.T) {tokenID = claims.IdentityAccessTokenID}- // Set uses remaining to 0 in keystore (simulating exhausted limit)key := "identity-token-uses-remaining:" + identity.ID + ":" + tokenIDerr := memKeyStore.SetItem(context.Background(), key, "0")require.NoError(t, err)- // Create a new authenticator that checks numUsesLimit- // We need to sign a token WITH numUsesLimit claimtokenWithLimit := signIdentityJWT(t, infra.AuthSecret, func(c *apiauth.IdentityJWTClaims) {c.IdentityID = uuid.MustParse(identity.ID)c.OrgID = uuid.MustParse(stack.NodeJS().OrgID())@@ -683,7 +650,7 @@ func TestValidateIdentityAccessToken_NumUsesLimitExhausted(t *testing.T) {c.ParentOrgID = uuid.MustParse(stack.NodeJS().OrgID())c.AuthMethod = "universal-auth"c.AccessTokenTTL = 3600- c.NumUsesLimit = 5 // Has a limit+ c.NumUsesLimit = 5c.ID = tokenID})@@ -698,8 +665,6 @@ func TestValidateIdentityAccessToken_NumUsesLimitExhausted(t *testing.T) {// =============================================================================func TestValidateJWT_UserToken_AlgNoneAttack(t *testing.T) {- // Create a token with alg=none - this should be rejected- // JWT with alg:none has no signatureheader := base64URLEncode(`{"alg":"none","typ":"JWT"}`)payload := base64URLEncode(`{"authTokenType":"accessToken","userId":"` + stack.NodeJS().UserID() + `"}`)algNoneToken := header + "." + payload + "."@@ -710,8 +675,6 @@ func TestValidateJWT_UserToken_AlgNoneAttack(t *testing.T) {}func TestValidateJWT_UserToken_WrongAlgorithm(t *testing.T) {- // Try to use RS256 when the server expects HS256- // This tests that the server properly validates the algorithmtoken := jwt.NewWithClaims(jwt.SigningMethodHS384, &apiauth.UserJWTClaims{AuthTokenType: auth.AuthTokenTypeAccessToken,UserID: uuid.MustParse(stack.NodeJS().UserID()),@@ -723,13 +686,11 @@ func TestValidateJWT_UserToken_WrongAlgorithm(t *testing.T) {IssuedAt: jwt.NewNumericDate(time.Now()),},})- // Sign with the correct secret but wrong algorithmtokenString, err := token.SignedString([]byte(infra.AuthSecret))require.NoError(t, err)_, err = authenticator.ValidateJWT(context.Background(), tokenString)- // Should fail because algorithm doesn't matchassertUnauthorized(t, err)}@@ -740,7 +701,6 @@ func TestValidateJWT_UserToken_WrongAlgorithm(t *testing.T) {func TestValidateIdentityAccessToken_LegacyRevoked(t *testing.T) {nodejs := stack.NodeJS()- // Create identityprojName := "test-legacy-rev-" + uuid.New().String()[:8]proj := nodejs.CreateProject(t, projName)t.Cleanup(func() {@@ -750,8 +710,6 @@ func TestValidateIdentityAccessToken_LegacyRevoked(t *testing.T) {identity := nodejs.CreateIdentity(t, "identity-legacy-"+uuid.New().String()[:8])nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("admin"))- // Create a legacy-style token (without full renew claims) that points to a DB row- // Insert a revoked token row directly into DBtokenID := uuid.New()identityID := uuid.MustParse(identity.ID)@@ -770,12 +728,9 @@ func TestValidateIdentityAccessToken_LegacyRevoked(t *testing.T) {pgx.NamedArgs{"tokenID": tokenID})})- // Create a legacy token (no full renew claims) pointing to this DB rowlegacyToken := signIdentityJWT(t, infra.AuthSecret, func(c *apiauth.IdentityJWTClaims) {c.IdentityID = identityIDc.IdentityAccessTokenID = tokenID.String()- // Don't set OrgID, RootOrgID, ParentOrgID, AuthMethod, AccessTokenTTL- // This makes HasFullRenewClaims() return false, triggering legacy DB lookupc.OrgID = uuid.Nilc.RootOrgID = uuid.Nilc.ParentOrgID = uuid.Nil@@ -825,31 +780,3 @@ func TestValidateJWT_MalformedTokens(t *testing.T) {})}}--// =============================================================================-// TODO(go:akhilmhdh): Missing Edge Cases-// =============================================================================-//-// The following edge cases are not yet covered by tests. They require additional-// setup (EE features, complex fixtures) or test infrastructure not yet available.-//-// JWT/User Token:-// - TODO: Sub-organization scoping (claims.SubOrganizationID set) - requires EE sub-org feature-// - TODO: Sub-org doesn't belong to root org (forbidden case)-// - TODO: Org membership inactive-// - TODO: Group-based org membership (actorGroupId IN (...) branch)-// - TODO: SuperAdmin field propagation onto Identity-// - TODO: IsMfaVerified/MfaMethod field propagation onto Identity-// - TODO: AuthMethod field propagation onto Identity-//-// Identity Access Token:-// - TODO: IdentityAuth claims propagation (OIDC details)-// - TODO: IdentityAuth claims propagation (Kubernetes details)-// - TODO: IdentityAuth claims propagation (AWS details)-// - TODO: Sub-org scoping for identity tokens-// - TODO: Explicit test for new-format token path (HasFullRenewClaims=true)-// - TODO: Explicit test for legacy DB-lookup path (HasFullRenewClaims=false)-//-// Cross-cutting:-// - TODO: HTTPInfoMiddleware propagation (IPAddress/UserAgent onto Identity)-// - TODO: IP blocklist check (currently bypassed with empty string)diff --git a/backend-go/internal/ee/services/externalkms/externalkms_integration_test.go b/backend-go/tests/platform/externalkms/externalkms_test.gosimilarity index 98%rename from backend-go/internal/ee/services/externalkms/externalkms_integration_test.gorename to backend-go/tests/platform/externalkms/externalkms_test.goindex 52e9e594a7..7fd13fde24 100644--- a/backend-go/internal/ee/services/externalkms/externalkms_integration_test.go+++ b/backend-go/tests/platform/externalkms/externalkms_test.go@@ -10,8 +10,7 @@ import ("github.com/stretchr/testify/require""github.com/infisical/api/internal/ee/services/externalkms"- "github.com/infisical/api/internal/testutil"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")// Secret keys in Infisical /platform folder.@@ -33,7 +32,7 @@ const (func newService(t *testing.T) *externalkms.Service {t.Helper()- svc, err := externalkms.NewService(context.Background(), testutil.NopLogger(), &externalkms.Deps{})+ svc, err := externalkms.NewService(context.Background(), infra.NopLogger(), &externalkms.Deps{})require.NoError(t, err)return svc}diff --git a/backend-go/internal/ee/services/hsm/hsm_integration_test.go b/backend-go/tests/platform/hsm/hsm_test.gosimilarity index 97%rename from backend-go/internal/ee/services/hsm/hsm_integration_test.gorename to backend-go/tests/platform/hsm/hsm_test.goindex 0f7ed3e4ba..f2ff65cfd9 100644--- a/backend-go/internal/ee/services/hsm/hsm_integration_test.go+++ b/backend-go/tests/platform/hsm/hsm_test.go@@ -12,7 +12,7 @@ import ("github.com/stretchr/testify/require""github.com/infisical/api/internal/ee/services/hsm"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")var runner = infra.NewContainerTest(@@ -20,7 +20,7 @@ var runner = infra.NewContainerTest("INFISICAL_HSM_TEST_INSIDE","INFISICAL_RUN_HSM_CONTAINER_TEST",).- WithTestPath("./internal/ee/services/hsm/...").+ WithTestPath("./tests/platform/hsm/...").WithBuildTags("integration").WithEnv("SOFTHSM2_LIB", "/usr/lib/softhsm/libsofthsm2.so")diff --git a/backend-go/internal/services/kms/kms_integration_test.go b/backend-go/tests/platform/kms/kms_test.gosimilarity index 98%rename from backend-go/internal/services/kms/kms_integration_test.gorename to backend-go/tests/platform/kms/kms_test.goindex e86ae22816..6639c63fc3 100644--- a/backend-go/internal/services/kms/kms_integration_test.go+++ b/backend-go/tests/platform/kms/kms_test.go@@ -15,8 +15,7 @@ import ("github.com/infisical/api/internal/ee/services/externalkms""github.com/infisical/api/internal/services/kms"- "github.com/infisical/api/internal/testutil"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")var stack *infra.Stack@@ -35,7 +34,7 @@ func TestMain(m *testing.M) {func startedService(t *testing.T) *kms.Service {t.Helper()- svc, err := kms.NewService(context.Background(), testutil.NopLogger(), &kms.Deps{+ svc, err := kms.NewService(context.Background(), infra.NopLogger(), &kms.Deps{DB: stack.DB(),HSM: nil,ExternalKms: nil,@@ -276,7 +275,7 @@ func TestCreateCipherPair_EmptyProjectIDFails(t *testing.T) {func startedServiceWithExternalKms(t *testing.T, extKms kms.ExternalKmsService) *kms.Service {t.Helper()- svc, err := kms.NewService(context.Background(), testutil.NopLogger(), &kms.Deps{+ svc, err := kms.NewService(context.Background(), infra.NopLogger(), &kms.Deps{DB: stack.DB(),HSM: nil,ExternalKms: extKms,diff --git a/backend-go/internal/services/permission/permission_integration_test.go b/backend-go/tests/platform/permission/permission_test.gosimilarity index 64%rename from backend-go/internal/services/permission/permission_integration_test.gorename to backend-go/tests/platform/permission/permission_test.goindex 561314707e..39c0e3e914 100644--- a/backend-go/internal/services/permission/permission_integration_test.go+++ b/backend-go/tests/platform/permission/permission_test.go@@ -16,8 +16,7 @@ import ("github.com/infisical/api/internal/services/auth""github.com/infisical/api/internal/services/permission""github.com/infisical/api/internal/services/permission/project"- "github.com/infisical/api/internal/testutil"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")var (@@ -40,7 +39,7 @@ func TestMain(m *testing.M) {}func newPermissionService() *permission.Service {- return permission.NewService(context.Background(), testutil.NopLogger(), &permission.Deps{DB: stack.DB()})+ return permission.NewService(context.Background(), infra.NopLogger(), &permission.Deps{DB: stack.DB()})}func getProjectPermission(t *testing.T, actorType auth.ActorType, actorID string) *permission.GetProjectPermissionResult {@@ -73,42 +72,34 @@ func TestIdentityAdmin_CanDoEverything(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability- // Secrets CRUDassert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{}))- // Secret folders CRUDassert.True(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))assert.True(t, gocasl.Can(ability, project.SecretFolderActionCreate, project.SecretFolderSubject{}))assert.True(t, gocasl.Can(ability, project.SecretFolderActionEdit, project.SecretFolderSubject{}))assert.True(t, gocasl.Can(ability, project.SecretFolderActionDelete, project.SecretFolderSubject{}))- // Membersassert.True(t, gocasl.Can(ability, project.MemberActionRead, project.MemberSubject{}))assert.True(t, gocasl.Can(ability, project.MemberActionCreate, project.MemberSubject{}))assert.True(t, gocasl.Can(ability, project.MemberActionEdit, project.MemberSubject{}))assert.True(t, gocasl.Can(ability, project.MemberActionDelete, project.MemberSubject{}))- // Project managementassert.True(t, gocasl.Can(ability, project.ProjectActionEdit, project.ProjectSubject{}))assert.True(t, gocasl.Can(ability, project.ProjectActionDelete, project.ProjectSubject{}))- // Rolesassert.True(t, gocasl.Can(ability, project.RoleActionRead, project.RoleSubject{}))assert.True(t, gocasl.Can(ability, project.RoleActionCreate, project.RoleSubject{}))- // Identity managementassert.True(t, gocasl.Can(ability, project.IdentityActionRead, project.IdentitySubject{}))assert.True(t, gocasl.Can(ability, project.IdentityActionCreate, project.IdentitySubject{}))assert.True(t, gocasl.Can(ability, project.IdentityActionGrantPrivileges, project.IdentitySubject{}))- // Environmentsassert.True(t, gocasl.Can(ability, project.EnvironmentsActionRead, project.EnvironmentsSubject{}))assert.True(t, gocasl.Can(ability, project.EnvironmentsActionCreate, project.EnvironmentsSubject{}))- // HasRoleassert.True(t, result.HasRole("admin"))assert.False(t, result.HasRole("viewer"))}@@ -121,24 +112,19 @@ func TestIdentityMember_LimitedAccess(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability- // Members CAN read/create/edit/delete secretsassert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{}))- // Members CAN manage secret foldersassert.True(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))assert.True(t, gocasl.Can(ability, project.SecretFolderActionCreate, project.SecretFolderSubject{}))- // Members CANNOT delete projectassert.False(t, gocasl.Can(ability, project.ProjectActionDelete, project.ProjectSubject{}))- // Members CANNOT grant privilegesassert.False(t, gocasl.Can(ability, project.MemberActionGrantPrivileges, project.MemberSubject{}))assert.False(t, gocasl.Can(ability, project.IdentityActionGrantPrivileges, project.IdentitySubject{}))- // HasRoleassert.True(t, result.HasRole("member"))assert.False(t, result.HasRole("admin"))}@@ -151,7 +137,6 @@ func TestIdentityViewer_ReadOnly(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability- // Viewers CAN read (viewer has describeSecret + readValue, not the combined "read" action)assert.True(t, gocasl.Can(ability, project.SecretActionDescribeSecret, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionReadValue, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))@@ -162,30 +147,23 @@ func TestIdentityViewer_ReadOnly(t *testing.T) {assert.True(t, gocasl.Can(ability, project.RoleActionRead, project.RoleSubject{}))assert.True(t, gocasl.Can(ability, project.AuditLogsActionRead, project.AuditLogsSubject{}))- // Viewer does NOT have the combined "read" (describeAndReadValue) actionassert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))- // Viewers CANNOT write secretsassert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{}))- // Viewers CANNOT write foldersassert.False(t, gocasl.Can(ability, project.SecretFolderActionCreate, project.SecretFolderSubject{}))assert.False(t, gocasl.Can(ability, project.SecretFolderActionEdit, project.SecretFolderSubject{}))assert.False(t, gocasl.Can(ability, project.SecretFolderActionDelete, project.SecretFolderSubject{}))- // Viewers CANNOT manage membersassert.False(t, gocasl.Can(ability, project.MemberActionCreate, project.MemberSubject{}))assert.False(t, gocasl.Can(ability, project.MemberActionDelete, project.MemberSubject{}))- // Viewers CANNOT delete projectassert.False(t, gocasl.Can(ability, project.ProjectActionDelete, project.ProjectSubject{}))- // Viewers CANNOT manage dynamic secretsassert.False(t, gocasl.Can(ability, project.DynamicSecretActionCreateRootCredential, project.DynamicSecretSubject{}))- // HasRoleassert.True(t, result.HasRole("viewer"))}@@ -197,7 +175,6 @@ func TestIdentityNoAccess_DeniedEverything(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability- // No-access CANNOT do anythingassert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))@@ -205,13 +182,11 @@ func TestIdentityNoAccess_DeniedEverything(t *testing.T) {assert.False(t, gocasl.Can(ability, project.ProjectActionDelete, project.ProjectSubject{}))assert.False(t, gocasl.Can(ability, project.IdentityActionRead, project.IdentitySubject{}))- // HasRoleassert.True(t, result.HasRole("no-access"))}func TestIdentityNotMember_Forbidden(t *testing.T) {nodejs := stack.NodeJS()- // Create identity but do NOT add to projectidentity := nodejs.CreateIdentity(t, "outsider-identity")ctx := context.Background()@@ -241,7 +216,6 @@ func TestUserAdmin_CanDoEverything(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeUser, user.ID)ability := result.Permission.Ability- // Admin can do everythingassert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))@@ -263,13 +237,11 @@ func TestUserViewer_ReadOnly(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeUser, user.ID)ability := result.Permission.Ability- // Can read (viewer has describeSecret + readValue, not combined "read")assert.True(t, gocasl.Can(ability, project.SecretActionDescribeSecret, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionReadValue, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))assert.True(t, gocasl.Can(ability, project.MemberActionRead, project.MemberSubject{}))- // Cannot writeassert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{}))@@ -311,7 +283,6 @@ func TestWrongProjectType_BadRequest(t *testing.T) {ctx := context.Background()svc := newPermissionService()- // Project is secret-manager, but we request certificate-manager_, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),@@ -330,8 +301,6 @@ func TestProjectTypeAny_Allowed(t *testing.T) {nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("viewer"))result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)- // ActionProjectTypeAny is used by getProjectPermission helper via ActionProjectTypeSecretManager,- // but let's test Any explicitlyctx := context.Background()svc := newPermissionService()resultAny, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{@@ -345,7 +314,6 @@ func TestProjectTypeAny_Allowed(t *testing.T) {require.NoError(t, err)require.NotNil(t, resultAny)- // Both should produce same abilities (viewer has describeSecret, not combined "read")assert.True(t, gocasl.Can(result.Permission.Ability, project.SecretActionDescribeSecret, project.SecretSubject{}))assert.True(t, gocasl.Can(resultAny.Permission.Ability, project.SecretActionDescribeSecret, project.SecretSubject{}))}@@ -402,9 +370,7 @@ func TestHasProjectEnforcement_ReturnsFunction(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)require.NotNil(t, result.HasProjectEnforcement)- // Default project should not have encrypted metadata enforcementassert.False(t, result.HasProjectEnforcement("enforceEncryptedSecretManagerSecretMetadata"))- // Unknown enforcement should return falseassert.False(t, result.HasProjectEnforcement("nonExistentEnforcement"))}@@ -415,7 +381,6 @@ func TestHasProjectEnforcement_ReturnsFunction(t *testing.T) {func TestIdentityCustomRole_SecretsReadCreateOnly(t *testing.T) {nodejs := stack.NodeJS()- // Create a custom role that allows only reading and creating secretscustomRole := nodejs.CreateCustomProjectRole(t, proj.ID, "secrets-read-create", "Secrets Read Create", []infra.Permission{{Subject: "secrets",@@ -429,62 +394,25 @@ func TestIdentityCustomRole_SecretsReadCreateOnly(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability- // CAN read and create secretsassert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))- // CANNOT edit or delete secretsassert.False(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{}))- // CANNOT do anything elseassert.False(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))assert.False(t, gocasl.Can(ability, project.MemberActionRead, project.MemberSubject{}))assert.False(t, gocasl.Can(ability, project.ProjectActionEdit, project.ProjectSubject{}))assert.False(t, gocasl.Can(ability, project.IdentityActionRead, project.IdentitySubject{}))- // HasRole returns the custom role slugassert.True(t, result.HasRole(customRole.Slug))assert.False(t, result.HasRole("admin"))assert.False(t, result.HasRole("member"))}-func TestUserCustomRole_SecretsReadCreateOnly(t *testing.T) {- nodejs := stack.NodeJS()-- customRole := nodejs.CreateCustomProjectRole(t, proj.ID, "user-secrets-rc", "User Secrets Read Create", []infra.Permission{- {- Subject: "secrets",- Action: []string{"read", "create"},- },- })-- user := nodejs.InviteAndCreateUser(t, "[email protected]")- nodejs.AddUserToProject(t, proj.ID, user.Email, []string{customRole.Slug})-- result := getProjectPermission(t, auth.ActorTypeUser, user.ID)- ability := result.Permission.Ability-- // CAN read and create secrets- assert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))- assert.True(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))-- // CANNOT edit or delete secrets- assert.False(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))- assert.False(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{}))-- // CANNOT do anything else- assert.False(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))- assert.False(t, gocasl.Can(ability, project.MemberActionRead, project.MemberSubject{}))- assert.False(t, gocasl.Can(ability, project.ProjectActionDelete, project.ProjectSubject{}))-- assert.True(t, result.HasRole(customRole.Slug))-}-func TestIdentityCustomRole_EnvironmentScoped(t *testing.T) {nodejs := stack.NodeJS()- // Create a custom role that allows reading secrets only in "dev" environmentcustomRole := nodejs.CreateCustomProjectRole(t, proj.ID, "dev-reader", "Dev Secret Reader", []infra.Permission{{Subject: "secrets",@@ -501,17 +429,13 @@ func TestIdentityCustomRole_EnvironmentScoped(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability- // CAN read secrets in "dev" environmentassert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{Environment: "dev"}))- // CANNOT read secrets in other environmentsassert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{Environment: "production"}))assert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{Environment: "staging"}))- // CANNOT read secrets without specifying environment (empty doesn't match "dev")assert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))- // CANNOT create/edit/delete even in devassert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{Environment: "dev"}))assert.False(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{Environment: "dev"}))assert.False(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{Environment: "dev"}))@@ -520,7 +444,6 @@ func TestIdentityCustomRole_EnvironmentScoped(t *testing.T) {func TestIdentityCustomRole_GlobSecretPath(t *testing.T) {nodejs := stack.NodeJS()- // Create a custom role with $glob condition on secretPathcustomRole := nodejs.CreateCustomProjectRole(t, proj.ID, "path-reader", "Path Scoped Reader", []infra.Permission{{Subject: "secrets",@@ -539,15 +462,12 @@ func TestIdentityCustomRole_GlobSecretPath(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability- // CAN read secrets under /app/assert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{SecretPath: "/app/config"}))assert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{SecretPath: "/app/nested/deep"}))- // CANNOT read secrets outside /app/assert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{SecretPath: "/other/path"}))assert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{SecretPath: "/"}))- // CANNOT read without path (empty doesn't match /app/**)assert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))}@@ -566,7 +486,6 @@ func TestGroupAdmin_UserInheritsFullAccess(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeUser, user.ID)ability := result.Permission.Ability- // User inherits admin permissions through groupassert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))@@ -589,83 +508,17 @@ func TestGroupViewer_UserInheritsReadOnly(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeUser, user.ID)ability := result.Permission.Ability- // User inherits viewer permissions through group (describeSecret + readValue, not combined "read")assert.True(t, gocasl.Can(ability, project.SecretActionDescribeSecret, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionReadValue, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))assert.True(t, gocasl.Can(ability, project.MemberActionRead, project.MemberSubject{}))- // Cannot writeassert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.ProjectActionDelete, project.ProjectSubject{}))}-func TestGroupCustomRole_UserInheritsCustomPermissions(t *testing.T) {- nodejs := stack.NodeJS()-- customRole := nodejs.CreateCustomProjectRole(t, proj.ID, "group-secrets-ro", "Group Secrets ReadOnly", []infra.Permission{- {- Subject: "secrets",- Action: []string{"read"},- },- {- Subject: "secret-folders",- Action: []string{"read"},- },- })-- group := nodejs.CreateGroup(t, "custom-role-group")- user := nodejs.InviteAndCreateUser(t, "[email protected]")- nodejs.AddUserToGroup(t, group.ID, user.Email)- nodejs.AddGroupToProject(t, proj.ID, group.ID, customRole.Slug)-- result := getProjectPermission(t, auth.ActorTypeUser, user.ID)- ability := result.Permission.Ability-- // CAN read secrets and folders through group's custom role- assert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))- assert.True(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))-- // CANNOT write secrets or folders- assert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))- assert.False(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))- assert.False(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{}))- assert.False(t, gocasl.Can(ability, project.SecretFolderActionCreate, project.SecretFolderSubject{}))-- // CANNOT do anything else- assert.False(t, gocasl.Can(ability, project.MemberActionRead, project.MemberSubject{}))- assert.False(t, gocasl.Can(ability, project.ProjectActionEdit, project.ProjectSubject{}))- assert.False(t, gocasl.Can(ability, project.IdentityActionRead, project.IdentitySubject{}))-- assert.True(t, result.HasRole(customRole.Slug))-}--func TestGroupNotMember_UserDenied(t *testing.T) {- nodejs := stack.NodeJS()-- // Create group and add to project, but user is NOT in the group- group := nodejs.CreateGroup(t, "exclusive-group")- nodejs.AddGroupToProject(t, proj.ID, group.ID, "admin")-- user := nodejs.InviteAndCreateUser(t, "[email protected]")-- ctx := context.Background()- svc := newPermissionService()-- _, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{- Actor: auth.ActorTypeUser,- ActorID: uuid.MustParse(user.ID),- ProjectID: proj.ID,- ActorAuthMethod: "",- ActorOrgID: uuid.MustParse(nodejs.OrgID()),- ActionProjectType: permission.ActionProjectTypeSecretManager,- })- require.Error(t, err)- assert.Contains(t, err.Error(), "not a member")-}-// ===========================// Additional privilege tests// ===========================@@ -673,7 +526,6 @@ func TestGroupNotMember_UserDenied(t *testing.T) {func TestIdentityAdditionalPrivilege_ExtendsRole(t *testing.T) {nodejs := stack.NodeJS()- // Give identity viewer role (read-only) then add additional privilege for secret creationidentity := nodejs.CreateIdentity(t, "addl-priv-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("viewer"))nodejs.CreateIdentityAdditionalPrivilege(t, identity.ID, proj.ID, []infra.Permission{@@ -686,123 +538,16 @@ func TestIdentityAdditionalPrivilege_ExtendsRole(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability- // Base viewer permissions still workassert.True(t, gocasl.Can(ability, project.SecretActionDescribeSecret, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionReadValue, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))- // Additional privilege grants createassert.True(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))- // Still cannot edit/delete (not in viewer or additional privilege)assert.False(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{}))}-func TestIdentityAdditionalPrivilege_WithConditions(t *testing.T) {- nodejs := stack.NodeJS()-- // Give identity no-access role, then add scoped additional privilege- identity := nodejs.CreateIdentity(t, "addl-priv-scoped-identity")- nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("no-access"))- nodejs.CreateIdentityAdditionalPrivilege(t, identity.ID, proj.ID, []infra.Permission{- {- Subject: "secrets",- Action: "read",- Conditions: map[string]any{- "environment": "dev",- },- },- }, nil)-- result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)- ability := result.Permission.Ability-- // CAN read secrets in dev via additional privilege- assert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{Environment: "dev"}))-- // CANNOT read in other environments- assert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{Environment: "production"}))- assert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))-- // CANNOT write even in dev- assert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{Environment: "dev"}))-}--func TestUserAdditionalPrivilege_ExtendsRole(t *testing.T) {- nodejs := stack.NodeJS()-- // Create project using user JWT so bootstrap user is automatically a member.- // This is needed because the user additional privilege API requires user JWT auth.- testProj := nodejs.CreateProject(t, "user-addl-priv-test")-- // Give user viewer role, then add additional privilege for secret edit- user := nodejs.InviteAndCreateUser(t, "[email protected]")- nodejs.AddUserToProject(t, testProj.ID, user.Email, []string{"viewer"})- nodejs.CreateUserAdditionalPrivilege(t, user.ID, testProj.ID, []infra.Permission{- {- Subject: "secrets",- Action: "edit",- },- })-- // Use testProj.ID instead of the shared proj.ID- svc := newPermissionService()- result, err := svc.GetProjectPermission(context.Background(), &permission.GetProjectPermissionArgs{- Actor: auth.ActorTypeUser,- ActorID: uuid.MustParse(user.ID),- ProjectID: testProj.ID,- ActorAuthMethod: "",- ActorOrgID: uuid.MustParse(nodejs.OrgID()),- ActionProjectType: permission.ActionProjectTypeSecretManager,- })- require.NoError(t, err)- ability := result.Permission.Ability-- // Base viewer permissions- assert.True(t, gocasl.Can(ability, project.SecretActionDescribeSecret, project.SecretSubject{}))- assert.True(t, gocasl.Can(ability, project.SecretActionReadValue, project.SecretSubject{}))-- // Additional privilege grants edit- assert.True(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))-- // Still cannot create/delete- assert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))- assert.False(t, gocasl.Can(ability, project.SecretActionDelete, project.SecretSubject{}))-}--func TestIdentityMultipleAdditionalPrivileges_Merge(t *testing.T) {- nodejs := stack.NodeJS()-- // Give identity no-access role, add two separate additional privileges- identity := nodejs.CreateIdentity(t, "multi-addl-priv-identity")- nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("no-access"))-- nodejs.CreateIdentityAdditionalPrivilege(t, identity.ID, proj.ID, []infra.Permission{- {- Subject: "secrets",- Action: "read",- },- }, nil)- nodejs.CreateIdentityAdditionalPrivilege(t, identity.ID, proj.ID, []infra.Permission{- {- Subject: "secret-folders",- Action: "read",- },- }, nil)-- result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)- ability := result.Permission.Ability-- // Both additional privileges are merged- assert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))- assert.True(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))-- // Nothing else- assert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))- assert.False(t, gocasl.Can(ability, project.MemberActionRead, project.MemberSubject{}))-}-// ===========================// Temporary role tests// ===========================@@ -811,7 +556,6 @@ func TestIdentityTemporaryRole_ActiveGrantsAccess(t *testing.T) {nodejs := stack.NodeJS()identity := nodejs.CreateIdentity(t, "temp-role-active-identity")- // API requires at least one permanent role; use no-access as the permanent basenodejs.AddIdentityToProject(t, proj.ID, identity.ID, []infra.RoleAssignment{{Role: "no-access",@@ -829,7 +573,6 @@ func TestIdentityTemporaryRole_ActiveGrantsAccess(t *testing.T) {result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability- // Active temporary admin role grants full accessassert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))assert.True(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))@@ -841,7 +584,6 @@ func TestIdentityTemporaryRole_ExpiredDeniesAccess(t *testing.T) {nodejs := stack.NodeJS()identity := nodejs.CreateIdentity(t, "temp-role-expired-identity")- // Permanent no-access + expired temporary admin (started 2h ago, range 1h)nodejs.AddIdentityToProject(t, proj.ID, identity.ID, []infra.RoleAssignment{{Role: "no-access",@@ -856,7 +598,6 @@ func TestIdentityTemporaryRole_ExpiredDeniesAccess(t *testing.T) {},})- // Identity is a project member but the only role is expired → no permissionsctx := context.Background()svc := newPermissionService()result, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{@@ -870,90 +611,8 @@ func TestIdentityTemporaryRole_ExpiredDeniesAccess(t *testing.T) {require.NoError(t, err)ability := result.Permission.Ability- // Expired temporary role grants nothingassert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))assert.False(t, gocasl.Can(ability, project.ProjectActionDelete, project.ProjectSubject{}))assert.False(t, gocasl.Can(ability, project.MemberActionRead, project.MemberSubject{}))}--func TestIdentityTemporaryRole_MixedWithPermanent(t *testing.T) {- nodejs := stack.NodeJS()-- identity := nodejs.CreateIdentity(t, "temp-role-mixed-identity")- // Permanent viewer + expired temporary admin- nodejs.AddIdentityToProject(t, proj.ID, identity.ID, []infra.RoleAssignment{- {- Role: "viewer",- IsTemporary: false,- },- {- Role: "admin",- IsTemporary: true,- TemporaryMode: "relative",- TemporaryRange: "1h",- TemporaryAccessStartTime: time.Now().Add(-2 * time.Hour).UTC().Format(time.RFC3339),- },- })-- result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)- ability := result.Permission.Ability-- // Permanent viewer permissions still work- assert.True(t, gocasl.Can(ability, project.SecretActionDescribeSecret, project.SecretSubject{}))- assert.True(t, gocasl.Can(ability, project.SecretActionReadValue, project.SecretSubject{}))- assert.True(t, gocasl.Can(ability, project.SecretFolderActionRead, project.SecretFolderSubject{}))-- // Expired admin does NOT contribute write permissions- assert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))- assert.False(t, gocasl.Can(ability, project.SecretActionEdit, project.SecretSubject{}))- assert.False(t, gocasl.Can(ability, project.ProjectActionDelete, project.ProjectSubject{}))-}--// ===========================-// Temporary additional privilege tests-// ===========================--func TestIdentityTemporaryAdditionalPrivilege_ActiveGrantsAccess(t *testing.T) {- nodejs := stack.NodeJS()-- identity := nodejs.CreateIdentity(t, "temp-addl-active-identity")- nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("no-access"))- nodejs.CreateIdentityAdditionalPrivilege(t, identity.ID, proj.ID, []infra.Permission{- {- Subject: "secrets",- Action: "read",- },- }, &infra.IdentityPrivilegeOpts{TemporaryRange: "1h", TemporaryAccessStartTime: time.Now().UTC().Format(time.RFC3339)})-- result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)- ability := result.Permission.Ability-- // Active temporary additional privilege grants read- assert.True(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))-- // But not write- assert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))-}--func TestIdentityTemporaryAdditionalPrivilege_ExpiredDeniesAccess(t *testing.T) {- nodejs := stack.NodeJS()-- identity := nodejs.CreateIdentity(t, "temp-addl-expired-identity")- nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("no-access"))- // Start 2h ago, range 1h → expired- nodejs.CreateIdentityAdditionalPrivilege(t, identity.ID, proj.ID, []infra.Permission{- {- Subject: "secrets",- Action: "read",- },- }, &infra.IdentityPrivilegeOpts{TemporaryRange: "1h", TemporaryAccessStartTime: time.Now().Add(-2 * time.Hour).UTC().Format(time.RFC3339)})-- result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)- ability := result.Permission.Ability-- // Expired temporary additional privilege grants nothing (base role is no-access)- assert.False(t, gocasl.Can(ability, project.SecretActionDescribeAndReadValue, project.SecretSubject{}))- assert.False(t, gocasl.Can(ability, project.SecretActionCreate, project.SecretSubject{}))- assert.False(t, gocasl.Can(ability, project.MemberActionRead, project.MemberSubject{}))-}diff --git a/backend-go/internal/server/api/platform/projects/projects_integration_test.go b/backend-go/tests/platform/projects/projects_test.gosimilarity index 89%rename from backend-go/internal/server/api/platform/projects/projects_integration_test.gorename to backend-go/tests/platform/projects/projects_test.goindex 0c14885178..4b1c1c92d8 100644--- a/backend-go/internal/server/api/platform/projects/projects_integration_test.go+++ b/backend-go/tests/platform/projects/projects_test.go@@ -15,8 +15,7 @@ import ("github.com/infisical/api/internal/server/api/platform/projects""github.com/infisical/api/internal/services/permission"- "github.com/infisical/api/internal/testutil"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")var stack *infra.Stack@@ -38,10 +37,10 @@ func newProjectsRouter(t *testing.T) http.Handler {t.Helper()ctx := t.Context()- permLib := permission.NewService(ctx, testutil.NopLogger(), &permission.Deps{DB: stack.DB()})+ permLib := permission.NewService(ctx, infra.NopLogger(), &permission.Deps{DB: stack.DB()})handler := projects.NewHandler(&projects.Deps{- Logger: testutil.NopLogger(),+ Logger: infra.NopLogger(),Permission: permLib,})diff --git a/backend-go/internal/ee/services/ratelimit/ratelimit_integration_test.go b/backend-go/tests/platform/ratelimit/ratelimit_test.gosimilarity index 96%rename from backend-go/internal/ee/services/ratelimit/ratelimit_integration_test.gorename to backend-go/tests/platform/ratelimit/ratelimit_test.goindex 9110fdae49..77003c2889 100644--- a/backend-go/internal/ee/services/ratelimit/ratelimit_integration_test.go+++ b/backend-go/tests/platform/ratelimit/ratelimit_test.go@@ -18,8 +18,7 @@ import ("github.com/infisical/api/internal/ee/services/license""github.com/infisical/api/internal/ee/services/ratelimit""github.com/infisical/api/internal/services/auth"- "github.com/infisical/api/internal/testutil"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")var stack *infra.Stack@@ -59,7 +58,7 @@ func (m *mockLicenseService) GetPlan(ctx context.Context, orgID string) (*licensfunc newTestService(t *testing.T, isCloud bool) *ratelimit.Service {t.Helper()- return ratelimit.NewService(context.Background(), testutil.NopLogger(), &ratelimit.Deps{+ return ratelimit.NewService(context.Background(), infra.NopLogger(), &ratelimit.Deps{Redis: stack.Redis().Client(),LicenseSvc: &mockLicenseService{},IsCloud: isCloud,@@ -78,7 +77,7 @@ func TestRedisCounter_IncrementAndGet_BasicFlow(t *testing.T) {counter := ratelimit.NewRedisCounter(&ratelimit.RedisCounterConfig{Client: client,PrefixKey: "test-basic-" + t.Name(),- Logger: testutil.NopLogger(),+ Logger: infra.NopLogger(),})counter.Config(100, time.Minute)@@ -105,7 +104,7 @@ func TestRedisCounter_Get_ReturnsZeroForNewKey(t *testing.T) {counter := ratelimit.NewRedisCounter(&ratelimit.RedisCounterConfig{Client: client,PrefixKey: "test-zero-" + t.Name(),- Logger: testutil.NopLogger(),+ Logger: infra.NopLogger(),})counter.Config(100, time.Minute)@@ -126,7 +125,7 @@ func TestRedisCounter_SeparateWindows_HaveIndependentCounts(t *testing.T) {counter := ratelimit.NewRedisCounter(&ratelimit.RedisCounterConfig{Client: client,PrefixKey: "test-windows-" + t.Name(),- Logger: testutil.NopLogger(),+ Logger: infra.NopLogger(),})counter.Config(100, time.Minute)@@ -157,7 +156,7 @@ func TestRedisCounter_DifferentKeys_HaveIndependentCounts(t *testing.T) {counter := ratelimit.NewRedisCounter(&ratelimit.RedisCounterConfig{Client: client,PrefixKey: "test-keys-" + t.Name(),- Logger: testutil.NopLogger(),+ Logger: infra.NopLogger(),})counter.Config(100, time.Minute)@@ -188,7 +187,7 @@ func TestRedisCounter_IncrementBy_IncrementsCorrectAmount(t *testing.T) {counter := ratelimit.NewRedisCounter(&ratelimit.RedisCounterConfig{Client: client,PrefixKey: "test-incrby-" + t.Name(),- Logger: testutil.NopLogger(),+ Logger: infra.NopLogger(),})counter.Config(100, time.Minute)@@ -339,7 +338,7 @@ func TestRateLimitMiddleware_UsesDynamicLimitFromPlan(t *testing.T) {},}- svc := ratelimit.NewService(context.Background(), testutil.NopLogger(), &ratelimit.Deps{+ svc := ratelimit.NewService(context.Background(), infra.NopLogger(), &ratelimit.Deps{Redis: stack.Redis().Client(),LicenseSvc: licenseSvc,IsCloud: true,diff --git a/backend-go/internal/server/api/secretmanager/secret/get_secret_by_name_integration_test.go b/backend-go/tests/secretmanager/secrets/get_secret_by_name_integration_test.gosimilarity index 99%rename from backend-go/internal/server/api/secretmanager/secret/get_secret_by_name_integration_test.gorename to backend-go/tests/secretmanager/secrets/get_secret_by_name_integration_test.goindex 0195c03d2d..e18ce6a9a4 100644--- a/backend-go/internal/server/api/secretmanager/secret/get_secret_by_name_integration_test.go+++ b/backend-go/tests/secretmanager/secrets/get_secret_by_name_integration_test.go@@ -1,6 +1,6 @@//go:build integration-package secret_test+package secrets_testimport ("encoding/json"@@ -16,7 +16,7 @@ import ("github.com/infisical/api/internal/server/api/secretmanager/secret""github.com/infisical/api/internal/server/api/shared""github.com/infisical/api/internal/services/auth"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")// httpGetSecretV4 makes a direct HTTP GET request to /api/v4/secrets/{secretName}diff --git a/backend-go/internal/server/api/secretmanager/secret/get_secret_by_name_permission_integration_test.go b/backend-go/tests/secretmanager/secrets/get_secret_by_name_permission_integration_test.gosimilarity index 98%rename from backend-go/internal/server/api/secretmanager/secret/get_secret_by_name_permission_integration_test.gorename to backend-go/tests/secretmanager/secrets/get_secret_by_name_permission_integration_test.goindex f42e8264ba..56de3fd012 100644--- a/backend-go/internal/server/api/secretmanager/secret/get_secret_by_name_permission_integration_test.go+++ b/backend-go/tests/secretmanager/secrets/get_secret_by_name_permission_integration_test.go@@ -1,6 +1,6 @@//go:build integration-package secret_test+package secrets_testimport ("testing"@@ -9,7 +9,7 @@ import ("github.com/stretchr/testify/require""github.com/infisical/api/internal/services/auth"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")// =============================================================================diff --git a/backend-go/internal/server/api/secretmanager/secret/list_secrets_integration_test.go b/backend-go/tests/secretmanager/secrets/list_secrets_integration_test.gosimilarity index 99%rename from backend-go/internal/server/api/secretmanager/secret/list_secrets_integration_test.gorename to backend-go/tests/secretmanager/secrets/list_secrets_integration_test.goindex 84c842fe8b..ea71d22507 100644--- a/backend-go/internal/server/api/secretmanager/secret/list_secrets_integration_test.go+++ b/backend-go/tests/secretmanager/secrets/list_secrets_integration_test.go@@ -1,6 +1,6 @@//go:build integration-package secret_test+package secrets_testimport ("encoding/json"@@ -16,7 +16,7 @@ import ("github.com/infisical/api/internal/server/api/secretmanager/secret""github.com/infisical/api/internal/server/api/shared""github.com/infisical/api/internal/services/auth"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")// httpListSecretsV4 makes a direct HTTP GET request to /api/v4/secretsdiff --git a/backend-go/internal/server/api/secretmanager/secret/list_secrets_permission_integration_test.go b/backend-go/tests/secretmanager/secrets/list_secrets_permission_integration_test.gosimilarity index 99%rename from backend-go/internal/server/api/secretmanager/secret/list_secrets_permission_integration_test.gorename to backend-go/tests/secretmanager/secrets/list_secrets_permission_integration_test.goindex c88e1fd1e6..eb9d4def69 100644--- a/backend-go/internal/server/api/secretmanager/secret/list_secrets_permission_integration_test.go+++ b/backend-go/tests/secretmanager/secrets/list_secrets_permission_integration_test.go@@ -1,6 +1,6 @@//go:build integration-package secret_test+package secrets_testimport ("testing"@@ -10,7 +10,7 @@ import ("github.com/stretchr/testify/require""github.com/infisical/api/internal/services/auth"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")// =============================================================================diff --git a/backend-go/internal/server/api/secretmanager/secret/main_test.go b/backend-go/tests/secretmanager/secrets/main_test.gosimilarity index 92%rename from backend-go/internal/server/api/secretmanager/secret/main_test.gorename to backend-go/tests/secretmanager/secrets/main_test.goindex 01e71c4363..9a2492a9ba 100644--- a/backend-go/internal/server/api/secretmanager/secret/main_test.go+++ b/backend-go/tests/secretmanager/secrets/main_test.go@@ -1,6 +1,6 @@//go:build integration-package secret_test+package secrets_testimport ("encoding/json"@@ -28,8 +28,7 @@ import (secretSvc "github.com/infisical/api/internal/services/secretmanager/secret""github.com/infisical/api/internal/services/secretmanager/secretfolder""github.com/infisical/api/internal/services/secretmanager/secretimport"- "github.com/infisical/api/internal/testutil"- "github.com/infisical/api/internal/testutil/infra"+ "github.com/infisical/api/tests/infra")var (@@ -57,12 +56,12 @@ func newSecretsHandler(t *testing.T) *secret.Handler {ctx := t.Context()- permSvc := permission.NewService(ctx, testutil.NopLogger(), &permission.Deps{DB: stack.DB()})+ permSvc := permission.NewService(ctx, infra.NopLogger(), &permission.Deps{DB: stack.DB()})redisClient := stack.Redis().Client()t.Cleanup(func() { redisClient.Close() })- kmsSvc, err := kms.NewService(ctx, testutil.NopLogger(), &kms.Deps{+ kmsSvc, err := kms.NewService(ctx, infra.NopLogger(), &kms.Deps{DB: stack.DB(),HSM: nil,ExternalKms: nil,@@ -73,16 +72,16 @@ func newSecretsHandler(t *testing.T) *secret.Handler {err = kmsSvc.Start(ctx, false)require.NoError(t, err)- projectSvc := project.NewService(ctx, testutil.NopLogger(), &project.Deps{DB: stack.DB()})+ projectSvc := project.NewService(ctx, infra.NopLogger(), &project.Deps{DB: stack.DB()})- queueSvc := queue.NewService(ctx, testutil.NopLogger(), redisClient)+ queueSvc := queue.NewService(ctx, infra.NopLogger(), redisClient)- auditLogSvc := auditlog.NewService(ctx, testutil.NopLogger(), &auditlog.Deps{Queue: queueSvc, Config: stack.Config()})+ auditLogSvc := auditlog.NewService(ctx, infra.NopLogger(), &auditlog.Deps{Queue: queueSvc, Config: stack.Config()})- secretFolderSvc := secretfolder.NewService(ctx, testutil.NopLogger(), &secretfolder.Deps{DB: stack.DB()})- secretImportSvc := secretimport.NewService(ctx, testutil.NopLogger(), &secretimport.Deps{DB: stack.DB()})+ secretFolderSvc := secretfolder.NewService(ctx, infra.NopLogger(), &secretfolder.Deps{DB: stack.DB()})+ secretImportSvc := secretimport.NewService(ctx, infra.NopLogger(), &secretimport.Deps{DB: stack.DB()})- secretsSvc := secretSvc.NewService(ctx, testutil.NopLogger(), &secretSvc.Deps{+ secretsSvc := secretSvc.NewService(ctx, infra.NopLogger(), &secretSvc.Deps{DB: stack.DB(),SecretFolderService: secretFolderSvc,SecretImportService: secretImportSvc,@@ -90,7 +89,7 @@ func newSecretsHandler(t *testing.T) *secret.Handler {})return secret.NewHandler(&secret.Deps{- Logger: testutil.NopLogger(),+ Logger: infra.NopLogger(),Permission: permSvc,Project: projectSvc,AuditLog: auditLogSvc,@@ -394,7 +393,7 @@ func newTestServer(t *testing.T, handler *secret.Handler, actorType auth.ActorTyrouter := secret.NewRouter(handler,secret.WithMiddleware(testAuthMiddleware(actorType, actorID, orgID)),- secret.WithErrorHandler(shared.NewErrorHandler(testutil.NopLogger())),+ secret.WithErrorHandler(shared.NewErrorHandler(infra.NopLogger())),)return httptest.NewServer(router)