test_v5_features.pyโข9.88 kB
#!/usr/bin/env python3
"""
Test script for MSF Console MCP v5.0 features
Tests plugin system, core commands, and session management
"""
import asyncio
import json
import sys
from datetime import datetime
# Add path for imports
sys.path.insert(0, '.')
from mcp_server_stable import MSFConsoleMCPServer
async def test_v5_features():
"""Test all v5.0 features"""
server = MSFConsoleMCPServer()
print("\n๐ MSF Console MCP v5.0 Feature Test Suite")
print("=" * 60)
# Initialize server
print("\n๐ฆ Initializing MCP Server v5.0...")
try:
await server.initialize()
print("โ
Server initialized successfully")
except Exception as e:
print(f"โ Initialization failed: {e}")
return
# Test results
results = {
"total_tests": 0,
"passed": 0,
"failed": 0,
"features_tested": []
}
# ========== TEST PLUGIN SYSTEM ==========
print("\n\n๐ Testing Enhanced Plugin System")
print("-" * 40)
# Test 1: List plugins
print("\n1๏ธโฃ Testing plugin listing...")
try:
result = await server.handle_tool_call("msf_enhanced_plugin_manager", {
"action": "list"
})
data = json.loads(result["content"][0]["text"])
plugin_count = len(data.get("plugins", []))
print(f"โ
Found {plugin_count} plugins available")
results["passed"] += 1
results["features_tested"].append("plugin_listing")
except Exception as e:
print(f"โ Plugin listing failed: {e}")
results["failed"] += 1
results["total_tests"] += 1
# Test 2: Load plugin
print("\n2๏ธโฃ Testing plugin loading (auto_add_route)...")
try:
result = await server.handle_tool_call("msf_enhanced_plugin_manager", {
"action": "load",
"plugin_name": "auto_add_route"
})
data = json.loads(result["content"][0]["text"])
if data.get("success"):
print(f"โ
Plugin loaded: {data.get('data', {}).get('plugin')}")
results["passed"] += 1
results["features_tested"].append("plugin_loading")
else:
print(f"โ Plugin load failed: {data.get('error')}")
results["failed"] += 1
except Exception as e:
print(f"โ Plugin loading error: {e}")
results["failed"] += 1
results["total_tests"] += 1
# Test 3: Execute plugin command
print("\n3๏ธโฃ Testing plugin command execution...")
try:
result = await server.handle_tool_call("msf_enhanced_plugin_manager", {
"action": "execute",
"plugin_name": "auto_add_route",
"command": "status"
})
data = json.loads(result["content"][0]["text"])
if data.get("success"):
print(f"โ
Plugin command executed successfully")
print(f" Status: {data.get('data', {})}")
results["passed"] += 1
results["features_tested"].append("plugin_commands")
else:
print(f"โ Plugin command failed: {data.get('error')}")
results["failed"] += 1
except Exception as e:
print(f"โ Plugin command error: {e}")
results["failed"] += 1
results["total_tests"] += 1
# ========== TEST CORE COMMANDS ==========
print("\n\nโก Testing Core Commands")
print("-" * 40)
# Test 4: Network routing (route command)
print("\n4๏ธโฃ Testing route manager...")
try:
result = await server.handle_tool_call("msf_route_manager", {
"action": "list"
})
data = json.loads(result["content"][0]["text"])
if data.get("success"):
print(f"โ
Route manager working - {len(data.get('data', {}).get('routes', []))} routes")
results["passed"] += 1
results["features_tested"].append("route_manager")
else:
print(f"โ Route manager failed: {data.get('error')}")
results["failed"] += 1
except Exception as e:
print(f"โ Route manager error: {e}")
results["failed"] += 1
results["total_tests"] += 1
# Test 5: Output filtering (grep command)
print("\n5๏ธโฃ Testing output filter (grep)...")
try:
result = await server.handle_tool_call("msf_output_filter", {
"pattern": "version",
"command": "version"
})
data = json.loads(result["content"][0]["text"])
if data.get("success"):
print(f"โ
Output filter working - {data.get('data', {}).get('matches', 0)} matches")
results["passed"] += 1
results["features_tested"].append("output_filter")
else:
print(f"โ Output filter failed: {data.get('error')}")
results["failed"] += 1
except Exception as e:
print(f"โ Output filter error: {e}")
results["failed"] += 1
results["total_tests"] += 1
# Test 6: Console logger (spool command)
print("\n6๏ธโฃ Testing console logger...")
try:
result = await server.handle_tool_call("msf_console_logger", {
"action": "status"
})
data = json.loads(result["content"][0]["text"])
if data.get("success"):
print(f"โ
Console logger status: {data.get('data', {})}")
results["passed"] += 1
results["features_tested"].append("console_logger")
else:
print(f"โ Console logger failed: {data.get('error')}")
results["failed"] += 1
except Exception as e:
print(f"โ Console logger error: {e}")
results["failed"] += 1
results["total_tests"] += 1
# Test 7: Config manager (save command)
print("\n7๏ธโฃ Testing config manager...")
try:
result = await server.handle_tool_call("msf_config_manager", {
"action": "list"
})
data = json.loads(result["content"][0]["text"])
if data.get("success"):
print(f"โ
Config manager working - {len(data.get('data', {}).get('configurations', []))} configs")
results["passed"] += 1
results["features_tested"].append("config_manager")
else:
print(f"โ Config manager failed: {data.get('error')}")
results["failed"] += 1
except Exception as e:
print(f"โ Config manager error: {e}")
results["failed"] += 1
results["total_tests"] += 1
# ========== TEST SESSION MANAGEMENT ==========
print("\n\n๐ฏ Testing Advanced Session Management")
print("-" * 40)
# Test 8: Session clustering
print("\n8๏ธโฃ Testing session clustering...")
try:
result = await server.handle_tool_call("msf_session_clustering", {
"action": "create",
"group_name": "test_group"
})
data = json.loads(result["content"][0]["text"])
if data.get("success"):
print(f"โ
Session clustering working - created group: {data.get('data', {}).get('group')}")
results["passed"] += 1
results["features_tested"].append("session_clustering")
else:
print(f"โ Session clustering failed: {data.get('error')}")
results["failed"] += 1
except Exception as e:
print(f"โ Session clustering error: {e}")
results["failed"] += 1
results["total_tests"] += 1
# Test 9: Session persistence
print("\n9๏ธโฃ Testing session persistence...")
try:
result = await server.handle_tool_call("msf_session_persistence", {
"action": "list"
})
data = json.loads(result["content"][0]["text"])
if data.get("success"):
print(f"โ
Session persistence working - {len(data.get('data', {}).get('persistence_handlers', []))} handlers")
results["passed"] += 1
results["features_tested"].append("session_persistence")
else:
print(f"โ Session persistence failed: {data.get('error')}")
results["failed"] += 1
except Exception as e:
print(f"โ Session persistence error: {e}")
results["failed"] += 1
results["total_tests"] += 1
# ========== SUMMARY ==========
print("\n\n๐ Test Results Summary")
print("=" * 60)
print(f"Total Tests: {results['total_tests']}")
print(f"โ
Passed: {results['passed']}")
print(f"โ Failed: {results['failed']}")
print(f"Success Rate: {(results['passed'] / results['total_tests'] * 100):.1f}%")
print(f"\nFeatures Tested: {', '.join(results['features_tested'])}")
# Check feature coverage
expected_features = [
"plugin_listing", "plugin_loading", "plugin_commands",
"route_manager", "output_filter", "console_logger",
"config_manager", "session_clustering", "session_persistence"
]
missing_features = set(expected_features) - set(results["features_tested"])
if missing_features:
print(f"\nโ ๏ธ Missing features: {', '.join(missing_features)}")
else:
print(f"\nโ
All expected v5.0 features tested!")
# Cleanup
await server.cleanup()
return results
if __name__ == "__main__":
print("MSF Console MCP v5.0 Feature Test")
print("Testing plugin system, core commands, and session management...")
try:
results = asyncio.run(test_v5_features())
# Exit with appropriate code
if results["failed"] == 0:
print("\n๐ All tests passed!")
sys.exit(0)
else:
print(f"\nโ ๏ธ {results['failed']} tests failed")
sys.exit(1)
except KeyboardInterrupt:
print("\nTest interrupted")
sys.exit(1)
except Exception as e:
print(f"\nTest suite error: {e}")
sys.exit(1)