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

Class TestExploitListingTools

tests/test_tools_integration.py:120–233  ·  view source on GitHub ↗

Test tools for listing exploits and payloads.

Source from the content-addressed store, hash-verified

118
119
120class TestExploitListingTools:
121 """Test tools for listing exploits and payloads."""
122
123 @pytest.fixture
124 def mock_client(self):
125 """Fixture providing a mock MSF client."""
126 client = MockMsfRpcClient()
127 with patch('MetasploitMCP.get_msf_client', return_value=client):
128 yield client
129
130 @pytest.mark.asyncio
131 async def test_list_exploits_no_filter(self, mock_client):
132 """Test listing exploits without filter."""
133 mock_client.modules.exploits = [
134 'windows/smb/ms17_010_eternalblue',
135 'unix/ftp/vsftpd_234_backdoor',
136 'windows/http/iis_webdav_upload_asp'
137 ]
138
139 result = await list_exploits()
140
141 assert isinstance(result, list)
142 assert len(result) == 3
143 assert 'windows/smb/ms17_010_eternalblue' in result
144
145 @pytest.mark.asyncio
146 async def test_list_exploits_with_filter(self, mock_client):
147 """Test listing exploits with search term."""
148 mock_client.modules.exploits = [
149 'windows/smb/ms17_010_eternalblue',
150 'unix/ftp/vsftpd_234_backdoor',
151 'windows/smb/ms08_067_netapi'
152 ]
153
154 result = await list_exploits("smb")
155
156 assert isinstance(result, list)
157 assert len(result) == 2
158 assert all('smb' in exploit.lower() for exploit in result)
159
160 @pytest.mark.asyncio
161 async def test_list_exploits_error(self, mock_client):
162 """Test listing exploits with MSF error."""
163 mock_client.modules.exploits = Mock(side_effect=MockMsfRpcError("Connection failed"))
164
165 result = await list_exploits()
166
167 assert isinstance(result, list)
168 assert len(result) == 1
169 assert "Error" in result[0]
170
171 @pytest.mark.asyncio
172 async def test_list_exploits_timeout(self, mock_client):
173 """Test listing exploits with timeout."""
174 import asyncio
175
176 def slow_exploits():
177 # Simulate a slow response that would timeout

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected