Skip to content

Commit

Permalink
sanitise wrangler login
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Dec 17, 2024
1 parent b7bf528 commit 0d6ad0c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions packages/wrangler/src/__tests__/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,20 @@ describe("metrics", () => {
expect(std.debug).toContain('isWorkersCI":true');
});

it("should not send arguments with wrangler login", async () => {
const requests = mockMetricRequest();

await expect(
runWrangler("login username password")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: Unknown arguments: username, password]`
);

expect(requests.count).toBe(2);
expect(std.debug).toContain('"argsCombination":""');
expect(std.debug).toContain('"command":"wrangler login"');
});

it("should include args provided by the user", async () => {
const requests = mockMetricRequest();

Expand Down
5 changes: 3 additions & 2 deletions packages/wrangler/src/__tests__/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ vi.mock("../user/generate-auth-url", () => {
};
});

vi.mock("../is-ci", () => {
return { CI: { isCI: vi.fn().mockImplementation(() => false) } };
vi.mock("../is-ci", async (importOriginal) => {
const original = await importOriginal<typeof import("../is-ci")>();
return { ...original, CI: { isCI: vi.fn().mockImplementation(() => false) } };
});

vi.mock("../user/generate-random-state", () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/wrangler/src/metrics/metrics-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) {
argv?: string[]
) {
try {
if (properties.command?.startsWith("wrangler login")) {
properties.command = "wrangler login";
}
if (
properties.command === "wrangler telemetry disable" ||
properties.command === "wrangler metrics disable"
Expand Down

0 comments on commit 0d6ad0c

Please sign in to comment.