mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-12 12:05:07 +00:00
feat(search): add ANONYMOUS_SEARCH to skip the login for a service
A service that sets the flag gets no cookie load, no authenticate() call and no cookie save on a search, on the CLI and in the REST search handler. /api/services reports it as anonymous_search.
This commit is contained in:
@@ -144,6 +144,27 @@ async def test_server_account_uses_its_own_cache_and_returns_none(seen, tmp_path
|
||||
assert not (tmp_path / "_requests").exists()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_anonymous_search_skips_the_login_and_keeps_the_account_cache(seen, tmp_path, monkeypatch):
|
||||
def search(self):
|
||||
seen["search_cache_dir"] = self.cache.get("tokens").path.parent
|
||||
return iter(())
|
||||
|
||||
def no_login_material(*args):
|
||||
raise AssertionError("an anonymous search must not read login material")
|
||||
|
||||
handlers.Services.load("EXAMPLE").ANONYMOUS_SEARCH = True
|
||||
monkeypatch.setattr(_CacheService, "search", search)
|
||||
monkeypatch.setattr(handlers, "resolve_server_account", lambda *args: "acct")
|
||||
monkeypatch.setattr(handlers, "server_login_material", no_login_material)
|
||||
response = await handlers.search_handler({"service": "EXAMPLE", "query": "q", **CREDENTIALS})
|
||||
|
||||
assert json.loads(response.body)["results"] == []
|
||||
assert "seeded" not in seen
|
||||
assert seen["parent_params"]["cookies_supplied"] is False
|
||||
assert seen["search_cache_dir"] == tmp_path / "_accounts" / "EXAMPLE" / "acct"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_full_mode_keeps_the_server_cache(seen, tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(stats, "mode", "full")
|
||||
|
||||
Reference in New Issue
Block a user