Skip to content

Commit

Permalink
[wrangler] Allow empty strings in secret:bulk (#4860)
Browse files Browse the repository at this point in the history
* test: add failing test for empty string secrets

* fix: check existence in list with undefined comparison

* docs: add changeset

* fix: remove leftover not
  • Loading branch information
Sibirius authored Jan 30, 2024
1 parent f2ca5e2 commit b92e5ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/eleven-carrots-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: allow empty strings in secret:bulk upload

Previously, the `secret:bulk` command would fail if any of the secrets in the secret.json file were empty strings and they already existed remotely.
6 changes: 5 additions & 1 deletion packages/wrangler/src/__tests__/secret.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ describe("wrangler secret", () => {
JSON.stringify({
"secret-name-2": "secret_text",
"secret-name-3": "secret_text",
"secret-name-4": "",
})
);

Expand All @@ -761,6 +762,7 @@ describe("wrangler secret", () => {
},
{ type: "secret_text", name: "secret-name-1" },
{ type: "secret_text", name: "secret-name-2" },
{ type: "secret_text", name: "secret-name-4" },
],
})
)
Expand Down Expand Up @@ -795,6 +797,7 @@ describe("wrangler secret", () => {
name: "secret-name-3",
text: "secret_text",
},
{ type: "secret_text", name: "secret-name-4", text: "" },
],
});
expect(parsedSettings).not.toHaveProperty(["bindings", 0, "text"]);
Expand All @@ -811,9 +814,10 @@ describe("wrangler secret", () => {
"🌀 Creating the secrets for the Worker \\"script-name\\"
✨ Successfully created secret for key: secret-name-2
✨ Successfully created secret for key: secret-name-3
✨ Successfully created secret for key: secret-name-4
Finished processing secrets JSON file:
2 secrets successfully uploaded"
3 secrets successfully uploaded"
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/wrangler/src/secret/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ export const secretBulkHandler = async (secretBulkArgs: SecretBulkArgs) => {
.filter((binding) => {
// secrets that currently exist for the worker but are not provided for bulk update
// are inherited over with other binding types
return binding.type !== "secret_text" || !content[binding.name];
return (
binding.type !== "secret_text" || content[binding.name] === undefined
);
})
.map((binding) => ({ type: binding.type, name: binding.name }));
// secrets to upload are provided as bindings in their full form
Expand Down

0 comments on commit b92e5ac

Please sign in to comment.