test(win_client): add mTLS client certificate handling test in test_win_client.py
This commit is contained in:
@@ -184,6 +184,31 @@ class TestWinClientComponent(unittest.TestCase):
|
||||
# Only rec 103 and 102 should be processed (101 is already sent, <= 100 breaks early)
|
||||
self.assertEqual(logs, [103, 102])
|
||||
|
||||
def test_mtls_client_certificate_handling(self):
|
||||
import shutil
|
||||
test_dir = "test_win_mtls_certs"
|
||||
os.makedirs(test_dir, exist_ok=True)
|
||||
try:
|
||||
from src import server_enrollment as se
|
||||
ca_cert, ca_key, ca_pem, _ = se.generate_ca_if_needed(test_dir)
|
||||
client_cert_pem, client_key_pem = se.issue_client_cert("win-client-test", ca_cert, ca_key)
|
||||
|
||||
with open(os.path.join(test_dir, "ca.crt"), "w") as f:
|
||||
f.write(ca_pem)
|
||||
with open(os.path.join(test_dir, "client.crt"), "w") as f:
|
||||
f.write(client_cert_pem)
|
||||
with open(os.path.join(test_dir, "client.key"), "w") as f:
|
||||
f.write(client_key_pem)
|
||||
|
||||
# Test missing certs exception
|
||||
empty_dir = "test_empty_certs"
|
||||
os.makedirs(empty_dir, exist_ok=True)
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
Win_Client.get_tls_socket("127.0.0.1", 9443, empty_dir)
|
||||
shutil.rmtree(empty_dir, ignore_errors=True)
|
||||
finally:
|
||||
shutil.rmtree(test_dir, ignore_errors=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user