test(linux_client): add mTLS client certificate handling test in test_linux_client.py
This commit is contained in:
@@ -198,6 +198,31 @@ class TestLinuxClientComponent(unittest.TestCase):
|
|||||||
self.assertEqual(logs[0]["__CURSOR"], "c3")
|
self.assertEqual(logs[0]["__CURSOR"], "c3")
|
||||||
self.assertEqual(newest_cursor, "c4")
|
self.assertEqual(newest_cursor, "c4")
|
||||||
|
|
||||||
|
def test_mtls_client_certificate_handling(self):
|
||||||
|
import shutil
|
||||||
|
test_dir = "test_linux_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("linux-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_linux_certs"
|
||||||
|
os.makedirs(empty_dir, exist_ok=True)
|
||||||
|
with self.assertRaises(FileNotFoundError):
|
||||||
|
Linux_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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user