Igor commited on
Commit
2523ab7
·
unverified ·
1 Parent(s): 25240da

Tests: Add coverage for CLI util commands (channel key management)

Browse files
Files changed (1) hide show
  1. tests/test_e2e.py +28 -0
tests/test_e2e.py CHANGED
@@ -128,5 +128,33 @@ class TestShitposterE2E(unittest.TestCase):
128
  self.assertIn(f"[!] DECRYPTED SUCCESS: {welcome_msg}", res_scan.stdout)
129
  print("[SUCCESS] Bob successfully read the welcome message!")
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  if __name__ == '__main__':
132
  unittest.main()
 
128
  self.assertIn(f"[!] DECRYPTED SUCCESS: {welcome_msg}", res_scan.stdout)
129
  print("[SUCCESS] Bob successfully read the welcome message!")
130
 
131
+ def test_util_commands(self):
132
+ print("\n--- Starting Util Commands Test ---")
133
+
134
+ # 1. Generate Channel Key
135
+ print("[1] Generating Channel Key...")
136
+ res_gen = self.run_cli(['util', 'generate-channel-key', '--out', 'broadcast.key'])
137
+ self.assertEqual(res_gen.returncode, 0)
138
+ self.assertTrue(os.path.exists(os.path.join(self.work_dir, 'broadcast.key')))
139
+
140
+ # Extract the words from stdout
141
+ key_words = self.extract_key_from_output(res_gen.stdout)
142
+ self.assertEqual(len(key_words.split()), 32)
143
+ print(f"[DEBUG] Generated Key Words: {key_words[:30]}...")
144
+
145
+ # 2. Words to Bytes
146
+ print("[2] Converting Words back to Bytes...")
147
+ res_w2b = self.run_cli(['util', 'words-to-bytes', key_words, '--out', 'restored.key'])
148
+ self.assertEqual(res_w2b.returncode, 0)
149
+
150
+ # 3. Verify Files Match
151
+ with open(os.path.join(self.work_dir, 'broadcast.key'), 'rb') as f1:
152
+ k1 = f1.read()
153
+ with open(os.path.join(self.work_dir, 'restored.key'), 'rb') as f2:
154
+ k2 = f2.read()
155
+
156
+ self.assertEqual(k1, k2, "Restored key does not match original!")
157
+ print("[SUCCESS] Key conversion loop verified.")
158
+
159
  if __name__ == '__main__':
160
  unittest.main()