Buckets:

download
raw
4.18 kB
"""
VALIDIERUNGS-Test für Gobuster v2 - muss GRÜN sein!
Prüft dass der neue robuste Parser funktioniert
"""
import json
import os
import sys
import pytest
sys.path.insert(0, "/root/.openclaw/workspace/Zen-Ai-Pentest")
from tools.gobuster_integration import GobusterResult, GobusterScanner
class TestGobusterRobustParser:
"""
Diese Tests validieren den NEUEN robusten Parser
Sie müssen ALLE GRÜN sein!
"""
def test_parser_handles_301_moved_permanently(self):
"""
NEU: JSON-Output ignoriert "Moved Permanently" Text
"""
scanner = GobusterScanner()
# Simuliere JSON-Output (wie Gobuster mit --format json liefert)
test_json = "/tmp/test_gobuster_301.json" # nosec B108
with open(test_json, "w") as f:
# JSON-Format: {"Url": "...", "Status": 301, "Length": 178}
f.write(json.dumps({"Url": "/admin", "Status": 301, "Length": 178}) + "\n")
f.write(json.dumps({"Url": "/api", "Status": 200, "Length": 2048}) + "\n")
try:
results = scanner._parse_json_results(test_json)
# Sollte 2 Ergebnisse haben
assert len(results) == 2
# /admin sollte korrekt geparst sein
admin = next(r for r in results if r.url == "/admin")
assert admin.status_code == 301
assert admin.size == 178 # ← KORREKT! Nicht 0!
# /api sollte auch korrekt sein
api = next(r for r in results if r.url == "/api")
assert api.status_code == 200
assert api.size == 2048
finally:
if os.path.exists(test_json):
os.remove(test_json)
def test_soft_404_detection(self):
"""
NEU: Gleiche Size = Soft-404 erkannt
"""
scanner = GobusterScanner()
test_json = "/tmp/test_gobuster_soft404.json" # nosec B108
with open(test_json, "w") as f:
# 3 Pfade mit gleicher Size = Soft-404
f.write(json.dumps({"Url": "/admin", "Status": 200, "Length": 1542}) + "\n")
f.write(json.dumps({"Url": "/config", "Status": 200, "Length": 1542}) + "\n")
f.write(json.dumps({"Url": "/backup", "Status": 200, "Length": 1542}) + "\n")
# 1 echter Pfad mit anderer Size
f.write(json.dumps({"Url": "/api", "Status": 200, "Length": 2048}) + "\n")
try:
results = scanner._parse_json_results(test_json)
# Soft-404s sollten markiert sein
admin = next(r for r in results if r.url == "/admin")
assert admin.is_soft_404, "Sollte als Soft-404 erkannt werden"
api = next(r for r in results if r.url == "/api")
assert not api.is_soft_404, "Sollte KEIN Soft-404 sein"
finally:
if os.path.exists(test_json):
os.remove(test_json)
def test_interesting_results_filter(self):
"""
NEU: Nur interessante Ergebnisse (keine Soft-404s)
"""
scanner = GobusterScanner()
results = [
GobusterResult("/admin", 200, 1542, is_soft_404=True), # Soft-404
GobusterResult("/api", 200, 2048, is_soft_404=False), # Interessant
GobusterResult("/secret", 200, 1542, is_soft_404=True), # Soft-404
]
interesting = scanner.get_interesting_results(results)
# Nur /api sollte übrig bleiben
assert len(interesting) == 1
assert interesting[0].url == "/api"
def test_summary_generation(self):
"""
NEU: Zusammenfassung mit Soft-404-Filter
"""
scanner = GobusterScanner()
results = [
GobusterResult("/a", 200, 100, is_soft_404=True),
GobusterResult("/b", 200, 100, is_soft_404=True),
GobusterResult("/c", 200, 100, is_soft_404=True),
GobusterResult("/api", 200, 500, is_soft_404=False),
]
summary = scanner.generate_summary(results)
assert summary["total"] == 4
assert summary["interesting"] == 1
assert summary["soft_404s_filtered"] == 3
assert len(summary["top_findings"]) == 1

Xet Storage Details

Size:
4.18 kB
·
Xet hash:
c993236793c718071243c64207709c404b1972850441d535a4ba78c1a73f0ad1

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