test : add unit tests for KnowledgeBase.infer_cpe and _normalize_version helpers

Abierto
#2,335 3 comentarios 0 reacciones 0 asignados Ver en GitHub

@aaniya22 ya está trabajando en esto.

Desde el 2/8/2026.

  • #2340 de @tmdeveloper007 — cerrado sin fusionar

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python
Área
security, testing

Línea de trabajo

Read backend/secuscan/knowledgebase.py and existing tests under testing/backend/unit/ to see how KnowledgeBase is initialized and tested. Add the requested cases in testing/backend/unit/test_knowledgebase_infer_cpe.py, then run that test file. Done means the normalization cases and exact, family, missing-entry, and no-match CPE cases pass; a linked pull request already exists, and the issue says the work is being handled by tmdeveloper007.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary of What Needs to be Done:
Add unit tests for the infer_cpe method and _normalize_version helper in backend/secuscan/knowledgebase.py. infer_cpe returns the best CPE match for a given service/product/version tuple. _normalize_version extracts a normalized version string using a regex. Both are directly importable from the module.

Changes that Need to be Made:

  • Add a new file testing/backend/unit/test_knowledgebase_infer_cpe.py
  • Import KnowledgeBase and _normalize_version from backend.secuscan.knowledgebase
  • For _normalize_version:
    • Test empty string returns ""
    • Test version with patch level: "1.2.3" extracts "1.2.3"
    • Test version with extra text: "nginx-1.18.0" extracts "1.18.0"
    • Test version with only major.minor: "apache2.4" extracts "2.4"
    • Test version with no digits returns lowercased stripped input
    • Test version with leading zeros handling
  • For infer_cpe:
    • Test returns None when no entries loaded
    • Test returns None when no match found
    • Test returns CPE string when exact match found
    • Test falls back to family match when exact version not found

Impact that it would Provide:

  • Improves test coverage for the knowledgebase CPE inference pipeline
  • Validates version normalization edge cases that are easy to get wrong
  • Ensures graceful handling of unknown products/versions

Note: This task is being handled by tmdeveloper007 — please assign to that account when picking it up.

Lenguaje dominante
Python
Estrellas
36
Forks
234
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de utksh1/SecuScan

Todos los issues de utksh1/SecuScan

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.