feat(windows): clean_system_identity for values read without the DMI files, UserDict.sid
clean_system_identity applies parse_system_identity's placeholder rules to values a host reads through an interface of its own (Windows' CIM classes, NetOrk/netork#2888); parse_system_identity now uses it. UserDict gains an optional sid beside the int uid (NetOrk/netork#2889).
This commit is contained in:
1 parent
2df46741f2
commit
5c2bfb7dfa
7 files changed
+146
-11
No files matched your search
@@ -0,0 +1,24 @@
|
||||
"""``UserDict``: a local OS account, as ``get_os_users`` lists it (NetOrk/netork#2889).
|
||||
|
||||
POSIX numbers each account with a uid; Windows names it with a security identifier
|
||||
(SID). The uid stays an int for every driver, and a driver that has a SID gives it
|
||||
beside it, so nothing that reads ``uid`` today changes.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import get_type_hints
|
||||
|
||||
from napalm_device_types.models import UserDict
|
||||
|
||||
|
||||
def test_a_posix_account_needs_no_sid():
|
||||
assert UserDict.__required_keys__ == frozenset(
|
||||
{"username", "uid", "gid", "home", "shell", "groups"}
|
||||
)
|
||||
|
||||
|
||||
def test_an_account_may_carry_its_sid_beside_its_uid():
|
||||
assert get_type_hints(UserDict)["sid"] is str
|
||||
assert "sid" in UserDict.__optional_keys__
|
||||
assert get_type_hints(UserDict)["uid"] is int
|
||||
@@ -7,6 +7,7 @@ import pytest
|
||||
from napalm_device_types import (
|
||||
SYSTEM_IDENTITY_COMMAND,
|
||||
SystemIdentityMixin,
|
||||
clean_system_identity,
|
||||
is_placeholder_identity,
|
||||
parse_system_identity,
|
||||
)
|
||||
@@ -153,6 +154,62 @@ def test_terminal_noise_around_the_frame_is_ignored():
|
||||
assert parse_system_identity("\x1b[?2004h" + _out(UUID, "S1", "B1"))["board_serial"] == "B1"
|
||||
|
||||
|
||||
# ── values read some other way ────────────────────────────────────────────────
|
||||
|
||||
|
||||
def _values(**changes: str) -> dict[str, str]:
|
||||
values = {
|
||||
"system_uuid": UUID,
|
||||
"product_serial": "S1",
|
||||
"board_serial": "B1",
|
||||
"bios_vendor": "Dell Inc.",
|
||||
"bios_version": "2.19.0",
|
||||
"bios_date": "2023-08-14",
|
||||
}
|
||||
return {**values, **changes}
|
||||
|
||||
|
||||
def test_values_read_without_the_dmi_files_are_cleaned_the_same_way():
|
||||
# A host that reads its SMBIOS tables through its own interface (Windows' CIM classes)
|
||||
# hands the values over one by one; the placeholders are the same vendors'.
|
||||
assert clean_system_identity(**_values()) == {
|
||||
"system_uuid": "31303043-534d-c40c-7a72-6f1300000000",
|
||||
"product_serial": "S1",
|
||||
"board_serial": "B1",
|
||||
"bios_vendor": "Dell Inc.",
|
||||
"bios_version": "2.19.0",
|
||||
"bios_date": "2023-08-14",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"field", ["system_uuid", "product_serial", "board_serial"], ids=["uuid", "product", "board"]
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"value",
|
||||
["To be filled by O.E.M.", "Default string", "00000000-0000-0000-0000-000000000000", " "],
|
||||
)
|
||||
def test_a_placeholder_identity_value_reads_as_empty(field, value):
|
||||
assert clean_system_identity(**_values(**{field: value}))[field] == ""
|
||||
|
||||
|
||||
def test_a_firmware_text_is_cleaned_as_the_dmi_files_are():
|
||||
identity = clean_system_identity(**_values(bios_vendor="Default string", bios_version="1"))
|
||||
assert identity["bios_vendor"] == ""
|
||||
assert identity["bios_version"] == "1"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("date", ["", "08/14/2023", "2023-13-01", "2023-08-14T00:00:00"])
|
||||
def test_a_firmware_date_must_be_an_iso_date(date):
|
||||
assert clean_system_identity(**_values(bios_date=date))["bios_date"] == ""
|
||||
|
||||
|
||||
def test_values_are_stripped():
|
||||
identity = clean_system_identity(**_values(board_serial=" B1 ", bios_date=" 2023-08-14 "))
|
||||
assert identity["board_serial"] == "B1"
|
||||
assert identity["bios_date"] == "2023-08-14"
|
||||
|
||||
|
||||
# ── the mixin ─────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user