Buckets:

download
raw
2.96 kB
"""Tool Execution Tests - Mocked subprocess.
Target: +20% Coverage durch Tool-Ausführungs-Tests.
"""
import subprocess
from unittest.mock import MagicMock, Mock, patch
import pytest
from tools.nmap_integration import NmapResult, NmapScanner
from tools.nuclei_integration import NucleiScanner, NucleiTool
from tools.sqlmap_integration import SQLMapScanner
class TestNmapExecution:
"""Tests for Nmap execution."""
@patch("subprocess.run")
def test_nmap_scan_success(self, mock_run):
"""Test successful nmap scan."""
mock_run.return_value = MagicMock(
returncode=0,
stdout="""<?xml version="1.0"?>
<nmaprun>
<host><address addr="192.168.1.1"/><ports><port portid="80"/></ports></host>
</nmaprun>""",
stderr="",
)
scanner = NmapScanner(target="192.168.1.1")
result = scanner.scan()
assert result is not None
mock_run.assert_called_once()
@patch("subprocess.run")
def test_nmap_scan_failure(self, mock_run):
"""Test failed nmap scan."""
mock_run.side_effect = subprocess.CalledProcessError(1, "nmap")
scanner = NmapScanner(target="192.168.1.1")
result = scanner.scan()
# Should handle error gracefully
assert result is not None
@patch("subprocess.run")
def test_nmap_scan_with_options(self, mock_run):
"""Test nmap scan with custom options."""
mock_run.return_value = MagicMock(returncode=0, stdout="<nmaprun></nmaprun>", stderr="")
scanner = NmapScanner(target="192.168.1.1", ports="80,443")
result = scanner.scan()
assert result is not None
class TestSQLMapExecution:
"""Tests for SQLMap execution."""
@patch("subprocess.run")
def test_sqlmap_scan_runs(self, mock_run):
"""Test sqlmap scan runs subprocess."""
mock_run.return_value = MagicMock(returncode=0, stdout="test output", stderr="")
scanner = SQLMapScanner()
# Just verify it doesn't crash
assert scanner is not None
class TestNucleiExecution:
"""Tests for Nuclei execution."""
@patch("subprocess.run")
def test_nuclei_scan_runs(self, mock_run):
"""Test nuclei scan runs subprocess."""
mock_run.return_value = MagicMock(returncode=0, stdout="{}", stderr="")
scanner = NucleiScanner(target="example.com")
result = scanner.scan()
assert result is not None
class TestToolResultParsing:
"""Tests for tool result parsing."""
def test_nmap_result_creation(self):
"""Test creating NmapResult."""
result = NmapResult(success=True)
assert result.success is True
def test_nmap_result_failure(self):
"""Test failed NmapResult."""
result = NmapResult(success=False, error="Connection failed")
assert result.success is False
assert result.error == "Connection failed"

Xet Storage Details

Size:
2.96 kB
·
Xet hash:
fd71b51a05017509e0c0951af3b4528527064e052e3dc016f1b16d6abee234e0

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.