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

Class TestSetModuleOptions

tests/test_helpers.py:157–208  ·  view source on GitHub ↗

Test the _set_module_options helper function.

Source from the content-addressed store, hash-verified

155
156
157class TestSetModuleOptions:
158 """Test the _set_module_options helper function."""
159
160 @pytest.fixture
161 def mock_module(self):
162 """Fixture providing a mock module object."""
163 module = Mock()
164 module.fullname = 'exploit/test/module'
165 module.__setitem__ = Mock()
166 return module
167
168 @pytest.mark.asyncio
169 async def test_set_module_options_basic(self, mock_module):
170 """Test basic option setting."""
171 options = {'RHOSTS': '192.168.1.1', 'RPORT': '80'}
172
173 await _set_module_options(mock_module, options)
174
175 # Should be called twice, once for each option
176 assert mock_module.__setitem__.call_count == 2
177 mock_module.__setitem__.assert_any_call('RHOSTS', '192.168.1.1')
178 mock_module.__setitem__.assert_any_call('RPORT', 80) # Type conversion: '80' -> 80
179
180 @pytest.mark.asyncio
181 async def test_set_module_options_type_conversion(self, mock_module):
182 """Test option setting with type conversion."""
183 options = {
184 'RPORT': '80', # String number -> int
185 'SSL': 'true', # String boolean -> bool
186 'VERBOSE': 'false', # String boolean -> bool
187 'THREADS': '10' # String number -> int
188 }
189
190 await _set_module_options(mock_module, options)
191
192 # Verify type conversions
193 calls = mock_module.__setitem__.call_args_list
194 call_dict = {call[0][0]: call[0][1] for call in calls}
195
196 assert call_dict['RPORT'] == 80
197 assert call_dict['SSL'] is True
198 assert call_dict['VERBOSE'] is False
199 assert call_dict['THREADS'] == 10
200
201 @pytest.mark.asyncio
202 async def test_set_module_options_error(self, mock_module):
203 """Test option setting with error."""
204 mock_module.__setitem__.side_effect = KeyError("Invalid option")
205 options = {'INVALID_OPT': 'value'}
206
207 with pytest.raises(ValueError, match="Failed to set option"):
208 await _set_module_options(mock_module, options)
209
210
211class TestGetMsfConsole:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected