mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 12:35:13 +00:00
fix(api): redact error replies, lock segment url lookups, refuse unresolvable proxy hosts and recheck job proxies at start
This commit is contained in:
@@ -340,6 +340,38 @@ async def test_services_load_errors_go_to_the_admin_key_only(
|
||||
assert admin["load_errors"] == ["BAD: failed to import - ImportError: boom"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"path", ["/api/maintenance/clear-cache", "/api/maintenance/clear-temp", "/api/maintenance/refresh-services"]
|
||||
)
|
||||
async def test_maintenance_needs_an_admin_key(make_app, aiohttp_client, monkeypatch: pytest.MonkeyPatch, path) -> None:
|
||||
from unshackle.commands import env
|
||||
from unshackle.core import services as services_module
|
||||
from unshackle.core.config import config
|
||||
|
||||
monkeypatch.setattr(env, "clear_directory", lambda path: (0, 0))
|
||||
monkeypatch.setattr(services_module, "refresh_and_reload", lambda busy: [])
|
||||
monkeypatch.setattr(config, "serve", {"api_secret": "admin", "users": {"user": {}, "boss": {"admin": True}}})
|
||||
client = await aiohttp_client(make_app())
|
||||
user = await client.post(path, headers={"X-Secret-Key": "user"})
|
||||
assert user.status == 403
|
||||
assert (await user.json())["error_code"] == "FORBIDDEN"
|
||||
for key in ("admin", "boss"):
|
||||
assert (await client.post(path, headers={"X-Secret-Key": key})).status == 200, key
|
||||
|
||||
|
||||
async def test_config_sends_directories_to_an_admin_key_only(
|
||||
make_app, aiohttp_client, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
from unshackle.core.config import config
|
||||
|
||||
monkeypatch.setattr(config, "serve", {"api_secret": "admin", "users": {"user": {}}})
|
||||
client = await aiohttp_client(make_app())
|
||||
user = await (await client.get("/api/config", headers={"X-Secret-Key": "user"})).json()
|
||||
admin = await (await client.get("/api/config", headers={"X-Secret-Key": "admin"})).json()
|
||||
assert "directories" not in user["config"]
|
||||
assert set(admin["config"]["directories"]) == {"downloads", "temp", "cache"}
|
||||
|
||||
|
||||
async def test_health_needs_an_api_key(make_app, aiohttp_client) -> None:
|
||||
app = make_app(remote_only=True, with_auth_middleware=True)
|
||||
app["config"]["users"]["good-key"] = {}
|
||||
|
||||
Reference in New Issue
Block a user