mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-15 22:41:28 +00:00
Test scene search API authentication
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from scene_search.api import require_api_key
|
||||
|
||||
|
||||
class ApiAuthTests(unittest.TestCase):
|
||||
def test_api_key_disabled_accepts_request(self) -> None:
|
||||
fake_settings = SimpleNamespace(scene_api_key="")
|
||||
with patch("scene_search.api.settings", fake_settings):
|
||||
require_api_key(authorization=None, x_scene_search_key=None)
|
||||
|
||||
def test_bearer_api_key_is_accepted(self) -> None:
|
||||
fake_settings = SimpleNamespace(scene_api_key="secret")
|
||||
with patch("scene_search.api.settings", fake_settings):
|
||||
require_api_key(
|
||||
authorization="Bearer secret",
|
||||
x_scene_search_key=None,
|
||||
)
|
||||
|
||||
def test_header_api_key_is_accepted(self) -> None:
|
||||
fake_settings = SimpleNamespace(scene_api_key="secret")
|
||||
with patch("scene_search.api.settings", fake_settings):
|
||||
require_api_key(
|
||||
authorization=None,
|
||||
x_scene_search_key="secret",
|
||||
)
|
||||
|
||||
def test_wrong_api_key_is_rejected(self) -> None:
|
||||
fake_settings = SimpleNamespace(scene_api_key="secret")
|
||||
with patch("scene_search.api.settings", fake_settings):
|
||||
with self.assertRaises(HTTPException) as caught:
|
||||
require_api_key(
|
||||
authorization="Bearer wrong",
|
||||
x_scene_search_key=None,
|
||||
)
|
||||
|
||||
self.assertEqual(caught.exception.status_code, 401)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user