feat(local-accounts): remove_local_account_keys can clear the password too
driver / lint (pull_request) Successful in 16s
driver / standard (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m1s
driver / test (3.13) (pull_request) Successful in 1m15s
driver / test (3.12) (pull_request) Successful in 1m18s
driver / lowest (pull_request) Successful in 39s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m36s
driver / publish (pull_request) Skipped
driver / lint (pull_request) Successful in 16s
driver / standard (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m1s
driver / test (3.13) (pull_request) Successful in 1m15s
driver / test (3.12) (pull_request) Successful in 1m18s
driver / lowest (pull_request) Successful in 39s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m36s
driver / publish (pull_request) Skipped
A person who deletes their key loses the password that went with it in netOrk, but the devices kept it, and sudo with it. remove_local_account_keys(name, keys, clear_password=True) takes the keys, the password and sudo in one call; the account stays open. Each step runs when another failed. See NetOrk/netork#2033.
This commit is contained in:
1 parent
c967635cba
commit
ac49e2b5d4
3 files changed
+91
-8
No files matched your search
@@ -981,3 +981,69 @@ def test_a_driver_with_its_own_key_store_drops_keys_there(host: _Host) -> None:
|
||||
removed = driver.remove_local_account_keys("alice", [ALICE_KEY])
|
||||
assert removed["success"], removed["output"]
|
||||
assert driver.store == {"alice": []}
|
||||
|
||||
|
||||
# -- removing keys and the password at once (NetOrk/netork#2033) ------------------------
|
||||
|
||||
|
||||
def test_removing_keys_with_clear_password_takes_the_password_and_sudo_too(
|
||||
host: _Host, driver: _Driver
|
||||
) -> None:
|
||||
"""A person who deleted their key: the password netOrk no longer knows goes too, and
|
||||
sudo, which asks for it. The account stays open, its other keys stay."""
|
||||
_add_alice(host, keys=f"{ALICE_KEY}\n{OWN_KEY}\n")
|
||||
host.files["/etc/sudoers.d/80-account-alice"] = sudoers_rule("alice")
|
||||
|
||||
result = driver.remove_local_account_keys("alice", [ALICE_KEY], clear_password=True)
|
||||
|
||||
assert result["success"], result["output"]
|
||||
assert [s["step"] for s in result["steps"]] == ["keys", "password", "sudo"]
|
||||
assert _alice_keys(host) == f"{OWN_KEY}\n"
|
||||
a = host.accounts["alice"]
|
||||
assert a.password is None and not a.locked and a.groups == ["alice"]
|
||||
assert "/etc/sudoers.d/80-account-alice" not in host.files
|
||||
account = result["account"]
|
||||
assert account is not None and not account["admin"] and not account["locked"]
|
||||
|
||||
|
||||
def test_removing_keys_with_clear_password_runs_each_step_when_one_failed(
|
||||
host: _Host, driver: _Driver
|
||||
) -> None:
|
||||
_add_alice(host, keys=f"{ALICE_KEY}\n")
|
||||
host.files["/etc/sudoers.d/80-account-alice"] = sudoers_rule("alice")
|
||||
host.failing.add("clearpw")
|
||||
|
||||
result = driver.remove_local_account_keys("alice", [ALICE_KEY], clear_password=True)
|
||||
|
||||
assert not result["success"]
|
||||
steps = {s["step"]: s for s in result["steps"]}
|
||||
assert steps["keys"]["ok"] and not steps["password"]["ok"]
|
||||
# sudo does not wait for the password: without a known password it has to go anyway.
|
||||
assert steps["sudo"]["ok"]
|
||||
assert "/etc/sudoers.d/80-account-alice" not in host.files
|
||||
assert _alice_keys(host) == ""
|
||||
|
||||
|
||||
def test_removing_keys_with_a_driver_that_cannot_clear_a_password_says_so(host: _Host) -> None:
|
||||
class _NoClear(_Driver):
|
||||
_account_clear_password = LocalAccountsMixin._account_clear_password
|
||||
|
||||
_add_alice(host, keys=f"{ALICE_KEY}\n")
|
||||
|
||||
result = _NoClear(host).remove_local_account_keys("alice", [ALICE_KEY], clear_password=True)
|
||||
|
||||
password = next(s for s in result["steps"] if s["step"] == "password")
|
||||
assert not password["ok"] and "cannot remove" in password["output"]
|
||||
assert not result["success"]
|
||||
|
||||
|
||||
def test_removing_keys_of_an_account_that_is_not_there_clears_nothing(driver: _Driver) -> None:
|
||||
result = driver.remove_local_account_keys("bob", [ALICE_KEY], clear_password=True)
|
||||
|
||||
assert not result["success"] and "no account" in result["output"]
|
||||
assert [s["step"] for s in result["steps"]] == ["keys"]
|
||||
|
||||
|
||||
def test_clear_password_is_a_keyword(driver: _Driver) -> None:
|
||||
with pytest.raises(TypeError):
|
||||
driver.remove_local_account_keys("alice", [ALICE_KEY], True) # type: ignore[misc]
|
||||
Reference in new issue
Block a user