From 55567a33bc49a9982b3c104d209205b1877eedcb Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Mon, 3 Feb 2025 23:38:45 +0100 Subject: [PATCH] adjust test data --- client/playwright.config.ts | 1 + client/tests/e2e/dhcp.spec.ts | 10 +++++---- client/tests/helpers/network.ts | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 client/tests/helpers/network.ts diff --git a/client/playwright.config.ts b/client/playwright.config.ts index 7ededa8d..e621722a 100644 --- a/client/playwright.config.ts +++ b/client/playwright.config.ts @@ -8,6 +8,7 @@ import path from 'path'; export default defineConfig({ testDir: './tests/e2e', globalSetup: path.resolve('./tests/e2e/globalSetup.ts'), + timeout: 5000, /* Run tests in files in parallel */ fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ diff --git a/client/tests/e2e/dhcp.spec.ts b/client/tests/e2e/dhcp.spec.ts index 9ef72fac..1c5465e2 100644 --- a/client/tests/e2e/dhcp.spec.ts +++ b/client/tests/e2e/dhcp.spec.ts @@ -1,10 +1,12 @@ import { test, expect } from '@playwright/test'; import { ADMIN_PASSWORD, ADMIN_USERNAME } from '../constants'; +import { getDHCPConfig } from '../helpers/network'; -const INTERFACE_NAME = 'en0'; -const RANGE_START = '192.168.1.100'; -const RANGE_END = '192.168.1.200'; -const SUBNET_MASK = '255.255.255.0'; +const dhcpConfig = getDHCPConfig(); +const INTERFACE_NAME = dhcpConfig.interfaceName; +const RANGE_START = dhcpConfig.rangeStart; +const RANGE_END = dhcpConfig.rangeEnd; +const SUBNET_MASK = dhcpConfig.subnetMask; const LEASE_TIME = '86400'; test.describe('DHCP Configuration', () => { diff --git a/client/tests/helpers/network.ts b/client/tests/helpers/network.ts new file mode 100644 index 00000000..33a797df --- /dev/null +++ b/client/tests/helpers/network.ts @@ -0,0 +1,38 @@ +import { networkInterfaces } from 'os'; + +interface DHCPConfig { + interfaceName: string; + rangeStart: string; + rangeEnd: string; + subnetMask: string; +} + +export function getDHCPConfig(): DHCPConfig { + const interfaces = networkInterfaces(); + for (const [name, addresses] of Object.entries(interfaces)) { + const ipv4Address = addresses?.find((addr) => addr.family === 'IPv4' && !addr.internal); + if (ipv4Address) { + const ip = ipv4Address.address.split('.').map(Number); + const mask = ipv4Address.netmask?.split('.').map(Number) || [255, 255, 255, 0]; + + // Calculate network address + const network = ip.map((octet, i) => octet & mask[i]); + + // Calculate first and last usable addresses (excluding network and broadcast) + const rangeStart = [...network]; + rangeStart[3] = network[3] + 1; + + const broadcast = network.map((octet, i) => octet | (~mask[i] & 255)); + const rangeEnd = [...broadcast]; + rangeEnd[3] = broadcast[3] - 1; + + return { + interfaceName: name, + rangeStart: rangeStart.join('.'), + rangeEnd: rangeEnd.join('.'), + subnetMask: ipv4Address.netmask || '255.255.255.0', + }; + } + } + throw new Error('No suitable network interface found'); +}