-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_security_basic.py
More file actions
158 lines (128 loc) · 4.37 KB
/
Copy pathtest_security_basic.py
File metadata and controls
158 lines (128 loc) · 4.37 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
"""
Basic security framework structure test (no Redis required)
"""
import os
import sys
from pathlib import Path
def test_security_files():
"""Test that all security files exist."""
base_path = Path(__file__).parent / 'apps' / 'security'
required_files = [
'security_manager.py',
'api_security.py',
'database_security.py',
'audit_monitoring.py',
'input_validation.py',
'config_management.py',
'error_handling.py',
'__init__.py'
]
missing_files = []
for file in required_files:
if not (base_path / file).exists():
missing_files.append(file)
if missing_files:
print(f"X Missing security files: {', '.join(missing_files)}")
return False
print("+ All security files present")
return True
def test_security_imports_syntax():
"""Test that security modules have valid Python syntax."""
import ast
base_path = Path(__file__).parent / 'apps' / 'security'
files_to_check = [
'security_manager.py',
'api_security.py',
'database_security.py',
'input_validation.py',
'error_handling.py'
]
for file in files_to_check:
file_path = base_path / file
try:
with open(file_path, 'r', encoding='utf-8') as f:
code = f.read()
ast.parse(code)
except SyntaxError as e:
print(f"X Syntax error in {file}: {e}")
return False
except Exception as e:
print(f"X Error reading {file}: {e}")
return False
print("+ All security files have valid syntax")
return True
def test_django_settings():
"""Test that Django settings include security configurations."""
settings_path = Path(__file__).parent / 'fraud_platform' / 'settings.py'
try:
with open(settings_path, 'r', encoding='utf-8') as f:
settings_content = f.read()
required_configs = [
'APISecurityMiddleware',
'SecurityErrorMiddleware',
'SECURITY_FRAMEWORK_ENABLED',
'REDIS_URL'
]
missing_configs = []
for config in required_configs:
if config not in settings_content:
missing_configs.append(config)
if missing_configs:
print(f"X Missing Django configurations: {', '.join(missing_configs)}")
return False
print("+ Django settings configured for security framework")
return True
except Exception as e:
print(f"X Error checking Django settings: {e}")
return False
def test_requirements():
"""Test that requirements include security dependencies."""
requirements_path = Path(__file__).parent / 'requirements.txt'
try:
with open(requirements_path, 'r', encoding='utf-8') as f:
requirements_content = f.read()
required_deps = [
'cryptography',
'bcrypt',
'PyJWT',
'bleach'
]
missing_deps = []
for dep in required_deps:
if dep not in requirements_content:
missing_deps.append(dep)
if missing_deps:
print(f"X Missing dependencies: {', '.join(missing_deps)}")
return False
print("+ All security dependencies listed in requirements")
return True
except Exception as e:
print(f"X Error checking requirements: {e}")
return False
def main():
"""Run all basic security tests."""
print("Testing Security Framework Structure...")
print("=" * 50)
tests = [
test_security_files,
test_security_imports_syntax,
test_django_settings,
test_requirements
]
passed = 0
for test in tests:
if test():
passed += 1
print("=" * 50)
print(f"+ {passed}/{len(tests)} structure tests passed")
if passed == len(tests):
print("Security framework structure is valid!")
print("Note: Full functionality testing requires Redis to be running.")
return True
else:
print("Some structure tests failed. Please review the errors above.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)