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 15202a6 commit 433bc23
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"type": "node-terminal"
}
]
}
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
],
"scripts": {
"build": "node ./build/index.js",
"build:prod": "NODE='production' yarn build",
"build:dev": "node ./build/dev.js",
"build:prod": "NODE='production' yarn build",
"dev": "yarn build:dev",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"prepack": "./scripts/prepack.sh",
"serve": "yarn http-server ./dist",
"setup": "yarn install && yarn allow-scripts",
"start": "yarn build && yarn http-server ./dist",
"dev": "yarn build:dev",
"serve": "yarn http-server ./dist",
"test": "yarn playwright test"
},
"dependencies": {
Expand Down
17 changes: 9 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,21 @@ async function isBlockedByMetamask(href: string) {
/**
* Extract hostname and href from the query string.
*
* @returns the suspect hostname and href from the query string.
* @returns The suspect hostname and href from the query string.
* @param href - The href value to check.
*/
function getSuspect(
href: string | null,
): {
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 @@ -181,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 @@ -197,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 433bc23

Please sign in to comment.