41 lines
991 B
Python
41 lines
991 B
Python
"""Shared test fixtures and the offline searchsploit search function.
|
|
|
|
The injectable ``fixture_search_fn`` reads canned ``searchsploit --json`` output
|
|
from ``tests/fixtures/searchsploit/index.json`` so the whole grounding path is
|
|
exercised with zero network and no searchsploit binary.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from recon_triage.schema import ExploitDBMatch
|
|
from recon_triage.tools import searchsploit
|
|
|
|
FIXTURES = Path(__file__).parent / "fixtures"
|
|
|
|
|
|
def make_fixture_search_fn():
|
|
index = json.loads((FIXTURES / "searchsploit" / "index.json").read_text())
|
|
|
|
def _search(term: str) -> list[ExploitDBMatch]:
|
|
doc = index.get(term)
|
|
if doc is None:
|
|
return []
|
|
return searchsploit.normalize(json.dumps(doc), query=term)
|
|
|
|
return _search
|
|
|
|
|
|
@pytest.fixture
|
|
def fixtures_dir() -> Path:
|
|
return FIXTURES
|
|
|
|
|
|
@pytest.fixture
|
|
def fixture_search_fn():
|
|
return make_fixture_search_fn()
|