Skip to content

Commit

Permalink
added dev build, moved to using href
Browse files Browse the repository at this point in the history
  • Loading branch information
witmicko committed Nov 21, 2023
1 parent 0e59e84 commit 6849373
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,15 @@ async function isBlockedByMetamask(href: string) {
function getSuspect(href: string | null): {
suspectHostname: string;
suspectHref: string;
suspectHrefPlain: string;
} {
try {
const url = new URL(href || '');
const hrefStr = href || '';
const url = new URL(hrefStr);
return {
suspectHostname: url.hostname,
suspectHref: url.href,
suspectHrefPlain: hrefStr,
};
} catch (error) {
throw new Error(`Invalid 'href' query parameter`);
Expand All @@ -179,7 +182,7 @@ function start() {
const hashContents = hash.slice(1); // drop leading '#' from hash
const hashQueryString = new URLSearchParams(hashContents);

const { suspectHostname, suspectHref } = getSuspect(
const { suspectHostname, suspectHref, suspectHrefPlain } = getSuspect(
hashQueryString.get('href'),
);

Expand All @@ -195,8 +198,8 @@ function start() {
}

const newIssueParams = `?title=[Legitimate%20Site%20Blocked]%20${encodeURIComponent(
suspectHostname,
)}&body=${encodeURIComponent(suspectHref)}`;
suspectHrefPlain,
)}&body=${encodeURIComponent(suspectHrefPlain)}`;

newIssueLink.addEventListener('click', async () => {
const listName = (await isBlockedByMetamask(suspectHref))
Expand Down
2 changes: 1 addition & 1 deletion tests/failed-lookup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ test('directs users to eth-phishing-detect to dispute a block, including issue t
await page.waitForLoadState('networkidle');

await expect(page).toHaveURL(
'https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20test.com&body=https%3A%2F%2Ftest.com%2F',
'https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20https%3A%2F%2Ftest.com&body=https%3A%2F%2Ftest.com',
);
});
10 changes: 6 additions & 4 deletions tests/metamask-block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('directs users to eth-phishing-detect to dispute a block, including issue t
await page.waitForLoadState('networkidle');

await expect(page).toHaveURL(
'https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20test.com&body=https%3A%2F%2Ftest.com%2F',
'https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20https%3A%2F%2Ftest.com&body=https%3A%2F%2Ftest.com',
);
});

Expand All @@ -33,17 +33,19 @@ test('correctly matches unicode domains', async ({ context, page }) => {
blacklist: ['xn--metamsk-en4c.io'],
},
});
const url = 'https://metamạsk.io';
const querystring = new URLSearchParams({
hostname: 'test.com',
href: 'https://metamạsk.io',
hostname: url,
href: url,
});
const encoded = encodeURIComponent(url);
await page.goto(`/#${querystring}`);

await page.getByRole('link', { name: 'report a detection problem' }).click();
// Wait for dynamic configuration check
await page.waitForLoadState('networkidle');

await expect(page).toHaveURL(
'https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20test.com&body=https%3A%2F%2Fmetamạsk.io',
`https://github.com/MetaMask/eth-phishing-detect/issues/new?title=[Legitimate%20Site%20Blocked]%20${encoded}&body=${encoded}`,
);
});
2 changes: 1 addition & 1 deletion tests/phishfort-block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ test('directs users to PhishFort to dispute a block, including issue template pa
await page.waitForLoadState('networkidle');

await expect(page).toHaveURL(
'https://github.com/phishfort/phishfort-lists/issues/new?title=[Legitimate%20Site%20Blocked]%20test.com&body=https%3A%2F%2Ftest.com%2F',
'https://github.com/phishfort/phishfort-lists/issues/new?title=[Legitimate%20Site%20Blocked]%20https%3A%2F%2Ftest.com&body=https%3A%2F%2Ftest.com',
);
});

0 comments on commit 6849373

Please sign in to comment.