Test the _get_module_object helper function.
| 105 | |
| 106 | |
| 107 | class TestGetModuleObject: |
| 108 | """Test the _get_module_object helper function.""" |
| 109 | |
| 110 | @pytest.fixture |
| 111 | def mock_client(self): |
| 112 | """Fixture providing a mock MSF client.""" |
| 113 | client = Mock() |
| 114 | with patch('MetasploitMCP.get_msf_client', return_value=client): |
| 115 | yield client |
| 116 | |
| 117 | @pytest.mark.asyncio |
| 118 | async def test_get_module_object_success(self, mock_client): |
| 119 | """Test successful module object retrieval.""" |
| 120 | mock_module = Mock() |
| 121 | mock_client.modules.use.return_value = mock_module |
| 122 | |
| 123 | result = await _get_module_object('exploit', 'windows/smb/ms17_010_eternalblue') |
| 124 | |
| 125 | assert result is mock_module |
| 126 | mock_client.modules.use.assert_called_once_with('exploit', 'windows/smb/ms17_010_eternalblue') |
| 127 | |
| 128 | @pytest.mark.asyncio |
| 129 | async def test_get_module_object_full_path(self, mock_client): |
| 130 | """Test module object retrieval with full path.""" |
| 131 | mock_module = Mock() |
| 132 | mock_client.modules.use.return_value = mock_module |
| 133 | |
| 134 | result = await _get_module_object('exploit', 'exploit/windows/smb/ms17_010_eternalblue') |
| 135 | |
| 136 | assert result is mock_module |
| 137 | # Should strip the module type prefix |
| 138 | mock_client.modules.use.assert_called_once_with('exploit', 'windows/smb/ms17_010_eternalblue') |
| 139 | |
| 140 | @pytest.mark.asyncio |
| 141 | async def test_get_module_object_not_found(self, mock_client): |
| 142 | """Test module object retrieval when module not found.""" |
| 143 | mock_client.modules.use.side_effect = KeyError("Module not found") |
| 144 | |
| 145 | with pytest.raises(ValueError, match="not found"): |
| 146 | await _get_module_object('exploit', 'nonexistent/module') |
| 147 | |
| 148 | @pytest.mark.asyncio |
| 149 | async def test_get_module_object_msf_error(self, mock_client): |
| 150 | """Test module object retrieval with MSF RPC error.""" |
| 151 | mock_client.modules.use.side_effect = MockMsfRpcError("RPC Error") |
| 152 | |
| 153 | with pytest.raises(MockMsfRpcError, match="RPC Error"): |
| 154 | await _get_module_object('exploit', 'test/module') |
| 155 | |
| 156 | |
| 157 | class TestSetModuleOptions: |
nothing calls this directly
no outgoing calls
no test coverage detected