mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
- When the WireGuard interface on the client lacks IPv6 address, it is possible that the IPv6 traffic leaks and goes directly to Internet instead of via FreedomBox. Fix this by adding IPv6 address on the FreedomBox. - If the FreedomBox fails to forward IPv6 traffic, then the client will be incapable using IPv6. This is better than leaking IPv6 traffic. - In the form to add WireGuard server configuration, allow providing IPv6 address along with IPv4 address. Mullvad VPN provides such configuration. - Don't provide IPv6 address for DNS server. Querying via IPv4 is sufficient for both A (IPv4) queries and AAAA (IPv6) queries. Providing two different IPs (one IPv4 and one IPv6 for the same DNS server) is not better then providing just one IP address. - Add DNS server information in the show client page. Tests: - Unit and functional tests work. - When WireGuard app is installed and server is started, the app page shows IPv4 and IPv6 addresses of the server. - After auto-adding client, the downloaded configuration contains two IP allowed addresses for the client. The configuration details also contain this information. DNS address information is correct. - Show client page shows multiple allowed IPs for the client. Multiple IPs for the server. DNS server is also shown. - When adding a server configuration, multiple IPs (one IPv4 and one IPv6) can be provided. - When adding clients, next free IP addresses for IPv4 and IPv6 are allocated as expected. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
125 lines
3.2 KiB
Python
125 lines
3.2 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
Tests for wireguard module forms.
|
|
"""
|
|
|
|
import pytest
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from freedombox.modules.wireguard.forms import (validate_endpoint,
|
|
validate_ip_addresses,
|
|
validate_key)
|
|
|
|
|
|
@pytest.mark.parametrize('key', [
|
|
'gKQhVGla4UtdqeY1dQ21G5lqrnX5NFcSEAqzM5iSdl0=',
|
|
'uHWSYIjPnS9fYFhZ0mf22IkOMyrWXDlfpXs6ve4QGHk=',
|
|
])
|
|
def test_validate_key_valid_patterns(key):
|
|
"""Test that valid wireguard key patterns as accepted."""
|
|
validate_key(key)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
'key',
|
|
[
|
|
# Invalid padding
|
|
'gKQhVGla4UtdqeY1dQ21G5lqrnX5NFcSEAqzM5iSdl0',
|
|
'invalid-base64',
|
|
'',
|
|
'aW52YWxpZC1sZW5ndGg=', # Incorrect length
|
|
])
|
|
def test_validate_key_invalid_patterns(key):
|
|
"""Test that invalid wireguard key patterns are rejected."""
|
|
with pytest.raises(ValidationError):
|
|
validate_key(key)
|
|
|
|
|
|
@pytest.mark.parametrize('endpoint', [
|
|
'[1::2]:1234',
|
|
'1.2.3.4:1234',
|
|
'example.com:1234',
|
|
])
|
|
def test_validate_endpoint_valid_patterns(endpoint):
|
|
"""Test that valid wireguard endpoint patterns are accepted."""
|
|
validate_endpoint(endpoint)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
'endpoint',
|
|
[
|
|
'',
|
|
# Invalid port
|
|
'1.2.3.4',
|
|
'1.2.3.4:',
|
|
'1.2.3.4:0',
|
|
'1.2.3.4:65536',
|
|
'1.2.3.4:1234invalid',
|
|
'1.2.3.4:invalid',
|
|
# Invalid IPv6
|
|
'[]:1234',
|
|
'[:1234',
|
|
])
|
|
def test_validate_endpoint_invalid_patterns(endpoint):
|
|
"""Test that invalid wireguard endpoint patterns are rejected."""
|
|
with pytest.raises(ValidationError):
|
|
validate_endpoint(endpoint)
|
|
|
|
|
|
@pytest.mark.parametrize('value', [
|
|
'1.2.3.4',
|
|
'1.2.3.4/0',
|
|
'1.2.3.4/32',
|
|
'1.2.3.4/24',
|
|
'1.2.3.4/255.255.255.0',
|
|
'1.2.3.4/0.0.0.255',
|
|
'::1',
|
|
'2001:db8::1',
|
|
'2001:db8::1/64',
|
|
'fe80::1/64',
|
|
'::/0',
|
|
])
|
|
def test_validate_ip_address_with_network_valid_patterns(value):
|
|
"""Test validating IPv4 address with network works for valid values."""
|
|
validate_ip_addresses(value)
|
|
|
|
|
|
@pytest.mark.parametrize('value', [
|
|
'1.2.3.4/',
|
|
'invalid-ip/24',
|
|
'1.2.3.4/x',
|
|
'1.2.3.4/-1',
|
|
'1.2.3.4/33',
|
|
'1.2.3.4/9.8.7.6',
|
|
'2001:db8::1/',
|
|
'2001:db8::1/129',
|
|
'2001:db8::1/x',
|
|
'2001:db8::1/-1',
|
|
'2001:db8::1/255.255.255.0',
|
|
'2001:db8::1::1',
|
|
'12345::1',
|
|
])
|
|
def test_validate_ip_address_with_network_invalid_patterns(value):
|
|
"""Test validating IPv4 address with network works for invalid values."""
|
|
with pytest.raises(ValidationError):
|
|
validate_ip_addresses(value)
|
|
|
|
|
|
@pytest.mark.parametrize('value', [
|
|
'1.2.3.4,5.6.7.8,2001:db8::1',
|
|
'1.2.3.4, 2001:db8::1',
|
|
])
|
|
def test_validate_ip_addresses_with_multiple_addresses(value):
|
|
"""Test validating multiple IP addresses separated by comma."""
|
|
validate_ip_addresses(value)
|
|
|
|
|
|
@pytest.mark.parametrize('value', [
|
|
'1.2.3.4 2001:db8::1',
|
|
'1.2.3.4, 2001:db8::1,',
|
|
])
|
|
def test_validate_ip_addresses_with_invalid_multiple_addresses(value):
|
|
"""Test validating multiple IP addresses separated by comma."""
|
|
with pytest.raises(ValidationError):
|
|
validate_ip_addresses(value)
|