- S4: bump jinja2>=3.1.4, python-multipart>=0.0.18, httpx>=0.28.0
- S5: _detect_ecosystem — DEFAULT_ECOSYSTEM для неизвестных форматов
- S6: harvester — log.exception() вместо log.error()
- S8: _scan_component — urlencode параметров
- P1: scanner — proc.kill() при таймауте
- P3: api_packages — selectinload(Scan.findings), убран N+1
- P4+P5: утечка _url_locks и _llm_locks при early return
- P6: DB reaper — сброс {'status':'analyzing'} при старте
- UI: htmx-пагинация, фильтры не теряют flagged, 404 с layout
- UI: мобильные таблицы overflow-x, полная стата на дашборде
- UI: i18n статусов в _status_badge, urlencode package_name
- 16 новых тестов: analyze endpoint (6), scanner errors (4),
webhook signature (2), llm client (4)
90 lines
2.5 KiB
Python
90 lines
2.5 KiB
Python
"""Tests for Nexus package info extractors."""
|
|
|
|
from guarddog_nexus.core.nexus import (
|
|
extract_go_info,
|
|
extract_npm_info,
|
|
extract_package_info,
|
|
extract_pypi_info,
|
|
)
|
|
|
|
|
|
class TestPyPIExtractor:
|
|
def test_simple(self):
|
|
assert extract_pypi_info("/packages/requests/2.31.0/requests-2.31.0.tar.gz") == (
|
|
"requests",
|
|
"2.31.0",
|
|
)
|
|
|
|
def test_leading_slash(self):
|
|
assert extract_pypi_info("packages/numpy/1.24.0/numpy-1.24.0.tar.gz") == (
|
|
"numpy",
|
|
"1.24.0",
|
|
)
|
|
|
|
def test_non_package(self):
|
|
assert extract_pypi_info("/some/path") is None
|
|
|
|
def test_too_short(self):
|
|
assert extract_pypi_info("/packages/pkg") is None
|
|
|
|
|
|
class TestGoExtractor:
|
|
def test_simple(self):
|
|
assert extract_go_info("packages/github.com/gorilla/mux/@v/v1.8.0.zip") == (
|
|
"github.com/gorilla/mux",
|
|
"v1.8.0",
|
|
)
|
|
|
|
def test_long_module(self):
|
|
assert extract_go_info("/packages/github.com/gin-gonic/gin/@v/v1.9.0.zip") == (
|
|
"github.com/gin-gonic/gin",
|
|
"v1.9.0",
|
|
)
|
|
|
|
def test_no_at_v(self):
|
|
assert extract_go_info("packages/some/pkg/v1.0.0.zip") is None
|
|
|
|
def test_empty(self):
|
|
assert extract_go_info("") is None
|
|
|
|
|
|
class TestNpmExtractor:
|
|
def test_simple(self):
|
|
assert extract_npm_info("packages/lodash/-/lodash-4.17.21.tgz") == (
|
|
"lodash",
|
|
"4.17.21",
|
|
)
|
|
|
|
def test_scoped_package(self):
|
|
# Note: scoped packages have a different path in Nexus
|
|
assert extract_npm_info("packages/@scope/name/-/name-1.0.0.tgz") is None
|
|
|
|
def test_not_packages(self):
|
|
assert extract_npm_info("/other/lodash/-/lodash-4.17.21.tgz") is None
|
|
|
|
def test_short_path(self):
|
|
assert extract_npm_info("packages/lodash") is None
|
|
|
|
|
|
class TestDispatchExtractor:
|
|
def test_pypi(self):
|
|
assert extract_package_info("/packages/requests/2.31.0/requests-2.31.0.tar.gz", "pypi") == (
|
|
"requests",
|
|
"2.31.0",
|
|
)
|
|
|
|
def test_go(self):
|
|
assert extract_package_info("github.com/gorilla/mux/@v/v1.8.0.zip", "go") == (
|
|
"github.com/gorilla/mux",
|
|
"v1.8.0",
|
|
)
|
|
|
|
def test_npm(self):
|
|
assert extract_package_info("packages/lodash/-/lodash-4.17.21.tgz", "npm") == (
|
|
"lodash",
|
|
"4.17.21",
|
|
)
|
|
|
|
def test_unknown_ecosystem(self):
|
|
assert extract_package_info("/packages/pkg/1.0/file.tar.gz", "unknown") == ("pkg", "1.0")
|