This repository has been archived on 2026-11-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
WGTools-Extended/tests/test_service_policy.py
asminme f4929c7cac
Wydanie WGTools-Extended / release (push) Successful in 11s
1.0.5 - opisy usług w przekierowaniach
2026-10-30 13:15:39 +01:00

26 lines
1.3 KiB
Python

import pytest
from app.core import preferences
from app import main
def test_service_policy_and_validation(tmp_path, monkeypatch):
monkeypatch.setattr(preferences, 'DATABASE_PATH', str(tmp_path / 'settings.db'))
monkeypatch.setattr(main, 'audit_username', lambda request: 'jan')
assert not preferences.get_service_policy()['enabled']
with pytest.raises(ValueError):
preferences.update_service_policy(True, 'list', [])
preferences.update_service_policy(True, 'list', ['WireGuard', 'WireGuard'])
request = main.ExtendedForwardRequest(public_ip='192.0.2.1', public_port=80, target_ip='10.0.0.2', target_port=80, protocol='tcp', service='WireGuard')
with pytest.raises(ValueError):
main.forward_payload(request, None)
request.confirmation = main.SERVICE_CONFIRMATION
result = main.forward_payload(request, None)
assert result['responsibility']['user'] == 'jan'
request.service = 'inny'
with pytest.raises(ValueError):
main.forward_payload(request, None)
preferences.update_service_policy(True, 'combo', ['WireGuard'])
assert main.forward_payload(request, None)['service'] == 'inny'
preferences.update_service_policy(True, 'custom', [])
assert main.forward_payload(request, None)['service'] == 'inny'