Skip to content

Commit

Permalink
fix: don't attempt to login during a --dryRun (#1037)
Browse files Browse the repository at this point in the history
* fix: don't attempt to login during a --dryRun

* Create wild-seas-breathe.md

* chore: update test to explicitly set CLOUDFLARE_ACCOUNT_ID to an empty string
  • Loading branch information
rozenmd authored and JacobMGEvans committed May 17, 2022
1 parent 95852c3 commit 9518906
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-dolphins-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: added `trim()` to secretValue being sent in PUT request
5 changes: 5 additions & 0 deletions .changeset/wild-seas-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: don't attempt to login during a --dryRun
1 change: 1 addition & 0 deletions packages/wrangler/src/__tests__/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4677,6 +4677,7 @@ addEventListener('fetch', event => {});`
migrations: [{ tag: "v1", new_classes: ["SomeClass"] }],
});
writeWorkerSource();
process.env.CLOUDFLARE_ACCOUNT_ID = "";
await runWrangler("publish index.js --dry-run");
expect(std).toMatchInlineSnapshot(`
Object {
Expand Down
15 changes: 15 additions & 0 deletions packages/wrangler/src/__tests__/secret.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ describe("wrangler secret", () => {
);
}

test("should trim input ", async () => {
mockPrompt({
text: "Enter a secret value:",
type: "password",
result: ` hunter2 `,
});

mockPutRequest({ name: `secret-name`, text: `hunter2` });
await runWrangler("secret put secret-name --name script-name");
expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating the secret for script script-name
✨ Success! Uploaded secret secret-name"
`);
});

describe("interactive", () => {
useMockStdin({ isTTY: true });

Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ export async function main(argv: string[]): Promise<void> {
);
}

const accountId = await requireAuth(config);
const accountId = args.dryRun ? undefined : await requireAuth(config);

const assetPaths = getAssetPaths(
config,
Expand Down Expand Up @@ -1740,7 +1740,7 @@ export async function main(argv: string[]): Promise<void> {
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: args.key,
text: secretValue,
text: secretValue.trim(),
type: "secret_text",
}),
});
Expand Down
3 changes: 2 additions & 1 deletion packages/wrangler/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { CfWorkerInit } from "./worker";

type Props = {
config: Config;
accountId: string;
accountId: string | undefined;
entry: Entry;
rules: Config["rules"];
name: string | undefined;
Expand Down Expand Up @@ -325,6 +325,7 @@ export default async function publish(props: Props): Promise<void> {
logger.log(`--dry-run: exiting now.`);
return;
}
assert(accountId, "Missing accountId");

const uploadMs = Date.now() - start;
const deployments: Promise<string[]>[] = [];
Expand Down
4 changes: 3 additions & 1 deletion packages/wrangler/src/sites.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from "node:assert";
import { readdir, readFile, stat } from "node:fs/promises";
import * as path from "node:path";
import ignore from "ignore";
Expand Down Expand Up @@ -103,7 +104,7 @@ async function createKVNamespaceIfNotAlreadyExisting(
* asset in the KV namespace.
*/
export async function syncAssets(
accountId: string,
accountId: string | undefined,
scriptName: string,
siteAssets: AssetPaths | undefined,
preview: boolean,
Expand All @@ -120,6 +121,7 @@ export async function syncAssets(
logger.log("(Note: doing a dry run, not uploading or deleting anything.)");
return { manifest: undefined, namespace: undefined };
}
assert(accountId, "Missing accountId");

const title = `__${scriptName}-workers_sites_assets${
preview ? "_preview" : ""
Expand Down

0 comments on commit 9518906

Please sign in to comment.