Igor commited on
Commit
317dbf5
·
unverified ·
1 Parent(s): fb283a1

Tests: Add E2E API test suite

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -0
  2. tests/test_api_e2e.py +73 -0
requirements.txt CHANGED
@@ -2,3 +2,4 @@ cryptography
2
  click
3
  fastapi
4
  uvicorn
 
 
2
  click
3
  fastapi
4
  uvicorn
5
+ requests
tests/test_api_e2e.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ import requests
3
+ import time
4
+ import os
5
+
6
+ API_URL = os.environ.get("API_URL", "https://igor53627-shitposter-api.hf.space")
7
+
8
+ class TestShitposterAPI(unittest.TestCase):
9
+ def test_e2e_encryption_flow(self):
10
+ print(f"\nTesting against: {API_URL}")
11
+
12
+ # 0. Wait for service (simple retry loop)
13
+ retries = 5
14
+ while retries > 0:
15
+ try:
16
+ requests.get(f"{API_URL}/docs", timeout=5)
17
+ break
18
+ except:
19
+ print("Waiting for API to wake up...")
20
+ time.sleep(5)
21
+ retries -= 1
22
+
23
+ # 1. Generate Alice
24
+ print("[1] Generating Alice...")
25
+ resp = requests.get(f"{API_URL}/keygen")
26
+ if resp.status_code == 503:
27
+ self.skipTest("API Service is unavailable (still building?)")
28
+
29
+ self.assertEqual(resp.status_code, 200)
30
+ alice = resp.json()
31
+ self.assertTrue("private_key_b64" in alice)
32
+ self.assertTrue("public_signal" in alice)
33
+
34
+ # 2. Generate Bob
35
+ print("[2] Generating Bob...")
36
+ resp = requests.get(f"{API_URL}/keygen")
37
+ self.assertEqual(resp.status_code, 200)
38
+ bob = resp.json()
39
+
40
+ # 3. Alice Encrypts for Bob
41
+ message = "The eagle flies at midnight."
42
+ print(f"[3] Encrypting: '{message}'")
43
+
44
+ payload = {
45
+ "message": message,
46
+ "sender_private_key_b64": alice["private_key_b64"],
47
+ "recipient_public_signal": bob["public_signal"],
48
+ "stealth": True
49
+ }
50
+ resp = requests.post(f"{API_URL}/encrypt", json=payload)
51
+ self.assertEqual(resp.status_code, 200)
52
+ data = resp.json()
53
+ self.assertTrue("shitpost" in data)
54
+ ciphertext = data["shitpost"]
55
+ print(f" Shitpost: {ciphertext[:50]}...")
56
+
57
+ # 4. Bob Decrypts
58
+ print("[4] Decrypting...")
59
+ payload = {
60
+ "ciphertext_shitpost": ciphertext,
61
+ "recipient_private_key_b64": bob["private_key_b64"],
62
+ "sender_public_signal": alice["public_signal"]
63
+ }
64
+ resp = requests.post(f"{API_URL}/decrypt", json=payload)
65
+ self.assertEqual(resp.status_code, 200)
66
+ data = resp.json()
67
+ self.assertEqual(data["message"], message)
68
+
69
+ print(f" Decrypted: {data['message']}")
70
+ print("[SUCCESS] API E2E Test Passed.")
71
+
72
+ if __name__ == '__main__':
73
+ unittest.main()