mirror of
https://github.com/d9pouces/id_configurator.git
synced 2026-11-09 01:47:21 +01:00
refactor: remove unnecessary noqa comments in user tests and user entry creation
Signed-off-by: d9pouces <github@19pouces.net>
This commit is contained in:
@@ -57,7 +57,7 @@ def parse_passwd(content: str) -> list[PasswdEntry]:
|
||||
except ValueError:
|
||||
continue
|
||||
entries.append(
|
||||
PasswdEntry(name=fields[0], uid=uid, home=fields[5], shell=fields[6]) # noqa: B604
|
||||
PasswdEntry(name=fields[0], uid=uid, home=fields[5], shell=fields[6])
|
||||
)
|
||||
return entries
|
||||
|
||||
|
||||
+9
-18
@@ -43,23 +43,17 @@ def test_parse_passwd_skips_malformed_lines() -> None:
|
||||
|
||||
|
||||
def test_has_login_shell_true_for_regular_shell() -> None:
|
||||
entry = PasswdEntry(name="alice", uid=1000, home="/home/alice", shell="/bin/bash") # noqa: B604
|
||||
entry = PasswdEntry(name="alice", uid=1000, home="/home/alice", shell="/bin/bash")
|
||||
assert entry.has_login_shell is True
|
||||
|
||||
|
||||
def test_has_login_shell_false_for_nologin_sync_or_false() -> None:
|
||||
nologin = PasswdEntry(
|
||||
name="daemon",
|
||||
uid=1,
|
||||
home="/usr/sbin",
|
||||
shell="/usr/sbin/nologin", # noqa: B604
|
||||
name="daemon", uid=1, home="/usr/sbin", shell="/usr/sbin/nologin"
|
||||
)
|
||||
sync = PasswdEntry(name="sync", uid=4, home="/bin", shell="/bin/sync") # noqa: B604
|
||||
sync = PasswdEntry(name="sync", uid=4, home="/bin", shell="/bin/sync")
|
||||
false_shell = PasswdEntry(
|
||||
name="nobody",
|
||||
uid=65534,
|
||||
home="/nonexistent",
|
||||
shell="/usr/sbin/false", # noqa: B604
|
||||
name="nobody", uid=65534, home="/nonexistent", shell="/usr/sbin/false"
|
||||
)
|
||||
assert nologin.has_login_shell is False
|
||||
assert sync.has_login_shell is False
|
||||
@@ -67,32 +61,29 @@ def test_has_login_shell_false_for_nologin_sync_or_false() -> None:
|
||||
|
||||
|
||||
def test_is_regular_user_true_for_human_account() -> None:
|
||||
entry = PasswdEntry(name="alice", uid=1000, home="/home/alice", shell="/bin/bash") # noqa: B604
|
||||
entry = PasswdEntry(name="alice", uid=1000, home="/home/alice", shell="/bin/bash")
|
||||
assert entry.is_regular_user() is True
|
||||
|
||||
|
||||
def test_is_regular_user_true_for_root_despite_uid_zero() -> None:
|
||||
entry = PasswdEntry(name="root", uid=0, home="/root", shell="/bin/bash") # noqa: B604
|
||||
entry = PasswdEntry(name="root", uid=0, home="/root", shell="/bin/bash")
|
||||
assert entry.is_regular_user() is True
|
||||
|
||||
|
||||
def test_is_regular_user_false_for_root_with_disabled_shell() -> None:
|
||||
entry = PasswdEntry(name="root", uid=0, home="/root", shell="/usr/sbin/nologin") # noqa: B604
|
||||
entry = PasswdEntry(name="root", uid=0, home="/root", shell="/usr/sbin/nologin")
|
||||
assert entry.is_regular_user() is False
|
||||
|
||||
|
||||
def test_is_regular_user_false_for_disabled_shell_despite_high_uid() -> None:
|
||||
entry = PasswdEntry(
|
||||
name="nobody",
|
||||
uid=65534,
|
||||
home="/nonexistent",
|
||||
shell="/usr/sbin/false", # noqa: B604
|
||||
name="nobody", uid=65534, home="/nonexistent", shell="/usr/sbin/false"
|
||||
)
|
||||
assert entry.is_regular_user() is False
|
||||
|
||||
|
||||
def test_is_regular_user_honors_custom_uid_min() -> None:
|
||||
entry = PasswdEntry(name="svc", uid=500, home="/home/svc", shell="/bin/bash") # noqa: B604
|
||||
entry = PasswdEntry(name="svc", uid=500, home="/home/svc", shell="/bin/bash")
|
||||
assert entry.is_regular_user(uid_min=1000) is False
|
||||
assert entry.is_regular_user(uid_min=100) is True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user