mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-18 06:31:11 +00:00
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
![]() |
"""
|
||
|
Manage SSL test cases
|
||
|
"""
|
||
|
import os
|
||
|
import unittest
|
||
|
|
||
|
from pydantic import SecretStr
|
||
|
|
||
|
from metadata.utils.ssl_manager import SSLManager
|
||
|
|
||
|
|
||
|
class SSLManagerTest(unittest.TestCase):
|
||
|
"""
|
||
|
Tests to verify the functionality of SSLManager
|
||
|
"""
|
||
|
|
||
|
def setUp(self):
|
||
|
self.ca = SecretStr("CA certificate content")
|
||
|
self.key = SecretStr("Private key content")
|
||
|
self.cert = SecretStr("Certificate content")
|
||
|
self.ssl_manager = SSLManager(self.ca, self.key, self.cert)
|
||
|
|
||
|
def tearDown(self):
|
||
|
self.ssl_manager.cleanup_temp_files()
|
||
|
|
||
|
def test_create_temp_file(self):
|
||
|
content = SecretStr("Test content")
|
||
|
temp_file = self.ssl_manager.create_temp_file(content)
|
||
|
self.assertTrue(os.path.exists(temp_file))
|
||
|
with open(temp_file, "r", encoding="UTF-8") as file:
|
||
|
file_content = file.read()
|
||
|
self.assertEqual(file_content, content.get_secret_value())
|
||
|
content = SecretStr("")
|
||
|
temp_file = self.ssl_manager.create_temp_file(content)
|
||
|
self.assertTrue(os.path.exists(temp_file))
|
||
|
with open(temp_file, "r", encoding="UTF-8") as file:
|
||
|
file_content = file.read()
|
||
|
self.assertEqual(file_content, content.get_secret_value())
|
||
|
with self.assertRaises(AttributeError):
|
||
|
content = None
|
||
|
self.ssl_manager.create_temp_file(content)
|
||
|
|
||
|
def test_cleanup_temp_files(self):
|
||
|
temp_file = self.ssl_manager.create_temp_file(SecretStr("Test content"))
|
||
|
self.ssl_manager.cleanup_temp_files()
|
||
|
self.assertFalse(os.path.exists(temp_file))
|