Skip to content

fix: validar RUT explícito en create_link y rechazar formatos inválidos - #28

Open
Billyflin wants to merge 1 commit into
LibreDTE:masterfrom
Billyflin:fix/rut-explicito-validacion
Open

Billyflin wants to merge 1 commit into
LibreDTE:masterfrom
Billyflin:fix/rut-explicito-validacion

Conversation

@Billyflin

Copy link
Copy Markdown

Resumen

Corrige dos casos borde en el manejo y validación del RUT en ApiClient:

  1. create_link ignoraba valores explícitos falsy ('', 0, False) cuando self.rut estaba configurado

    • A diferencia de set_contribuyente (rut if rut is not None else ...), create_link usaba valor = rut or self.rut.
    • Si el cliente tenía un contribuyente activo (self.rut) y se llamaba create_link(recurso, rut='') o create_link(recurso, rut=0), se omitía silenciosamente el argumento inválido y se generaba el enlace para self.rut en vez de lanzar ApiException.
  2. Validación consistente del RUT en _parsear_rut (set_contribuyente y create_link)

    • En Python bool hereda de int, por lo que set_contribuyente(True) asignaba self.rut = 1.
    • Valores no positivos (0, -76192083) o textos mal formados con guion ('76192083-', '1-2-3') eran aceptados al hacer split('-')[0] y convertir con int(...).
    • Se centraliza la validación en _parsear_rut, exigiendo entero positivo (no bool) y dígito verificador válido (0-9 o K/k) cuando viene separado por -.

Verificación

  • Nuevas pruebas unitarias en tests/api_client/test_configuracion.py y tests/api_client/test_url.py.
  • python -m unittest discover -s tests/api_client -v: 31 passed.
  • ruff check . y mypy libredte tests: 0 errores / 0 advertencias.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant