import os import unittest import sys from pathlib import Path # Import from ca_core (same pattern as other tests) code_path = Path(__file__).parent.parent.parent / "ca_core" sys.path.insert(0, str(code_path)) from crypto.zenroom_service_client import ZenroomServiceClient def _live_enabled() -> bool: return os.environ.get("RUN_LIVE_ZENROOM", "").strip().lower() in { "1", "true", "yes" } @unittest.skipUnless( _live_enabled(), "Set RUN_LIVE_ZENROOM=1 to run live Zenroom service smoke tests", ) class TestZenroomLiveServices(unittest.TestCase): @classmethod def setUpClass(cls): base_url = os.environ.get("ZENROOM_BASE_URL", "http://localhost:3300").strip() api_prefix = os.environ.get("ZENROOM_API_PREFIX", "/api").strip() timeout_s = int(os.environ.get("ZENROOM_TIMEOUT_S", "20")) cls.client = ZenroomServiceClient( base_url=base_url, api_prefix=api_prefix, timeout_s=timeout_s, ) def test_keypair_reading_identity_from_data(self): """ Tests: POST /api/Generate-a-keypair,-reading-identity-from-data Payload wrapped as {"data": {"myName": "..."}} """ res = self.client.generate_a_keypair_reading_identity_from_data( "LiveUser123456" ) self.assertIn("public_key", res) self.assertIn("private_key", res) self.assertIsInstance(res["public_key"], str) self.assertIsInstance(res["private_key"], str) self.assertTrue(res["public_key"]) self.assertTrue(res["private_key"]) def test_encrypt_decrypt_password_roundtrip(self): """ Tests: POST /api/Encrypt-a-message-with-the-password POST /api/Decrypt-the-message-with-the-password """ plaintext = "Dear Bob, your name is too short, goodbye - Alice." encrypted = self.client.encrypt_a_message_with_the_password( header="A very important secret", message=plaintext, password="myVerySecretPassword", ) for k in ("checksum", "header", "iv", "text"): self.assertIn(k, encrypted) self.assertIsInstance(encrypted[k], str) self.assertTrue(encrypted[k]) decrypted = self.client.decrypt_the_message_with_the_password( secret_message=encrypted, password="myVerySecretPassword", ) self.assertEqual(decrypted.get("textDecrypted"), plaintext)