import unittest from types import SimpleNamespace from fastapi.testclient import TestClient from lg_control.server import create_app, secure_equal class UnicodeAuthenticationTests(unittest.TestCase): def test_unicode_secret_comparison(self): self.assertTrue(secure_equal('cle-secrete-é', 'cle-secrete-é')) self.assertFalse(secure_equal('cle-secrete-e', 'cle-secrete-é')) self.assertFalse(secure_equal(None, 'cle-secrete-é')) def test_wrong_ascii_token_against_unicode_secret_is_401_not_500(self): cfg = SimpleNamespace(origin='https://lg.example', worker_token='é'*32, client_id='', client_secret='', password='', redirects=set(), oauth_enabled=False) with TestClient(create_app(cfg)) as client: for path, method in [('/control/chat', 'post'), ('/worker/poll', 'get')]: response = getattr(client, method)(path, headers={'Authorization': 'Bearer ' + 'a'*32}) self.assertEqual(response.status_code, 401)