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_access_extended.py
T
asminme affe28ad71
Wydanie WGTools-Extended / release (push) Failing after 16s
1.0.0
2026-10-30 00:35:08 +01:00

26 lines
1.2 KiB
Python

import pytest
from app.core import auth
def test_accounts_start_with_safe_access_and_can_be_scoped(tmp_path, monkeypatch):
monkeypatch.setattr(auth, "DATABASE_PATH", str(tmp_path / "users.db"))
admin = auth.create_user("admin", "password123")
user = auth.create_user("tester", "password123")
assert auth.get_user_access(admin["id"])["role"] == "admin"
assert auth.get_user_access(user["id"]) == {"role": "user", "interfaces": [], "permissions": {}}
auth.set_user_access(user["id"], "user", ["wg2", "wg1", "wg1"])
assert auth.get_user_access(user["id"])["interfaces"] == ["wg1", "wg2"]
auth.set_user_access(user['id'], 'user', ['wg1'], {'wg1':['add']})
assert auth.get_user_access(user['id'])['permissions'] == {'wg1':['add']}
with pytest.raises(ValueError):
auth.set_user_access(user["id"], "user", ["wg1;rm"])
with pytest.raises(ValueError):
auth.set_user_access(user["id"], "user", ["wgnode0"])
def test_legacy_accounts_keep_admin_access(tmp_path, monkeypatch):
monkeypatch.setattr(auth, "DATABASE_PATH", str(tmp_path / "legacy.db"))
user = auth.create_user("legacy", "password123")
assert auth.get_user_access(user["id"]) == {"role": "admin", "interfaces": [], "permissions": {}}