Skip to content

Commit

Permalink
adds scrubPathGKey tests and tweaks scrubber
Browse files Browse the repository at this point in the history
  • Loading branch information
aristidesstaffieri committed Aug 19, 2024
1 parent 104bbe4 commit 5924f68
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
26 changes: 25 additions & 1 deletion extension/src/popup/helpers/__tests__/formatters.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BigNumber from "bignumber.js";
import { formatAmount } from "../formatters";
import { formatAmount, scrubPathGkey } from "../formatters";
import { formatTokenAmount } from "../soroban";

describe("formatAmount", () => {
Expand All @@ -15,3 +15,27 @@ describe("formatAmount", () => {
expect(formatTokenAmount(value, 7)).toBe(formatted);
});
});

describe("scrubPathGkey", () => {
const ADDRESS = "GCBDC5AVPZEOSO3IAASQZSVRJMHX3UCCZH5O7S53FPZ636LQ5RHEW65H";
it("should redact a G address from a URL", () => {
const route = "account-history/";
const url =
"http://0.0.0.0:3002/api/v1/account-history/GCBDC5AVPZEOSO3IAASQZSVRJMHX3UCCZH5O7S53FPZ636LQ5RHEW65H?network=PUBLIC";
const expected =
"http://0.0.0.0:3002/api/v1/account-history/REDACTED?network=PUBLIC";
expect(scrubPathGkey(route, url)).toBe(expected);
});
it("should redact a G address from a URL with no query params", () => {
const route = "account-history/";
const url =
"http://0.0.0.0:3002/api/v1/account-history/GCBDC5AVPZEOSO3IAASQZSVRJMHX3UCCZH5O7S53FPZ636LQ5RHEW65H";
const expected = "http://0.0.0.0:3002/api/v1/account-history/REDACTED";
expect(scrubPathGkey(route, url)).toBe(expected);
});
it("should return the URL in cases where it cannot redact", () => {
const route = "account-history/";
const url = "not-even-a-url";
expect(scrubPathGkey(route, url)).toBe(url);
});
});
10 changes: 7 additions & 3 deletions extension/src/popup/helpers/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ export const formattedBuffer = (data: Buffer) =>
truncatedPublicKey(Buffer.from(data).toString("hex").toUpperCase());

export const scrubPathGkey = (route: string, url: string) => {
const start = url.indexOf(route);
const end = url.indexOf("?");
return url.substring(start + route.length) + "REDACTED" + url.substring(end);
try {
const [base, slug] = url.split(route);
const end = slug.indexOf("?") === -1 ? slug.length : slug.indexOf("?");
return `${base}${route}` + "REDACTED" + slug.substring(end);
} catch (error) {
return url;
}
};

0 comments on commit 5924f68

Please sign in to comment.