Skip to content

Commit 7be53b2

Browse files
committed
Disable warnings for invalid config in wrangler login & logout
1 parent 02c8952 commit 7be53b2

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
@@ -25,6 +25,7 @@ import { runWrangler } from "./helpers/run-wrangler";
2525
import type { Config } from "../config";
2626
import type { UserAuthConfig } from "../user";
2727
import type { MockInstance } from "vitest";
28+
import { writeWranglerToml } from './helpers/write-wrangler-toml';
2829

2930
describe("User", () => {
3031
let isCISpy: MockInstance;
@@ -178,4 +179,47 @@ describe("User", () => {
178179
normalizeSlashes(`${getGlobalWranglerConfigPath()}/config/staging.toml`)
179180
);
180181
});
182+
183+
it("should not warn on invalid wrangler.toml when logging in", async () => {
184+
mockOAuthServerCallback("success");
185+
186+
let counter = 0;
187+
msw.use(
188+
http.post(
189+
"*/oauth2/token",
190+
async () => {
191+
counter += 1;
192+
193+
return HttpResponse.json({
194+
access_token: "test-access-token",
195+
expires_in: 100000,
196+
refresh_token: "test-refresh-token",
197+
scope: "account:read",
198+
});
199+
},
200+
{ once: true }
201+
)
202+
);
203+
204+
// @ts-expect-error - intentionally invalid
205+
writeWranglerToml({ invalid: true });
206+
207+
await runWrangler("login");
208+
209+
expect(counter).toBe(1);
210+
expect(std.out).toMatchInlineSnapshot(`
211+
"Attempting to login via OAuth...
212+
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
213+
Successfully logged in."
214+
`);
215+
expect(std.warn).toMatchInlineSnapshot(`""`);
216+
expect(std.err).toMatchInlineSnapshot(`""`);
217+
expect(readAuthConfigFile()).toEqual<UserAuthConfig>({
218+
api_token: undefined,
219+
oauth_token: "test-access-token",
220+
refresh_token: "test-refresh-token",
221+
expiration_time: expect.any(String),
222+
scopes: ["account:read"],
223+
});
224+
});
181225
});

packages/wrangler/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ export function createCLIParser(argv: string[]) {
657657
return;
658658
}
659659
await login({ browser: args.browser });
660-
const config = readConfig(args.config, args);
660+
const config = readConfig(args.config, args, undefined, true);
661661
await metrics.sendMetricsEvent("login user", {
662662
sendMetrics: config.send_metrics,
663663
});
@@ -677,7 +677,7 @@ export function createCLIParser(argv: string[]) {
677677
async (args) => {
678678
await printWranglerBanner();
679679
await logout();
680-
const config = readConfig(undefined, args);
680+
const config = readConfig(undefined, args, undefined, true);
681681
await metrics.sendMetricsEvent("logout user", {
682682
sendMetrics: config.send_metrics,
683683
});

0 commit comments

Comments
 (0)