Skip to content

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

feat: updated test md and secret reference test

=c23feb8e66a6
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts
index 57d4a0727a..6247b38c7e 100644
--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts
+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts
@@ -2939,10 +2939,18 @@ export const secretV2BridgeServiceFactory = ({
}
});
const secretsToDeleteSet = new Set(secretsToDelete.map((el) => el.key));
- if (secretsToDeleteSet.size !== inputSecrets.length)
+ const requestedKeys = inputSecrets.map((el) => el.secretKey);
+ const missingKeys = [...new Set(requestedKeys.filter((key) => !secretsToDeleteSet.has(key)))];
+ if (missingKeys.length)
throw new NotFoundError({
- message: `One or more secrets does not exist: ${secretsToDelete.map((el) => el.key).join(", ")}`
+ message: `One or more secrets does not exist: ${missingKeys.join(", ")}`
});
+ if (secretsToDeleteSet.size !== requestedKeys.length) {
+ const repeatedKeys = [...new Set(requestedKeys.filter((key, index) => requestedKeys.indexOf(key) !== index))];
+ throw new BadRequestError({
+ message: `Each secret can only be deleted once per request: ${repeatedKeys.join(", ")}`
+ });
+ }
secretsToDelete.forEach((el) => {
ForbiddenError.from(permission).throwUnlessCan(
ProjectPermissionSecretActions.Delete,
diff --git a/tests/docs/client.md b/tests/docs/client.md
index 5cf3b72365..6305befc9d 100644
--- a/tests/docs/client.md
+++ b/tests/docs/client.md
@@ -25,6 +25,8 @@ the harness image with `NODE_ENV=development`.
not inherit `MarshalJSON`, so it serialises as `{}`. Build the union, `json.Marshal` it,
and post with `...WithBodyWithResponse`. A union field inside an ordinary struct is
fine.
-- **Union responses.** `createSecretV4` returns a secret or an approval request. Unwrap
- with `AsCreateSecretV4200JSONResponseBody0()` and fail on the other branch, so an
- approval request never reads as success.
+- **Union responses.** A response that can take more than one shape is generated as a
+ union with one `As…N()` method per branch. Those methods only `json.Unmarshal`, so
+ every one of them succeeds whichever branch the server sent, and the wrong one hands
+ back zero values instead of an error. After unwrapping, require a field that only the
+ expected branch carries before trusting the result.
diff --git a/tests/suites/secretmanager/secrets/batch_test.go b/tests/suites/secretmanager/secrets/batch_test.go
index 800852e9df..c22a050293 100644
--- a/tests/suites/secretmanager/secrets/batch_test.go
+++ b/tests/suites/secretmanager/secrets/batch_test.go
@@ -197,8 +197,30 @@ func TestSecret_Batch(t *testing.T) {
// Assert
require.NoError(t, err)
- // Status only: the message names the keys that do exist rather than the missing one.
require.Equal(t, http.StatusNotFound, res.StatusCode())
+ require.Equal(t, "One or more secrets does not exist: MISSING", res.JSON404.Message)
require.Equal(t, map[string]string{"A": "value"}, valuesOf(t, proj))
})
+
+ t.Run("should refuse the whole delete and keep every secret when one name is listed twice", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ tn := h.NewTenant(t)
+ proj := fixture.NewProject(t, tn, fixture.WithProjectType("secret-manager"))
+ secretmanager.CreateSecret(t, proj, "dev", "A", "value")
+ secretmanager.CreateSecret(t, proj, "dev", "B", "value")
+ body := api.DeleteManySecretsV4JSONRequestBody{ProjectId: proj.ID, Environment: "dev"}
+ body.Secrets = slices.Grow(body.Secrets, 3)[:3]
+ body.Secrets[0].SecretKey, body.Secrets[1].SecretKey, body.Secrets[2].SecretKey = "A", "B", "A"
+
+ // Action
+ res, err := tn.Admin.API.DeleteManySecretsV4WithResponse(t.Context(), body)
+
+ // Assert
+ require.NoError(t, err)
+ require.Equal(t, http.StatusBadRequest, res.StatusCode())
+ require.Equal(t, "Each secret can only be deleted once per request: A", res.JSON400.Message)
+ require.Equal(t, map[string]string{"A": "value", "B": "value"}, valuesOf(t, proj))
+ })
}
diff --git a/tests/suites/secretmanager/secrets/reference_test.go b/tests/suites/secretmanager/secrets/reference_test.go
index 80cbfbcc9f..d29ef056a8 100644
--- a/tests/suites/secretmanager/secrets/reference_test.go
+++ b/tests/suites/secretmanager/secrets/reference_test.go
@@ -11,6 +11,7 @@ import (
"github.com/Infisical/infisical/tests/fixture/secretmanager"
"github.com/Infisical/infisical/tests/harness"
"github.com/Infisical/infisical/tests/internal/apierr"
+ "github.com/Infisical/infisical/tests/internal/wait"
"github.com/stretchr/testify/require"
)
@@ -202,6 +203,50 @@ func TestSecretReference_Expand(t *testing.T) {
require.Equal(t, "hello world", imported["GREETING"])
})
+ t.Run("should expand local and nested references inside a replicated import once it has replicated", func(t *testing.T) {
+ t.Parallel()
+
+ // Setup
+ tn := h.NewTenant(t)
+ proj := fixture.NewProject(t, tn, fixture.WithProjectType("secret-manager"))
+ secretmanager.CreateFolder(t, proj, "prod", "/deep/nested")
+ secretmanager.CreateSecret(t, proj, "prod", "DEEP_KEY", "testing", secretmanager.WithPath("/deep"))
+ secretmanager.CreateSecret(t, proj, "prod", "NESTED_KEY", "reference", secretmanager.WithPath("/deep/nested"))
+ secretmanager.CreateSecret(t, proj, "prod", "COMBINED", "secret ${NESTED_KEY} ${prod.deep.DEEP_KEY}",
+ secretmanager.WithPath("/deep/nested"))
+
+ // Action
+ imp, err := tn.Admin.API.CreateSecretImportWithResponse(t.Context(), api.CreateSecretImportJSONRequestBody{
+ ProjectId: proj.ID,
+ Environment: "dev",
+ IsReplication: new(true),
+ Import: struct {
+ Environment string `json:"environment"`
+ Path string `json:"path"`
+ SourceProjectId *string `json:"sourceProjectId,omitempty"`
+ }{Environment: "prod", Path: "/deep/nested"},
+ })
+ require.NoError(t, err)
+ require.NotNilf(t, imp.JSON200, "creating the import returned %d: %s", imp.StatusCode(), apierr.Body(imp.Body))
+
+ // Assert
+ var imported map[string]string
+ wait.Until(t, "the replicated import to carry the expanded secret", func() bool {
+ res, err := tn.Admin.API.ListSecretsV4WithResponse(t.Context(), &api.ListSecretsV4Params{
+ ProjectId: &proj.ID, Environment: new("dev"),
+ })
+ if err != nil || res.JSON200 == nil || res.JSON200.Imports == nil || len(*res.JSON200.Imports) == 0 {
+ return false
+ }
+ imported = map[string]string{}
+ for _, s := range (*res.JSON200.Imports)[0].Secrets {
+ imported[s.SecretKey] = s.SecretValue
+ }
+ return imported["COMBINED"] != ""
+ })
+ require.Equal(t, "secret reference testing", imported["COMBINED"])
+ })
+
t.Run("should resolve to the actor's own override of the referenced secret when overrides are included", func(t *testing.T) {
t.Parallel()