1.0.0
Wydanie WGTools-Extended / release (push) Failing after 16s

This commit is contained in:
asminme committed 2026-10-30 00:35:08 +01:00
1 parent f5bdd7e21c
commit affe28ad71
110 files changed
+52936 -14

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
"""Exercise the authorization guard through the HTTP stack in an isolated process."""
import os
from pathlib import Path
import subprocess
import sys
import textwrap
def test_user_is_restricted_to_assigned_interface(tmp_path):
root = Path(__file__).resolve().parents[1]
env = dict(os.environ, WGTOOLS_DATABASE=str(tmp_path / "test.db"),
WGTOOLS_SESSION_KEY_FILE=str(tmp_path / "session.key"))
script = textwrap.dedent('''
from unittest.mock import patch
from fastapi.testclient import TestClient
import app.main as m
from app.core.auth import create_user, set_user_access
from app.core.preferences import update_branding
create_user('admin', 'password123')
user = create_user('tester', 'password123')
set_user_access(user['id'], 'user', ['wg1'])
update_branding('', '#123456', '')
def helper(action, payload=None, **kwargs):
if action == 'interfaces_list':
return {'ok': True, 'interfaces': [{'name': 'wg1'}, {'name': 'wg2'}]}
if action == 'snapshot':
return {'ok': True, 'config': {'interface': {'post_up': ['secret hook']}}, 'peers': []}
return {'ok': True}
with patch.object(m, 'run_helper', side_effect=helper), patch.object(m, 'merge_wireguard_last_seen', return_value=[]), patch.object(m, 'list_vps', return_value=[]):
c = TestClient(m.app)
assert 'WGTools' not in c.get('/login').text
assert c.post('/api/auth/login', json={'username':'tester','password':'password123'}).status_code == 200
client_page = c.get('/clients')
assert client_page.status_code == 200
assert 'Przekierowania portów' in client_page.text
assert 'href="/server"' not in client_page.text
assert c.post('/api/interfaces/delete', json={'interface':'wg1'}).status_code == 403
assert c.post('/api/server/config/apply', json={'content':''}).status_code == 403
assert c.post('/api/branding', json={}).status_code == 403
assert c.post('/api/update/upload', content=b'invalid').status_code == 403
assert c.get('/api/extended/ip-groups').status_code == 403
assert [x['name'] for x in c.get('/api/interfaces').json()['interfaces']] == ['wg1']
c.cookies.set('wgtools_interface', 'wg2')
assert c.get('/api/snapshot').status_code == 403
assert c.get('/api/extended/forwardings').status_code == 403
assert c.post('/api/clients/create', json={'name':'bad','type':'client'}).status_code == 403
c.cookies.set('wgtools_interface', 'wg1')
response = c.get('/api/snapshot')
assert response.status_code == 200
assert 'post_up' not in response.json()['config']['interface']
assert c.post('/api/clients/create', json={'name':'bad','type':'site_to_site','remote_networks':['10.1.0.0/16']}).status_code == 403
set_user_access(user['id'], 'user', ['wg1'], {'wg1':['add']})
assert c.post('/api/extended/forwardings', json={'public_ip':'192.0.2.1','public_port':1234,'target_ip':'10.0.0.2','target_port':1234,'protocol':'tcp'}).status_code == 403
assert c.post('/api/clients/update', json={'name':'peer','public_key':'x'*44}).status_code == 403
''')
subprocess.run([sys.executable, '-c', script], cwd=root, env=env, check=True, timeout=30)