-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_security_modules.py
More file actions
99 lines (74 loc) · 2.32 KB
/
test_security_modules.py
File metadata and controls
99 lines (74 loc) · 2.32 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import sys
from pathlib import Path
pisc_root = Path(__file__).parent
sys.path.insert(0, str(pisc_root))
sys.path.insert(0, str(pisc_root / "api"))
print("Testing security modules...")
print("=" * 50)
# Test 1: security_validation
try:
from api.security_validation import validate_input
print("[OK] security_validation module imported")
# Test simple validation
result = validate_input("Hello world")
print(
" - Simple validation: Passed"
if result.is_valid
else " - Simple validation: Failed"
)
except Exception as e:
print("[FAIL] security_validation:", e)
import traceback
print(traceback.format_exc())
# Test 2: security_logging
try:
from api.security_logging import SecurityLogger
print("[OK] security_logging module imported")
logger = SecurityLogger("test")
logger.info("Test message", "test_event")
print(" - Logger created and tested")
except Exception as e:
print("[FAIL] security_logging:", e)
import traceback
print(traceback.format_exc())
# Test 3: security_audit
try:
from api.security_audit import audit_logger, AuditEventType, AuditSeverity
print("[OK] security_audit module imported")
event = audit_logger.log_event(AuditEventType.REQUEST_RECEIVED, AuditSeverity.INFO)
print(" - Audit event created:", event.event_id)
print(
" - Integrity check: Passed"
if event.verify_integrity()
else " - Integrity check: Failed"
)
except Exception as e:
print("[FAIL] security_audit:", e)
import traceback
print(traceback.format_exc())
# Test 4: security_ssrf
try:
from api.security_ssrf import validate_url
print("[OK] security_ssrf module imported")
valid_url = "https://api.openai.com"
invalid_url = "http://localhost:8000"
valid_result = validate_url(valid_url)
invalid_result = validate_url(invalid_url)
print(
" - Valid URL (",
valid_url,
"): Valid" if valid_result.is_valid else "Invalid",
sep="",
)
print(
" - Invalid URL (",
invalid_url,
"): Invalid" if not invalid_result.is_valid else "Valid",
sep="",
)
except Exception as e:
print("[FAIL] security_ssrf:", e)
import traceback
print(traceback.format_exc())
print("\n" + "=" * 50)
print("All modules tested!")