Files
napalm-proxmox/tests/test_users.py
T
Christian Manivong 4ee74e4b3d fix(users): list real login accounts and read admins from the ACL
The passwd filter's precedence was inverted: it listed uid < 1000
(daemon, bin, ...) and skipped regular users. The level check looked
for "Administrator" in the user record, which never names roles. The
level now comes from /access/acl (Administrator on /, by user or
group), root@pam always 15.

Closes #19
2026-11-01 21:50:16 +01:00

67 lines
2.2 KiB
Python

"""get_users: Proxmox users with their level, and the node's login accounts (#19)."""
from __future__ import annotations
from unittest.mock import patch
PASSWD = """\
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
alice:x:1000:1000:Alice:/home/alice:/bin/bash
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
"""
# GET /access/acl: who holds which role where.
ACL = [
{"path": "/", "roleid": "Administrator", "type": "user", "ugid": "admin@pve", "propagate": 1},
{"path": "/", "roleid": "Administrator", "type": "group", "ugid": "ops", "propagate": 1},
{"path": "/vms/100", "roleid": "Administrator", "type": "user", "ugid": "vm@pve"},
{"path": "/", "roleid": "PVEAuditor", "type": "user", "ugid": "audit@pve", "propagate": 1},
]
USERS = [
{"userid": "root@pam", "groups": ""},
{"userid": "admin@pve", "groups": ""},
{"userid": "bob@pve", "groups": "ops,dev"},
{"userid": "vm@pve", "groups": ""},
{"userid": "audit@pve", "groups": ""},
]
def _users(driver, passwd=PASSWD):
driver._api.access.users.get.return_value = USERS
driver._api.access.acl.get.return_value = ACL
with patch.object(driver, "_exec_ssh_command", return_value=passwd):
return driver.get_users()
class TestLocalAccounts:
def test_root_and_real_users_not_system_accounts(self, driver):
result = _users(driver)
assert result["root"]["level"] == 15
assert "alice" in result
for system in ("daemon", "bin", "www-data", "nobody"):
assert system not in result
class TestProxmoxUsers:
def test_administrator_on_the_whole_datacenter_is_level_15(self, driver):
result = _users(driver)
assert result["admin@pve"]["level"] == 15
def test_administrator_through_a_group_is_level_15(self, driver):
assert _users(driver)["bob@pve"]["level"] == 15
def test_root_at_pam_is_always_level_15(self, driver):
assert _users(driver)["root@pam"]["level"] == 15
def test_another_role_or_a_narrower_path_is_level_1(self, driver):
result = _users(driver)
assert result["audit@pve"]["level"] == 1
assert result["vm@pve"]["level"] == 1