MCPcopy Create free account
hub / github.com/GH05TCREW/MetasploitMCP / TestMsfClientFunctions

Class TestMsfClientFunctions

tests/test_helpers.py:61–104  ·  view source on GitHub ↗

Test MSF client initialization and management functions.

Source from the content-addressed store, hash-verified

59
60
61class TestMsfClientFunctions:
62 """Test MSF client initialization and management functions."""
63
64 @patch('MetasploitMCP.MSF_PASSWORD', 'test-password')
65 @patch('MetasploitMCP.MSF_SERVER', '127.0.0.1')
66 @patch('MetasploitMCP.MSF_PORT_STR', '55553')
67 @patch('MetasploitMCP.MSF_SSL_STR', 'false')
68 def test_initialize_msf_client_success(self):
69 """Test successful MSF client initialization."""
70 with patch('MetasploitMCP._msf_client_instance', None):
71 with patch('MetasploitMCP.MsfRpcClient') as mock_client_class:
72 mock_client = Mock()
73 mock_client.core.version = {'version': '6.3.0'}
74 mock_client_class.return_value = mock_client
75
76 result = initialize_msf_client()
77
78 assert result is mock_client
79 mock_client_class.assert_called_once_with(
80 password='test-password',
81 server='127.0.0.1',
82 port=55553,
83 ssl=False
84 )
85
86 @patch('MetasploitMCP.MSF_PORT_STR', 'invalid-port')
87 def test_initialize_msf_client_invalid_port(self):
88 """Test MSF client initialization with invalid port."""
89 with patch('MetasploitMCP._msf_client_instance', None):
90 with pytest.raises(ValueError, match="Invalid MSF connection parameters"):
91 initialize_msf_client()
92
93 def test_get_msf_client_not_initialized(self):
94 """Test get_msf_client when client not initialized."""
95 with patch('MetasploitMCP._msf_client_instance', None):
96 with pytest.raises(ConnectionError, match="not been initialized"):
97 get_msf_client()
98
99 def test_get_msf_client_initialized(self):
100 """Test get_msf_client when client is initialized."""
101 mock_client = Mock()
102 with patch('MetasploitMCP._msf_client_instance', mock_client):
103 result = get_msf_client()
104 assert result is mock_client
105
106
107class TestGetModuleObject:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected