Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow newIssueUrl to be specified by a hash query param #23

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ const phishingHtml = readFileSync(
*
* @param hostname - The hostname to include in the URL fragment.
* @param href - The href to include in the URL fragment.
* @param newIssueUrl - Optional, the url for the new issue link
* to include in in the URL fragment.
* @returns The phishing warning page URL.
*/
function getUrl(hostname?: string, href?: string) {
function getUrl(hostname?: string, href?: string, newIssueUrl?: string) {
const baseUrl = 'https://metamask.github.io/phishing-warning/#';
if (hostname && href) {
if (hostname && href && newIssueUrl) {
return `${baseUrl}hostname=${encodeURIComponent(
hostname,
)}&href=${encodeURIComponent(href)}&newIssueUrl=${encodeURIComponent(
newIssueUrl,
)}`;
} else if (hostname && href) {
return `${baseUrl}hostname=${encodeURIComponent(
hostname,
)}&href=${encodeURIComponent(href)}`;
Expand Down Expand Up @@ -98,6 +106,21 @@ describe('Phishing warning page', () => {
);
});

it('should have the correct "New issue" link if a newIssueUrl is specified in the hash query string', async () => {
mockLocation(
getUrl('example.com', 'https://example.com', 'https://example.com'),
);

// non-null assertion used because TypeScript doesn't know the event handler was run
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
onDomContentLoad!(new Event('DOMContentLoaded'));

const newIssueLink = window.document.getElementById('new-issue-link');
expect(newIssueLink?.getAttribute('href')).toBe(
'https://example.com?title=[Legitimate%20Site%20Blocked]%20example.com&body=https%3A%2F%2Fexample.com',
);
});

it.todo(
'should add site to safelist when the user continues at their own risk',
);
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ function start() {
throw new Error('Unable to locate new issue link');
}

const newIssueUrl = `https://github.com/MetaMask/eth-phishing-detect/issues/new`;
const newIssueUrl =
hashQueryString.get('newIssueUrl') ||
`https://github.com/MetaMask/eth-phishing-detect/issues/new`;
const newIssueParams = `?title=[Legitimate%20Site%20Blocked]%20${encodeURIComponent(
suspectHostname,
)}&body=${encodeURIComponent(suspectHref)}`;
Expand Down