Files
pic/tests/e2e/wg/test_wg_basic.py
T
roof ab6d6230dd
Unit Tests / test (push) Successful in 7m30s
Fix: read WG server IP and subnet from live API instead of hardcoding 10.0.0.x
test_wg_connect_and_ping_server and the connected_peer fixture hardcoded
10.0.0.1 / 10.0.0.0/24 as the server VPN address. This breaks when the
server uses a different subnet (e.g. pic1 uses 10.0.1.1/24). Now both
read 'address' from /api/wireguard/status at session start and pass the
live server_ip / server_network through wg_server_info and connected_peer.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 14:09:48 -04:00

31 lines
1.2 KiB
Python

import pytest
import subprocess
pytestmark = pytest.mark.wg
def test_wg_connect_and_ping_server(connected_peer):
"""Scenario 25+26: create peer, connect, ping server VPN IP."""
iface = connected_peer['iface']
server_ip = connected_peer.get('server_ip', '10.0.0.1')
assert iface.up, "WireGuard interface should be up"
assert iface.is_connected(server_ip), f"Server VPN IP {server_ip} should be reachable via WireGuard"
def test_wg_peer_has_assigned_ip(connected_peer):
"""Verify the assigned peer IP is routed correctly."""
peer_ip = connected_peer['ip']
result = subprocess.run(['ip', 'addr', 'show'], capture_output=True, text=True)
assert peer_ip in result.stdout, f"Peer IP {peer_ip} should be assigned to the WG interface"
def test_wg_disconnect_removes_route(connected_peer):
"""Scenario 29: after disconnect, VPN IP is not reachable."""
iface = connected_peer['iface']
server_ip = connected_peer.get('server_ip', '10.0.0.1')
iface.bring_down()
result = subprocess.run(['ping', '-c', '1', '-W', '2', server_ip],
capture_output=True, timeout=5)
# After disconnect, ping should fail
assert result.returncode != 0, "VPN IP should not be reachable after disconnect"