Skip to content

Commit

Permalink
chore: fix pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AugmentedMode committed Aug 29, 2024
1 parent 0b5e4ee commit fc58e1f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 57 deletions.
25 changes: 2 additions & 23 deletions app/scripts/lib/snap-keyring/utils/isBlockedUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ListNames, PhishingController } from '@metamask/phishing-controller';
import { ControllerMessenger } from '@metamask/base-controller';
import { isBlockedUrl, isC2DomainBlocked } from './isBlockedUrl';
import { isBlockedUrl } from './isBlockedUrl';

describe('isBlockedUrl', () => {
const messenger = new ControllerMessenger();
Expand All @@ -27,9 +27,7 @@ describe('isBlockedUrl', () => {
version: 1,
lastUpdated: 0,
name: ListNames.MetaMask,
c2DomainBlocklist: [
'a379a6f6eeafb9a55e378c118034e2751e682fab9f2d30ab13d2125586ce1947',
],
c2DomainBlocklist: [],
},
],
},
Expand Down Expand Up @@ -72,23 +70,4 @@ describe('isBlockedUrl', () => {
);
expect(result).toEqual(expected);
});

// @ts-expect-error This is missing from the Mocha type definitions
it.each([
['https://example.com', true],
['https://metamask.io', false],
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
])('"%s" is blocked: %s', async (url: any, expected: boolean) => {
const result = await isC2DomainBlocked(
url,
async () => {
return await phishingController.maybeUpdateState();
},
(origin: string) => {
return phishingController.isBlockedRequest(origin);
},
);
expect(result).toEqual(expected);
});
});
28 changes: 0 additions & 28 deletions app/scripts/lib/snap-keyring/utils/isBlockedUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,3 @@ export const isBlockedUrl = async (
return false;
}
};

/**
* Checks weather a given URL is blocked due to making a network request to a
* known C2 domain.
*
* @param url - The URL to check.
* @param maybeUpdateState - A function that updates the phishing controller state.
* @param testC2Domain - A function that tests if a URL is a known malicious C2 domain.
* @returns Returns a promise which resolves to `true` if the URL is blocked
* due to making a network request to a known malicious C2 domain. Otherwise,
* resolves to `false`.
*/
export const isC2DomainBlocked = async (
url: string,
maybeUpdateState: () => ReturnType<PhishingController['maybeUpdateState']>,
testC2Domain: (
url: string,
) => ReturnType<PhishingController['isBlockedRequest']>,
): Promise<boolean> => {
try {
// check if the url is in the phishing list
await maybeUpdateState();
return testC2Domain(url).result;
} catch (error) {
console.error('Invalid URL passed into snap-keyring:', error);
return false;
}
};
10 changes: 4 additions & 6 deletions test/e2e/tests/phishing-controller/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function setupPhishingDetectionMocks(
});

await mockServer
.forGet(`${C2_DOMAIN_BLOCKLIST_URL}`)
.forGet(C2_DOMAIN_BLOCKLIST_URL)
.withQuery({ timestamp: '2024-08-27T15:30:45Z' })
.thenCallback(() => {
return {
Expand Down Expand Up @@ -164,12 +164,10 @@ async function mockEmptyStalelistAndHotlist(mockServer) {
* @returns {string} The name of the phishing config in the response.
*/
function resolveProviderConfigName(providerName) {
switch (providerName.toLowerCase()) {
case BlockProvider.MetaMask:
return 'eth_phishing_detect_config';
default:
throw new Error('Provider name must be metamask');
if (providerName.toLowerCase() === BlockProvider.MetaMask) {
return 'eth_phishing_detect_config';
}
throw new Error(`Unknown provider: ${providerName}`);
}

module.exports = {
Expand Down

0 comments on commit fc58e1f

Please sign in to comment.