"""What netOrk's discovery scores the driver on. netOrk lowercases the page (title, Server header, body) and matches each rule's pattern as a substring; a port that answers adds its PortSpec weight. AMT names itself in its ``Server`` header on every answer, also the 401 of a page that needs a login. """ from napalm_device_types.base import rules_max_weight from napalm_amt import AmtDriver def _score(text: str) -> float: text = " ".join(text.lower().split()) return sum(rule.weight for rule in AmtDriver.HTTP_FINGERPRINT if rule.pattern in text) def test_amt_ports_are_probed(): assert {(s.scheme, s.port) for s in AmtDriver.PORT_SPECS} == {("http", 16992), ("https", 16993)} def test_server_header_is_recognised(): assert _score("Intel(R) Active Management Technology 11.8.50.3399") >= 10.0 def test_web_ui_landing_page_is_recognised(): page = ( "Intel® Active Management Technology" "Log On" ) assert _score(page) >= 10.0 def test_other_pages_score_nothing(): assert _score("Loading... Web Switch nginx") == 0.0 def test_an_answering_amt_port_with_its_header_is_a_confident_match(): # One of the two ports answers (16992 without TLS, 16993 with); with the header the # normalised score must reach netOrk's "high" (0.7). port = max(s.weight for s in AmtDriver.PORT_SPECS) total = sum(s.weight for s in AmtDriver.PORT_SPECS) + rules_max_weight( AmtDriver.HTTP_FINGERPRINT ) assert (port + _score("Intel(R) Active Management Technology 11.8")) / total >= 0.7