Download tests/control/test_unicode_auth.py from RDS777/lg: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/RDS777/lg/resolve/main/tests/control/test_unicode_auth.py
- Command line
-
hf download hf://spaces/RDS777/lg/tests/control/test_unicode_auth.py
-
curl -L -o test_unicode_auth.py https://huggingface.co/spaces/RDS777/lg/resolve/main/tests/control/test_unicode_auth.py
1.01 kB
| 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) | |