-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_ssl_context_manager.py
More file actions
73 lines (59 loc) · 1.98 KB
/
test_ssl_context_manager.py
File metadata and controls
73 lines (59 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""
Test SSL context manager for model downloads.
"""
import sys
import ssl
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def test_ssl_context_manager():
"""Test the SSL context manager."""
print("=" * 60)
print("Test: SSL Context Manager")
print("=" * 60)
# Import the context manager
from cdmf_stem_splitting import _SSLContextManager
# Save original context
original = ssl._create_default_https_context
print(f"Original SSL context: {original}")
# Test context manager
print("\nEntering SSL context manager...")
with _SSLContextManager():
current = ssl._create_default_https_context
print(f"Current SSL context: {current}")
# Verify that the context was changed to unverified context
unverified = ssl._create_unverified_context
if current == unverified:
print("✓ SSL context changed to unverified context successfully")
elif current != original:
print("✓ SSL context changed (but not to expected unverified context)")
else:
print("✗ SSL context was not changed")
return False
# Verify restoration
restored = ssl._create_default_https_context
print(f"\nRestored SSL context: {restored}")
if restored == original:
print("✓ SSL context restored successfully to original")
return True
else:
print("✗ SSL context was not restored to original")
return False
def main():
"""Run the test."""
try:
result = test_ssl_context_manager()
if result:
print("\n✓ Test passed!")
sys.exit(0)
else:
print("\n✗ Test failed")
sys.exit(1)
except Exception as e:
print(f"\n✗ Test failed with exception: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()