mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-14 22:11:27 +00:00
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
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()
|