Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

test(e2e): cover rotation credential grants and moves under approval policies, and give sync import its own test

varonix07be498640d9
diff --git a/tests/suites/secretmanager/rotations/move_test.go b/tests/suites/secretmanager/rotations/move_test.go
index c677cbfc64..f15a133190 100644
--- a/tests/suites/secretmanager/rotations/move_test.go
+++ b/tests/suites/secretmanager/rotations/move_test.go
@@ -4,9 +4,11 @@ import (
"net/http"
"testing"
+ "github.com/Infisical/infisical/tests/clients/api"
"github.com/Infisical/infisical/tests/fixture"
"github.com/Infisical/infisical/tests/fixture/secretmanager"
"github.com/Infisical/infisical/tests/internal/apierr"
+ "github.com/Infisical/infisical/tests/internal/spec"
"github.com/stretchr/testify/require"
)
@@ -32,6 +34,35 @@ func TestSecretRotation_Move(t *testing.T) {
require.Empty(t, e.secretsAt(t, "/"))
})
+ t.Run("should move the mapped secrets without an approval request when both folders have an approval policy", func(t *testing.T) {
+ t.Parallel()
+ spec.Why(t, `A rotation writes its mapped secrets itself, so moving it moves them directly
+ and opens no secret change request, even for an actor with no secret permissions.`)
+
+ // Setup
+ e := setup(t)
+ secretmanager.CreateFolder(t, e.proj, "dev", "/services")
+ r := e.newRotation(t)
+ published := e.published(t, "/")
+ for _, path := range []string{"/", "/services"} {
+ secretmanager.CreateApprovalPolicy(t, e.proj, secretmanager.Location{Env: "dev", Path: path}, e.tn.Admin)
+ }
+ e.proj.NewRole(t, "rotation-mover", fixture.Permission{
+ Subject: "secret-rotation",
+ Action: []string{"read", "create", "delete"},
+ })
+ mover := e.proj.NewMachineIdentity(t, fixture.WithRoles("rotation-mover"))
+
+ // Action
+ res := r.move(t, mover.API, "/services")
+
+ // Assert
+ requireStatus(t, http.StatusOK, res.StatusCode(), res.Body)
+ require.Equal(t, published, e.published(t, "/services"))
+ require.Empty(t, e.secretsAt(t, "/"))
+ require.Zero(t, e.openApprovalRequests(t))
+ })
+
t.Run("should refuse a move to the folder the rotation is already in", func(t *testing.T) {
t.Parallel()
@@ -92,3 +123,16 @@ func TestSecretRotation_Move(t *testing.T) {
require.Empty(t, e.secretsAt(t, "/services"))
})
}
+
+// openApprovalRequests is the number of secret change requests waiting in the project.
+func (e env) openApprovalRequests(t *testing.T) int {
+ t.Helper()
+ res, err := e.tn.Admin.API.GetSecretApprovalRequestCountWithResponse(t.Context(),
+ &api.GetSecretApprovalRequestCountParams{ProjectId: e.proj.ID})
+ require.NoError(t, err)
+ require.NotNilf(t, res.JSON200, "counting approval requests returned %d: %s", res.StatusCode(), apierr.Body(res.Body))
+ if res.JSON200.Approvals.Open == nil {
+ return 0
+ }
+ return int(*res.JSON200.Approvals.Open)
+}
diff --git a/tests/suites/secretmanager/rotations/permission_test.go b/tests/suites/secretmanager/rotations/permission_test.go
index 3371ffedaf..dab2661d33 100644
--- a/tests/suites/secretmanager/rotations/permission_test.go
+++ b/tests/suites/secretmanager/rotations/permission_test.go
@@ -8,6 +8,7 @@ import (
"github.com/Infisical/infisical/tests/fakes/license"
"github.com/Infisical/infisical/tests/fixture"
"github.com/Infisical/infisical/tests/internal/apierr"
+ "github.com/Infisical/infisical/tests/internal/spec"
"github.com/stretchr/testify/require"
)
@@ -33,6 +34,53 @@ func TestSecretRotation_Permission(t *testing.T) {
requireStatus(t, http.StatusForbidden, checked.StatusCode(), checked.Body)
})
}
+
+ t.Run("should return generated credentials and a credential check to a role granted only that action", func(t *testing.T) {
+ t.Parallel()
+ spec.Why(t, `New projects refuse additional privileges, so a custom role grants the one
+ action. Without this, the refusals above would also pass if the routes refused everyone.`)
+
+ // Setup
+ e := setup(t)
+ e.proj.NewRole(t, "credentials-reader", fixture.Permission{
+ Subject: "secret-rotation",
+ Action: []string{"read-generated-credentials"},
+ })
+ actor := e.proj.NewMachineIdentity(t, fixture.WithRoles("credentials-reader"))
+ r := e.newRotation(t)
+
+ // Action
+ generated := r.generated(t, actor.API)
+ checked := r.check(t, actor.API)
+
+ // Assert
+ requireStatus(t, http.StatusOK, generated.StatusCode(), generated.Body)
+ require.Contains(t, string(generated.Body), e.published(t, "/").password)
+ requireStatus(t, http.StatusNoContent, checked.StatusCode(), checked.Body)
+ })
+
+ t.Run("should refuse generated credentials and a credential check when the role grants the action only for another folder", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ e := setup(t)
+ e.proj.NewRole(t, "credentials-reader", fixture.Permission{
+ Subject: "secret-rotation",
+ Action: []string{"read-generated-credentials"},
+ Conditions: map[string]any{"secretPath": map[string]any{"$eq": "/elsewhere"}},
+ })
+ actor := e.proj.NewMachineIdentity(t, fixture.WithRoles("credentials-reader"))
+ r := e.newRotation(t)
+
+ // Action
+ generated := r.generated(t, actor.API)
+ checked := r.check(t, actor.API)
+
+ // Assert
+ requireStatus(t, http.StatusForbidden, generated.StatusCode(), generated.Body)
+ require.NotContains(t, string(generated.Body), e.published(t, "/").password)
+ requireStatus(t, http.StatusForbidden, checked.StatusCode(), checked.Body)
+ })
}
func TestSecretRotation_License(t *testing.T) {
diff --git a/tests/suites/secretmanager/syncs/delete_test.go b/tests/suites/secretmanager/syncs/delete_test.go
index c43921ee5e..903dfcece7 100644
--- a/tests/suites/secretmanager/syncs/delete_test.go
+++ b/tests/suites/secretmanager/syncs/delete_test.go
@@ -6,7 +6,6 @@ import (
"strings"
"testing"
- "github.com/Infisical/infisical/tests/clients/api"
"github.com/Infisical/infisical/tests/fakes/github"
"github.com/Infisical/infisical/tests/fixture/secretmanager"
"github.com/Infisical/infisical/tests/infra/fakenet"
@@ -121,22 +120,4 @@ func TestSecretSync_Delete(t *testing.T) {
require.Equal(t, "not ours", dest["UNMANAGED"].Value)
require.Equal(t, "api-value", secretmanager.GetSecret(t, proj, "dev", "API_KEY").Value)
})
-
- t.Run("should refuse an import naming GitHub's limitation and start no job", func(t *testing.T) {
- t.Parallel()
-
- // Setup
- proj, conn, _ := setup(t)
- s := newSync(t, proj, conn, repoScope("acme", "app"))
-
- // Action
- res, err := proj.Tenant().Admin.API.ImportGitHubSecretSyncSecretsWithResponse(t.Context(), s.ID,
- &api.ImportGitHubSecretSyncSecretsParams{ImportBehavior: api.ImportGitHubSecretSyncSecretsParamsImportBehaviorPrioritizeSource})
-
- // Assert
- require.NoError(t, err)
- require.Equal(t, http.StatusBadRequest, res.StatusCode())
- require.Equal(t, "GitHub does not support importing secrets.", message(res.Body))
- require.Nil(t, s.get(t).JSON200.SecretSync.ImportStatus)
- })
}
diff --git a/tests/suites/secretmanager/syncs/import_test.go b/tests/suites/secretmanager/syncs/import_test.go
new file mode 100644
index 0000000000..f2cca67f7d
--- /dev/null
+++ b/tests/suites/secretmanager/syncs/import_test.go
@@ -0,0 +1,31 @@
+package syncs_test
+
+import (
+ "net/http"
+ "testing"
+
+ "github.com/Infisical/infisical/tests/clients/api"
+ "github.com/stretchr/testify/require"
+)
+
+func TestSecretSync_Import(t *testing.T) {
+ t.Parallel()
+
+ t.Run("should refuse an import naming GitHub's limitation and start no job", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ proj, conn, _ := setup(t)
+ s := newSync(t, proj, conn, repoScope("acme", "app"))
+
+ // Action
+ res, err := proj.Tenant().Admin.API.ImportGitHubSecretSyncSecretsWithResponse(t.Context(), s.ID,
+ &api.ImportGitHubSecretSyncSecretsParams{ImportBehavior: api.ImportGitHubSecretSyncSecretsParamsImportBehaviorPrioritizeSource})
+
+ // Assert
+ require.NoError(t, err)
+ require.Equal(t, http.StatusBadRequest, res.StatusCode())
+ require.Equal(t, "GitHub does not support importing secrets.", message(res.Body))
+ require.Nil(t, s.get(t).JSON200.SecretSync.ImportStatus)
+ })
+}