Repository navigation
Expand file tree
/
Copy pathtest_structure.py
More file actions
159 lines (131 loc) · 5.05 KB
/
Copy pathtest_structure.py
File metadata and controls
159 lines (131 loc) · 5.05 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
159
#!/usr/bin/env python3
"""
Test script to validate that all module imports work correctly.
This ensures the structure alignment is correct.
"""
import sys
import os
# Add the mitregen directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'mitregen'))
def test_imports():
"""Test all module imports"""
print("=== Testing Module Imports ===\n")
# Test basic imports
tests = [
("prompts", "get_prompt"),
("universal_techniques", "UniversalTechnique"),
("enhanced_research", "MITREResearcher"),
("external_research", "ExternalSourceScraper"),
("universal_research", "UniversalResearcher"),
("universal_project_manager", "UniversalProjectManager"),
("generate", "main"),
("cli", "parse_args"),
]
passed = 0
failed = 0
for module_name, class_or_function in tests:
try:
module = __import__(module_name)
if hasattr(module, class_or_function):
print(f"✓ {module_name}.{class_or_function} - OK")
passed += 1
else:
print(f"✗ {module_name}.{class_or_function} - Missing attribute")
failed += 1
except ImportError as e:
print(f"✗ {module_name} - Import failed: {e}")
failed += 1
except Exception as e:
print(f"✗ {module_name} - Error: {e}")
failed += 1
print(f"\n=== Results ===")
print(f"Passed: {passed}")
print(f"Failed: {failed}")
print(f"Total: {passed + failed}")
return failed == 0
def test_core_functionality():
"""Test core functionality"""
print("\n=== Testing Core Functionality ===\n")
try:
# Test UniversalTechnique creation
from universal_techniques import UniversalTechnique, TechniqueType, TechniqueCategory
technique = UniversalTechnique(
name="Test Technique",
technique_type=TechniqueType.CUSTOM_DEFENSIVE,
category=TechniqueCategory.DETECTION,
platforms=["Windows"],
description="Test description"
)
print(f"✓ Created technique: {technique.id}")
# Test MITREResearcher
from enhanced_research import MITREResearcher
researcher = MITREResearcher()
validation = researcher.validate_technique("T1059")
print(f"✓ MITRE validation for T1059: {validation['valid']}")
# Test UniversalResearcher
from universal_research import UniversalResearcher
universal_researcher = UniversalResearcher()
print(f"✓ Universal researcher initialized")
# Test basic context generation
context, sources = universal_researcher.get_comprehensive_context("T1059", "Windows", "description.md")[:2]
print(f"✓ Context generation works (context length: {len(context)})")
return True
except Exception as e:
print(f"✗ Core functionality test failed: {e}")
return False
def test_external_research():
"""Test external research capabilities"""
print("\n=== Testing External Research ===\n")
try:
from external_research import ExternalSourceScraper
scraper = ExternalSourceScraper()
print("✓ External research scraper available")
# Test GitHub search (without actually making requests)
print("✓ External research module imports correctly")
return True
except ImportError:
print("! External research not available (optional)")
return True
except Exception as e:
print(f"✗ External research test failed: {e}")
return False
def test_project_structure():
"""Test project structure alignment"""
print("\n=== Testing Project Structure ===\n")
required_files = [
"mitregen/__init__.py",
"mitregen/generate.py",
"mitregen/prompts.py",
"mitregen/universal_techniques.py",
"mitregen/enhanced_research.py",
"mitregen/universal_research.py",
"mitregen/universal_project_manager.py",
"mitregen/cli.py",
"requirements.txt"
]
missing_files = []
for file_path in required_files:
if not os.path.exists(file_path):
missing_files.append(file_path)
if missing_files:
print(f"✗ Missing required files:")
for file_path in missing_files:
print(f" - {file_path}")
return False
else:
print("✓ All required files present")
return True
if __name__ == "__main__":
print("Starting comprehensive structure validation...\n")
success = True
# Run all tests
success &= test_project_structure()
success &= test_imports()
success &= test_core_functionality()
success &= test_external_research()
if success:
print("\n🎉 All tests passed! Structure alignment is correct.")
sys.exit(0)
else:
print("\n❌ Some tests failed. Please check the issues above.")
sys.exit(1)