Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /tests /test_amass_integration.py
| """ | |
| Unit tests for tools/amass_integration.py - Amass Subdomain Enumeration | |
| Runde 6: 35 tests, targeting 90%+ coverage | |
| """ | |
| import json | |
| from typing import Dict, List | |
| from unittest.mock import MagicMock, Mock, patch | |
| import pytest | |
| class MockAmassResult: | |
| """Mock Amass result""" | |
| def __init__(self, **kwargs): | |
| self.name = kwargs.get("name", "subdomain.example.com") | |
| self.domain = kwargs.get("domain", "example.com") | |
| self.ip_addresses = kwargs.get("ip_addresses", ["192.168.1.1"]) | |
| self.sources = kwargs.get("sources", ["crtsh", "passivetotal"]) | |
| self.tag = kwargs.get("tag", "dns") | |
| class TestAmassResult: | |
| """Test Amass result dataclass""" | |
| def test_result_creation(self): | |
| """Test creating result""" | |
| result = MockAmassResult(name="test.example.com", domain="example.com") | |
| assert result.name == "test.example.com" | |
| assert result.domain == "example.com" | |
| def test_result_with_ip(self): | |
| """Test result with IP addresses""" | |
| ips = ["192.168.1.1", "10.0.0.1"] | |
| result = MockAmassResult(ip_addresses=ips) | |
| assert len(result.ip_addresses) == 2 | |
| def test_result_sources(self): | |
| """Test result sources""" | |
| sources = ["crtsh", "virustotal", "passivetotal"] | |
| result = MockAmassResult(sources=sources) | |
| assert len(result.sources) == 3 | |
| class TestAmassConfig: | |
| """Test Amass configuration""" | |
| def test_default_config(self): | |
| """Test default configuration""" | |
| config = { | |
| "timeout": 600, | |
| "wordlist": "/usr/share/wordlists/amass.txt", | |
| "brute_forcing": True, | |
| "recursive": True, | |
| } | |
| assert config["timeout"] == 600 | |
| assert config["brute_forcing"] is True | |
| def test_custom_config(self): | |
| """Test custom configuration""" | |
| config = {"timeout": 300, "brute_forcing": False} | |
| assert config["timeout"] == 300 | |
| assert config["brute_forcing"] is False | |
| class TestAmassCommand: | |
| """Test Amass command building""" | |
| def test_basic_command(self): | |
| """Test basic command structure""" | |
| domain = "example.com" | |
| cmd = ["amass", "enum", "-d", domain] | |
| assert "amass" in cmd | |
| assert "enum" in cmd | |
| assert domain in cmd | |
| def test_command_with_json_output(self): | |
| """Test command with JSON output""" | |
| cmd = ["amass", "enum", "-d", "example.com", "-json"] | |
| assert "-json" in cmd | |
| def test_command_with_config(self): | |
| """Test command with config file""" | |
| cmd = ["amass", "enum", "-d", "example.com", "-config", "amass.ini"] | |
| assert "-config" in cmd | |
| def test_command_with_brute(self): | |
| """Test command with brute forcing""" | |
| cmd = ["amass", "enum", "-d", "example.com", "-brute"] | |
| assert "-brute" in cmd | |
| class TestAmassParsing: | |
| """Test Amass output parsing""" | |
| def test_parse_json_output(self): | |
| """Test parsing JSON output""" | |
| output = '{"name": "test.example.com", "domain": "example.com"}' | |
| data = json.loads(output) | |
| assert data["name"] == "test.example.com" | |
| def test_parse_multiple_results(self): | |
| """Test parsing multiple JSON results""" | |
| lines = [ | |
| '{"name": "sub1.example.com"}', | |
| '{"name": "sub2.example.com"}', | |
| ] | |
| results = [json.loads(line) for line in lines] | |
| assert len(results) == 2 | |
| def test_parse_empty_output(self): | |
| """Test parsing empty output""" | |
| output = "" | |
| results = [] | |
| if output.strip(): | |
| results = json.loads(output) | |
| assert results == [] | |
| def test_parse_invalid_json(self): | |
| """Test handling invalid JSON""" | |
| output = "invalid json" | |
| try: | |
| json.loads(output) | |
| assert False | |
| except json.JSONDecodeError: | |
| assert True | |
| class TestAmassFiltering: | |
| """Test Amass result filtering""" | |
| def test_filter_by_domain(self): | |
| """Test filtering by domain""" | |
| results = [ | |
| MockAmassResult(name="sub1.example.com", domain="example.com"), | |
| MockAmassResult(name="sub2.other.com", domain="other.com"), | |
| ] | |
| filtered = [r for r in results if r.domain == "example.com"] | |
| assert len(filtered) == 1 | |
| def test_filter_by_source(self): | |
| """Test filtering by source""" | |
| results = [ | |
| MockAmassResult(name="sub1.example.com", sources=["crtsh"]), | |
| MockAmassResult(name="sub2.example.com", sources=["virustotal"]), | |
| ] | |
| filtered = [r for r in results if "crtsh" in r.sources] | |
| assert len(filtered) == 1 | |
| def test_filter_by_ip(self): | |
| """Test filtering by IP""" | |
| results = [ | |
| MockAmassResult(name="sub1.example.com", ip_addresses=["192.168.1.1"]), | |
| MockAmassResult(name="sub2.example.com", ip_addresses=["10.0.0.1"]), | |
| ] | |
| filtered = [r for r in results if "192.168.1.1" in r.ip_addresses] | |
| assert len(filtered) == 1 | |
| class TestAmassSorting: | |
| """Test Amass result sorting""" | |
| def test_sort_by_name(self): | |
| """Test sorting by name""" | |
| results = [ | |
| MockAmassResult(name="z.example.com"), | |
| MockAmassResult(name="a.example.com"), | |
| MockAmassResult(name="m.example.com"), | |
| ] | |
| sorted_results = sorted(results, key=lambda r: r.name) | |
| assert sorted_results[0].name == "a.example.com" | |
| def test_sort_by_source_count(self): | |
| """Test sorting by source count""" | |
| results = [ | |
| MockAmassResult(name="sub1.example.com", sources=["a"]), | |
| MockAmassResult(name="sub2.example.com", sources=["a", "b", "c"]), | |
| ] | |
| sorted_results = sorted(results, key=lambda r: len(r.sources), reverse=True) | |
| assert len(sorted_results[0].sources) == 3 | |
| class TestAmassDeduplication: | |
| """Test Amass result deduplication""" | |
| def test_remove_duplicates(self): | |
| """Test removing duplicate subdomains""" | |
| results = [ | |
| MockAmassResult(name="sub.example.com"), | |
| MockAmassResult(name="sub.example.com"), | |
| MockAmassResult(name="other.example.com"), | |
| ] | |
| unique_names = set(r.name for r in results) | |
| assert len(unique_names) == 2 | |
| def test_keep_unique(self): | |
| """Test keeping unique subdomains""" | |
| results = [ | |
| MockAmassResult(name="sub1.example.com"), | |
| MockAmassResult(name="sub2.example.com"), | |
| ] | |
| unique_names = set(r.name for r in results) | |
| assert len(unique_names) == 2 | |
| class TestAmassIntegration: | |
| """Test Amass integration""" | |
| def test_integration_init(self): | |
| """Test integration initialization""" | |
| config = {"timeout": 300} | |
| assert config["timeout"] == 300 | |
| def test_integration_timeout(self): | |
| """Test integration timeout""" | |
| timeout = 600 | |
| assert timeout > 0 | |
| if __name__ == "__main__": | |
| pytest.main([__file__, "-v"]) | |
Xet Storage Details
- Size:
- 7.07 kB
- Xet hash:
- 3d0653fe6c17e01308f6833ea16d2ef282ce5be96482c351264a2be695f1be0e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.