feat(login-sources): where a device checks a login, and what each place asks for, 4.50.0 (NetOrk/netork#662)
driver / standard (pull_request) Successful in 20s
driver / lint (pull_request) Successful in 17s
driver / types (pull_request) Successful in 1m1s
driver / test (3.12) (pull_request) Successful in 1m22s
driver / test (3.13) (pull_request) Successful in 1m13s
driver / lowest (pull_request) Successful in 43s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m0s
CI / driver (pull_request) Successful in 3m0s
driver / publish (pull_request) Skipped

LoginSourceDict names one source with the device's word for its kind and what
it asks for: password, password_otp, external or unknown. WebLoginAuthDict is
what a driver's get_web_login_auth returns, every source the web interface
tries, in the device's order. SshServerAuthDict takes password_sources and
server_enabled for a platform that writes sshd_config itself.
This commit is contained in:
christianmanivong committed 2026-11-28 08:02:12 +01:00
1 parent 07920941c8
commit d778c805c1
7 files changed
+163 -2

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
"""Where a device checks a login, and what each place asks for (NetOrk/netork#662).
The module is a contract, not a reader: the shapes a driver returns from
``get_web_login_auth`` and, where its platform says it, in ``get_ssh_server_auth``.
These tests pin the vocabulary consumers match on.
"""
from __future__ import annotations
from typing import get_args, get_type_hints
import napalm_device_types
from napalm_device_types.login_sources import (
LOGIN_FACTORS,
LoginFactors,
LoginSourceDict,
WebLoginAuthDict,
)
from napalm_device_types.ssh_server_auth import SshServerAuthDict
def test_the_factor_names_are_the_literal_s():
assert LOGIN_FACTORS == get_args(LoginFactors)
assert LOGIN_FACTORS == ("password", "password_otp", "external", "unknown")
def test_a_source_names_itself_its_kind_and_what_it_asks_for():
assert set(get_type_hints(LoginSourceDict)) == {"name", "kind", "factors"}
def test_a_web_reading_is_its_sources_in_the_device_s_order():
assert set(get_type_hints(WebLoginAuthDict)) == {"sources"}
def test_an_ssh_reading_may_say_where_a_password_is_checked_and_that_sshd_is_off():
optional = SshServerAuthDict.__optional_keys__
assert {"password_sources", "server_enabled"} <= optional
# The keys every OpenSSH reading carries stay required.
assert "password_authentication" in SshServerAuthDict.__required_keys__
def test_the_package_exports_the_shapes():
for name in ("LOGIN_FACTORS", "LoginFactors", "LoginSourceDict", "WebLoginAuthDict"):
assert name in napalm_device_types.__all__
assert hasattr(napalm_device_types, name)