Skip to content

Commit 8e521b3

Browse files
WalshyDevemily-shen
authored andcommitted
Disable warnings for invalid config in wrangler login & logout
1 parent 68a2a84 commit 8e521b3

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
chore: disable wrangler.toml warnings when doing `wrangler login` & `wrangler logout`

packages/wrangler/src/__tests__/logout.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { mockConsoleMethods } from "./helpers/mock-console";
55
import { msw } from "./helpers/msw";
66
import { runInTempDir } from "./helpers/run-in-tmp";
77
import { runWrangler } from "./helpers/run-wrangler";
8+
import { writeWranglerToml } from "./helpers/write-wrangler-toml";
89

910
describe("logout", () => {
1011
runInTempDir();
@@ -50,4 +51,34 @@ describe("logout", () => {
5051
expect(fs.existsSync(config)).toBeFalsy();
5152
expect(counter).toBe(1);
5253
});
54+
55+
it("should not warn on invalid wrangler.toml when logging out", async () => {
56+
writeAuthConfigFile({
57+
oauth_token: "some-oauth-tok",
58+
refresh_token: "some-refresh-tok",
59+
});
60+
const config = getAuthConfigFilePath();
61+
62+
msw.use(
63+
http.post(
64+
"*/oauth2/revoke",
65+
async () => {
66+
return HttpResponse.text("");
67+
},
68+
{ once: true }
69+
)
70+
);
71+
72+
expect(fs.existsSync(config)).toBeTruthy();
73+
74+
// @ts-expect-error - intentionally invalid
75+
writeWranglerToml({ invalid: true });
76+
77+
await runWrangler("logout");
78+
79+
expect(std.out).toMatchInlineSnapshot(`"Successfully logged out."`);
80+
expect(std.warn).toMatchInlineSnapshot(`""`);
81+
expect(std.err).toMatchInlineSnapshot(`""`);
82+
expect(fs.existsSync(config)).toBeFalsy();
83+
});
5384
});

packages/wrangler/src/__tests__/user.test.ts

+44
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { normalizeString } from "./helpers/normalize";
2424
import { runInTempDir } from "./helpers/run-in-tmp";
2525
import { runWrangler } from "./helpers/run-wrangler";
26+
import { writeWranglerToml } from "./helpers/write-wrangler-toml";
2627
import type { Config } from "../config";
2728
import type { UserAuthConfig } from "../user";
2829
import type { MockInstance } from "vitest";
@@ -179,4 +180,47 @@ describe("User", () => {
179180
normalizeString(`${getGlobalWranglerConfigPath()}/config/staging.toml`)
180181
);
181182
});
183+
184+
it("should not warn on invalid wrangler.toml when logging in", async () => {
185+
mockOAuthServerCallback("success");
186+
187+
let counter = 0;
188+
msw.use(
189+
http.post(
190+
"*/oauth2/token",
191+
async () => {
192+
counter += 1;
193+
194+
return HttpResponse.json({
195+
access_token: "test-access-token",
196+
expires_in: 100000,
197+
refresh_token: "test-refresh-token",
198+
scope: "account:read",
199+
});
200+
},
201+
{ once: true }
202+
)
203+
);
204+
205+
// @ts-expect-error - intentionally invalid
206+
writeWranglerToml({ invalid: true });
207+
208+
await runWrangler("login");
209+
210+
expect(counter).toBe(1);
211+
expect(std.out).toMatchInlineSnapshot(`
212+
"Attempting to login via OAuth...
213+
Opening a link in your default browser: https://dash.cloudflare.com/oauth2/auth?response_type=code&client_id=54d11594-84e4-41aa-b438-e81b8fa78ee7&redirect_uri=http%3A%2F%2Flocalhost%3A8976%2Foauth%2Fcallback&scope=account%3Aread%20user%3Aread%20workers%3Awrite%20workers_kv%3Awrite%20workers_routes%3Awrite%20workers_scripts%3Awrite%20workers_tail%3Aread%20d1%3Awrite%20pages%3Awrite%20zone%3Aread%20ssl_certs%3Awrite%20ai%3Awrite%20queues%3Awrite%20pipelines%3Awrite%20offline_access&state=MOCK_STATE_PARAM&code_challenge=MOCK_CODE_CHALLENGE&code_challenge_method=S256
214+
Successfully logged in."
215+
`);
216+
expect(std.warn).toMatchInlineSnapshot(`""`);
217+
expect(std.err).toMatchInlineSnapshot(`""`);
218+
expect(readAuthConfigFile()).toEqual<UserAuthConfig>({
219+
api_token: undefined,
220+
oauth_token: "test-access-token",
221+
refresh_token: "test-refresh-token",
222+
expiration_time: expect.any(String),
223+
scopes: ["account:read"],
224+
});
225+
});
182226
});

packages/wrangler/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ export function createCLIParser(argv: string[]) {
642642
return;
643643
}
644644
await login({ browser: args.browser });
645-
const config = readConfig(args.config, args);
645+
const config = readConfig(args.config, args, undefined, true);
646646
await metrics.sendMetricsEvent("login user", {
647647
sendMetrics: config.send_metrics,
648648
});
@@ -662,7 +662,7 @@ export function createCLIParser(argv: string[]) {
662662
async (args) => {
663663
await printWranglerBanner();
664664
await logout();
665-
const config = readConfig(undefined, args);
665+
const config = readConfig(undefined, args, undefined, true);
666666
await metrics.sendMetricsEvent("logout user", {
667667
sendMetrics: config.send_metrics,
668668
});

0 commit comments

Comments
 (0)