"""Tests para identify_port_service."""

from identify_port_service import identify_port_service


def test_port_22_es_ssh():
    result = identify_port_service(22)
    assert result == {
        "port": 22,
        "proto": "tcp",
        "service": "ssh",
        "description": "Secure Shell",
        "known": True,
    }


def test_port_443_es_https():
    result = identify_port_service(443)
    assert result["service"] == "https"
    assert result["known"] is True
    assert result["proto"] == "tcp"


def test_port_3306_es_mysql():
    result = identify_port_service(3306)
    assert result["service"] == "mysql"
    assert result["known"] is True


def test_port_53_udp_es_dns():
    result = identify_port_service(53, "udp")
    assert result["service"] == "dns"
    assert result["proto"] == "udp"
    assert result["known"] is True


def test_puerto_fuera_de_rango_es_invalid():
    result = identify_port_service(99999)
    assert result["service"] == "invalid"
    assert result["known"] is False
    assert result["description"] == ""
    # negativo también
    assert identify_port_service(-1)["service"] == "invalid"


def test_puerto_desconocido_known_false():
    # Puerto válido pero no catalogado en la tabla.
    result = identify_port_service(40404)
    assert result["service"] == "unknown"
    assert result["known"] is False
    assert result["description"] == ""


def test_proto_invalido_es_invalid():
    result = identify_port_service(80, "sctp")
    assert result["service"] == "invalid"
    assert result["known"] is False


def test_proto_se_normaliza_mayusculas():
    result = identify_port_service(22, "TCP")
    assert result["proto"] == "tcp"
    assert result["service"] == "ssh"
    assert result["known"] is True


def test_determinismo_misma_entrada_misma_salida():
    a = identify_port_service(8080, "tcp")
    b = identify_port_service(8080, "tcp")
    assert a == b
    assert a["service"] == "http-proxy"
