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

[WIP] Malicious website protection - Windows support #282

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions integration-tests/Mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,24 @@ export class Mocks {
expect(calls).toMatchObject([['privacyDashboardOpenUrlInNewTab', { url }]]);
return;
}
throw new Error('unreachable. mockCalledForAboutLink must be handled');
if (this.platform.name === 'windows') {
const calls = await this.outgoing({
names: ['OpenInNewTab'],
});
expect(calls).toMatchObject([
[
'OpenInNewTab',
{
Feature: 'PrivacyDashboard',
Name: 'OpenInNewTab',
Data: {},
},
],
]);
return;
}

throw new Error('unreachable. mockCalledForOpenURLInNewTab must be handled');
}

async calledForInitialExtensionMessage() {
Expand Down Expand Up @@ -572,7 +589,7 @@ export class Mocks {
]);
return;
}
throw new Error('unreachable. mockCalledForAboutLink must be handled');
throw new Error('unreachable. mockCalledForToggleAllowList must be handled');
}

async calledForSearch(term) {
Expand Down
42 changes: 42 additions & 0 deletions integration-tests/windows.spec-int.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,48 @@ test.describe('cookie prompt management', () => {
});
});

test.describe('phishing & malware protection', () => {
test('phishing warning', { tag: '@screenshots' }, async ({ page }) => {
/** @type {DashboardPage} */
const dash = await DashboardPage.windows(page);
await dash.addState([testDataStates.phishing]);
await dash.screenshot('phishing-warning.png');
await dash.hasPhishingIcon();
await dash.hasPhishingHeadingText();
await dash.hasPhishingWarningText();
await dash.hasPhishingStatusText();
await dash.connectionLinkDoesntShow();
});

test('malware warning', { tag: '@screenshots' }, async ({ page }) => {
/** @type {DashboardPage} */
const dash = await DashboardPage.windows(page);
await dash.addState([testDataStates.malware]);
await dash.screenshot('malware-warning.png');
await dash.hasMalwareIcon();
await dash.hasMalwareHeadingText();
await dash.hasMalwareWarningText();
await dash.hasMalwareStatusText();
await dash.connectionLinkDoesntShow();
});

test('shows report as safe link', async ({ page }) => {
/** @type {DashboardPage} */
const dash = await DashboardPage.windows(page);
await dash.addState([testDataStates.malware]);
await dash.clickReportAsSafeLink();
await dash.mocks.calledForReportAsSafeLink('https://privacy-test-pages.site/security/badware/malware.html');
});

test('shows help page link', async ({ page }) => {
/** @type {DashboardPage} */
const dash = await DashboardPage.windows(page);
await dash.addState([testDataStates.malware]);
await dash.clickHelpPageLink();
await dash.mocks.calledForHelpPagesLink();
});
});

test.describe('windows screenshots', { tag: '@screenshots' }, () => {
const states = [
{ name: 'ad-attribution', state: testDataStates['ad-attribution'] },
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion schema/__generated__/schema.parsers.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions schema/__generated__/schema.types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion schema/windows-view-model.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
"type": "boolean"
},
"localeSettings": {
"$ref": "locale.json"
"$ref": "./locale.json"
},
"maliciousSiteStatus": {
"$ref": "./malicious-site.json"
}
}
}
2 changes: 1 addition & 1 deletion shared/js/browser/macos-communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const combineSources = () => ({
tab: Object.assign(
{},
trackerBlockingData || {},
{ maliciousSiteStatus: maliciousSiteStatus ?? false },
{ maliciousSiteStatus: maliciousSiteStatus ?? null },
{
isPendingUpdates,
parentEntity,
Expand Down
1 change: 0 additions & 1 deletion shared/js/browser/utils/communication-mocks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export async function mockDataProvider(params) {
}
window.onChangeLocale?.(state.localeSettings);
window.onChangeRequestData(state.url, { requests: state.requests || [] });

if (platform?.name === 'macos' || platform?.name === 'ios') {
window.onChangeMaliciousSiteStatus?.(state.maliciousSiteStatus);
}
Expand Down
8 changes: 7 additions & 1 deletion shared/js/browser/windows-communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@ let protections;
let isPendingUpdates;
let parentEntity;

/** @type {import('../../../schema/__generated__/schema.types').MaliciousSiteStatus | undefined} */
let maliciousSiteStatus;

/** @type {string | undefined} */
let locale;

const combineSources = () => ({
tab: Object.assign(
{},
trackerBlockingData || {},
{ maliciousSiteStatus: maliciousSiteStatus ?? null },
{
isPendingUpdates,
parentEntity,
Expand All @@ -90,7 +94,8 @@ const resolveInitialRender = function () {
const isUpgradedHttpsSet = typeof upgradedHttps === 'boolean';
const isIsProtectedSet = typeof protections !== 'undefined';
const isTrackerBlockingDataSet = typeof trackerBlockingData === 'object';
if (!isUpgradedHttpsSet || !isIsProtectedSet || !isTrackerBlockingDataSet) {
const isMaliciousSiteSet = maliciousSiteStatus && maliciousSiteStatus.kind !== undefined;
if (!isUpgradedHttpsSet || !isIsProtectedSet || !isTrackerBlockingDataSet || !isMaliciousSiteSet) {
return;
}

Expand Down Expand Up @@ -119,6 +124,7 @@ function handleViewModelUpdate(viewModel) {
certificateData = viewModel.certificates || [];
protections = viewModel.protections;
locale = viewModel.localeSettings?.locale;
maliciousSiteStatus = viewModel.maliciousSiteStatus;

trackerBlockingData = createTabData(viewModel.tabUrl, upgradedHttps, viewModel.protections, viewModel.rawRequestData);
trackerBlockingData.cookiePromptManagementStatus = viewModel.cookiePromptManagementStatus;
Expand Down
2 changes: 1 addition & 1 deletion shared/js/ui/platform-features.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function createPlatformFeatures(platform) {
initialScreen: screen,
opener,
supportsInvalidCertsImplicitly: platform.name !== 'browser' && platform.name !== 'windows',
supportsMaliciousSiteWarning: platform.name === 'macos' || platform.name === 'ios',
supportsMaliciousSiteWarning: platform.name === 'macos' || platform.name === 'ios' || platform.name === 'windows',
includeToggleOnBreakageForm,
randomisedCategories,
});
Expand Down
1 change: 1 addition & 0 deletions shared/js/ui/views/tests/generate-data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export class MockData {
cookiePromptManagementStatus: this.cookiePromptManagementStatus,
isInvalidCert: this.isInvalidCert,
localeSettings: this.localeSettings,
maliciousSiteStatus: this.maliciousSiteStatus || { kind: null },
},
};
}
Expand Down
Loading