diff options
| author | Oliver <oliver@mohlin.dev> | 2025-05-14 15:59:08 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2025-05-16 12:55:20 +0200 |
| commit | bb25086a2a57db6c636f364d63f08a63b785cfee (patch) | |
| tree | d5f935c40543c5f6756d4dcf2e2df1525ad0da9a /desktop | |
| parent | 3da577397b12930ac20861677ffc20a2009efc13 (diff) | |
| download | mullvadvpn-bb25086a2a57db6c636f364d63f08a63b785cfee.tar.xz mullvadvpn-bb25086a2a57db6c636f364d63f08a63b785cfee.zip | |
Add tests for unsupported WireGuard port notifications
Diffstat (limited to 'desktop')
| -rw-r--r-- | desktop/packages/mullvad-vpn/test/e2e/mocked/notifications.spec.ts | 119 |
1 files changed, 118 insertions, 1 deletions
diff --git a/desktop/packages/mullvad-vpn/test/e2e/mocked/notifications.spec.ts b/desktop/packages/mullvad-vpn/test/e2e/mocked/notifications.spec.ts index 3ac06ebbc7..f8e0ad8014 100644 --- a/desktop/packages/mullvad-vpn/test/e2e/mocked/notifications.spec.ts +++ b/desktop/packages/mullvad-vpn/test/e2e/mocked/notifications.spec.ts @@ -1,9 +1,17 @@ import { expect, test } from '@playwright/test'; import { Page } from 'playwright'; +import { getDefaultSettings } from '../../../src/main/default-settings'; import { colors } from '../../../src/renderer/lib/foundations'; import { RoutePath } from '../../../src/renderer/lib/routes'; -import { IAccountData } from '../../../src/shared/daemon-rpc-types'; +import { + Constraint, + ErrorStateCause, + IAccountData, + IRelayListWithEndpointData, + ISettings, + TunnelState, +} from '../../../src/shared/daemon-rpc-types'; import { getBackgroundColor } from '../utils'; import { MockedTestUtils, startMockedApp } from './mocked-utils'; @@ -52,3 +60,112 @@ test('App should notify user about account expiring soon', async () => { subTitle = page.getByTestId('notificationSubTitle'); await expect(subTitle).toContainText(/less than a day left\. buy more credit\./i); }); + +test.describe('Unsupported wireguard port', () => { + const portRanges: [number, number][] = [ + [1, 50], + [51, 100], + ]; + const portInRange = portRanges[0][0]; + const portOutOfRange = portRanges[1][1] + 1; + + const updatePort = async (port: Constraint<number>) => { + const settings = getDefaultSettings(); + if ('normal' in settings.relaySettings) { + settings.relaySettings.normal.wireguardConstraints.port = port; + } + await util.sendMockIpcResponse<ISettings>({ + channel: 'settings-', + response: settings, + }); + }; + + const updatePortRanges = async (portRanges: [number, number][]) => { + await util.sendMockIpcResponse<IRelayListWithEndpointData>({ + channel: 'relays-', + response: { + relayList: { + countries: [], + }, + wireguardEndpointData: { + portRanges, + udp2tcpPorts: [], + }, + }, + }); + }; + + const updateTunnelState = async (tunnelState: TunnelState) => { + await util.sendMockIpcResponse<TunnelState>({ + channel: 'tunnel-', + response: tunnelState, + }); + }; + + test.beforeAll(async () => { + await updatePortRanges(portRanges); + }); + + const cases: { + name: string; + port: Constraint<number>; + tunnelState: TunnelState; + }[] = [ + { + name: 'Should not show notification when any port is allowed', + port: 'any', + tunnelState: { + state: 'error', + details: { cause: ErrorStateCause.startTunnelError }, + }, + }, + { + name: 'Should not show notification when port is in range', + port: { only: portInRange }, + tunnelState: { + state: 'error', + details: { cause: ErrorStateCause.startTunnelError }, + }, + }, + { + name: 'Should not show notification when tunnel is not in error state', + port: { only: portOutOfRange }, + tunnelState: { + state: 'connected', + details: { + endpoint: { + address: '', + daita: false, + protocol: 'tcp', + quantumResistant: false, + tunnelType: 'wireguard', + }, + }, + }, + }, + ]; + + cases.forEach(({ name, port, tunnelState }) => { + test(name, async () => { + await updatePort(port); + await updateTunnelState(tunnelState); + + const subTitle = page.getByTestId('notificationSubTitle'); + + await expect(subTitle).not.toContainText(/The selected WireGuard port is not supported/i); + }); + }); + + test('Should show notification when port is out of range', async () => { + await updatePort({ only: portOutOfRange }); + await updateTunnelState({ + state: 'error', + details: { cause: ErrorStateCause.startTunnelError }, + }); + + const title = page.getByTestId('notificationTitle'); + const subTitle = page.getByTestId('notificationSubTitle'); + await expect(title).toHaveText('BLOCKING INTERNET'); + await expect(subTitle).toContainText(/The selected WireGuard port is not supported/i); + }); +}); |
