Files
outlookEmailPlus/tests/test_ui_settings_external_api_key.py
T
胡绍康 01d1dc0874 feat: implement external API security architecture (public mode, IP whitelist, rate limit)
- Add ExternalApiGuard for IP whitelisting, rate limiting, and public mode enforcement
- Update wait-message to support async mode
- Fix bugs in verification code extraction (BUG-00014 to BUG-00017)
- Update documentation and architectural diagrams
2026-03-13 11:27:34 +08:00

49 lines
1.6 KiB
Python

import unittest
from tests._import_app import import_web_app_module
class ExternalApiKeySettingsUITests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.module = import_web_app_module()
cls.app = cls.module.app
def _login(self, client, password: str = "testpass123"):
resp = client.post("/login", json={"password": password})
self.assertEqual(resp.status_code, 200)
self.assertTrue(resp.get_json().get("success"))
resp.close()
def _get_text(self, client, path):
resp = client.get(path)
try:
return resp.status_code, resp.data.decode("utf-8")
finally:
resp.close()
def test_settings_page_has_external_api_key_input(self):
client = self.app.test_client()
self._login(client)
status_code, html = self._get_text(client, "/")
self.assertEqual(status_code, 200)
self.assertIn('id="settingsExternalApiKey"', html)
self.assertIn('id="settingsExternalApiKeysJson"', html)
def test_main_js_loads_masked_external_api_key_fields(self):
client = self.app.test_client()
self._login(client)
status_code, js = self._get_text(client, "/static/js/main.js")
self.assertEqual(status_code, 200)
self.assertIn("external_api_key_masked", js)
self.assertIn("external_api_keys", js)
self.assertIn("settingsExternalApiKey", js)
self.assertIn("settingsExternalApiKeysJson", js)
self.assertIn("dataset.maskedValue", js)
if __name__ == "__main__":
unittest.main()