mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
fix(platform-admin): create platformadmin on existing installs in six roles
Matomo, SuiteCRM, WordPress, MediaWiki, Joomla and Listmonk only realigned an existing admin login, so existing installs without platformadmin stopped the deploy. Each admin step now creates the account next to the old admin when it is missing and realigns it when it is an admin. A platformadmin that exists without admin rights fails with its cause and remedy. MediaWiki alone promotes it, and only while SSO is the sole login and its confirmed email matches: there the account can only come from Keycloak's preferred_username. SuiteCRM keeps native login under SAML and lets users rename themselves, Listmonk's OIDC never creates that login, and Joomla's Keycloak plugin rewrites groups on every sign-in, so none of them promote. Matomo, SuiteCRM and WordPress write through php://stdout and php://stderr: PHP 8.2 defines no STDOUT/STDERR for code fed on stdin. MediaWiki's account probe lives in files/sql/admin_state.sql and receives name and email as hex literals. A lint checks that each role's admin step creates a missing admin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
104c140a0b
commit
cc70de8f28
31 files changed
+2393
-128
No files matched your search
@@ -0,0 +1,89 @@
|
||||
import unittest
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
|
||||
from plugins.filter.platform_admin import FilterModule
|
||||
|
||||
LOGIN = "platformadmin"
|
||||
EMAIL = "platformadmin@example.org"
|
||||
LEGACY = {"login": "administrator", "email": "administrator@example.org", "admin": True}
|
||||
|
||||
|
||||
def account(login: str, email: str, admin: bool) -> dict:
|
||||
return {"login": login, "email": email, "admin": admin}
|
||||
|
||||
|
||||
class TestPlatformAdminPlan(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.plan = FilterModule().filters()["platform_admin_plan"]
|
||||
|
||||
def test_absent_login_next_to_an_administrator_is_created(self) -> None:
|
||||
self.assertEqual(self.plan([LEGACY], LOGIN, EMAIL, "App", True), "create")
|
||||
|
||||
def test_present_administrator_is_realigned(self) -> None:
|
||||
accounts = [LEGACY, account(LOGIN, EMAIL, True)]
|
||||
self.assertEqual(self.plan(accounts, LOGIN, EMAIL, "App", True), "realign")
|
||||
|
||||
def test_present_administrator_is_realigned_even_when_its_email_differs(
|
||||
self,
|
||||
) -> None:
|
||||
accounts = [
|
||||
account("other", EMAIL, True),
|
||||
account(LOGIN, "old@example.org", True),
|
||||
]
|
||||
self.assertEqual(self.plan(accounts, LOGIN, EMAIL, "App", True), "realign")
|
||||
|
||||
def test_app_without_administrator_fails(self) -> None:
|
||||
with self.assertRaisesRegex(AnsibleFilterError, "App has no administrator"):
|
||||
self.plan(
|
||||
[account("reader", "r@example.org", False)], LOGIN, EMAIL, "App", True
|
||||
)
|
||||
|
||||
def test_app_without_any_account_fails(self) -> None:
|
||||
with self.assertRaisesRegex(AnsibleFilterError, "no administrator"):
|
||||
self.plan([], LOGIN, EMAIL, "App", True)
|
||||
|
||||
def test_email_held_by_another_account_fails_naming_every_holder(self) -> None:
|
||||
accounts = [
|
||||
LEGACY,
|
||||
account("zed", "PlatformAdmin@Example.org", False),
|
||||
account("amy", EMAIL, True),
|
||||
]
|
||||
with self.assertRaisesRegex(
|
||||
AnsibleFilterError, "held by the App account amy, zed"
|
||||
):
|
||||
self.plan(accounts, LOGIN, EMAIL, "App", True)
|
||||
|
||||
def test_non_administrator_holding_the_login_is_not_promoted(self) -> None:
|
||||
accounts = [LEGACY, account(LOGIN, EMAIL, False)]
|
||||
with self.assertRaisesRegex(AnsibleFilterError, "not promoted"):
|
||||
self.plan(accounts, LOGIN, EMAIL, "App", True)
|
||||
|
||||
def test_case_insensitive_app_matches_the_login_in_any_case(self) -> None:
|
||||
accounts = [LEGACY, account("PlatformAdmin", EMAIL, False)]
|
||||
with self.assertRaisesRegex(
|
||||
AnsibleFilterError, "'PlatformAdmin' is no administrator"
|
||||
):
|
||||
self.plan(accounts, LOGIN, EMAIL, "App", False)
|
||||
|
||||
def test_case_sensitive_app_treats_another_case_as_another_login(self) -> None:
|
||||
accounts = [LEGACY, account("PlatformAdmin", "pa@example.org", False)]
|
||||
self.assertEqual(self.plan(accounts, LOGIN, EMAIL, "App", True), "create")
|
||||
|
||||
def test_malformed_account_is_refused(self) -> None:
|
||||
with self.assertRaisesRegex(AnsibleFilterError, "boolean admin"):
|
||||
self.plan(
|
||||
[{"login": LOGIN, "email": EMAIL, "admin": "yes"}],
|
||||
LOGIN,
|
||||
EMAIL,
|
||||
"App",
|
||||
True,
|
||||
)
|
||||
|
||||
def test_accounts_that_are_no_list_are_refused(self) -> None:
|
||||
with self.assertRaisesRegex(AnsibleFilterError, "as a list"):
|
||||
self.plan({"login": LOGIN}, LOGIN, EMAIL, "App", True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,277 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import sys
|
||||
import unicodedata
|
||||
import unittest
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
|
||||
from plugins.filter.platform_admin import platform_admin_plan
|
||||
|
||||
from . import PROJECT_ROOT
|
||||
|
||||
|
||||
def _load_module(rel_path: str, name: str):
|
||||
path = PROJECT_ROOT / rel_path
|
||||
spec = importlib.util.spec_from_file_location(name, str(path))
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
assert spec and spec.loader
|
||||
sys.modules[name] = mod
|
||||
spec.loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
|
||||
MODULE = _load_module(
|
||||
"roles/web-app-joomla/filter_plugins/joomla_users.py", "joomla_users"
|
||||
)
|
||||
|
||||
HEADER = ["ID", "Username", "Name", "Email", "Blocked", "Groups"]
|
||||
LEGACY = [
|
||||
"42",
|
||||
"administrator",
|
||||
"Administrator Example",
|
||||
"administrator@example.org",
|
||||
"0",
|
||||
"Registered, Super Users",
|
||||
]
|
||||
READER = ["43", "biber", "Biber Test", "biber@example.org", "0", "Registered"]
|
||||
|
||||
|
||||
def display_width(text: str) -> int:
|
||||
"""Count the terminal columns Symfony's Helper::width() gives ``text``.
|
||||
|
||||
Args:
|
||||
text: one table cell.
|
||||
|
||||
Returns:
|
||||
2 per East Asian wide or fullwidth character, 0 per combining mark or
|
||||
format character, 1 per other character.
|
||||
"""
|
||||
width = 0
|
||||
for char in text:
|
||||
if unicodedata.combining(char) or unicodedata.category(char) in {
|
||||
"Mn",
|
||||
"Me",
|
||||
"Cf",
|
||||
}:
|
||||
continue
|
||||
width += 2 if unicodedata.east_asian_width(char) in {"W", "F"} else 1
|
||||
return width
|
||||
|
||||
|
||||
def table(border: str, lines: list[str]) -> str:
|
||||
"""Wrap rendered rows in the title and borders of user:list.
|
||||
|
||||
Args:
|
||||
border: the dash line above, between and below the rows.
|
||||
lines: the header row followed by every account row.
|
||||
|
||||
Returns:
|
||||
The stdout of ``user:list``.
|
||||
"""
|
||||
body = [border, lines[0], border, *lines[1:], border]
|
||||
return "\nList Users\n==========\n\n" + "\n".join(body) + "\n\n"
|
||||
|
||||
|
||||
def user_list(rows: list[list[str]]) -> str:
|
||||
"""Render ``rows`` the way SymfonyStyle::table() does for user:list.
|
||||
|
||||
Args:
|
||||
rows: the cells of every account, in the order of ``HEADER``.
|
||||
|
||||
Returns:
|
||||
The stdout of ``user:list``, every cell padded to its column's
|
||||
display width as Symfony's Table::renderCell() pads it.
|
||||
"""
|
||||
widths = [
|
||||
max(display_width(row[column]) for row in [HEADER, *rows]) + 2
|
||||
for column in range(len(HEADER))
|
||||
]
|
||||
border = " " + " ".join("-" * width for width in widths) + " "
|
||||
|
||||
def line(row: list[str]) -> str:
|
||||
cells = (
|
||||
f" {cell}" + " " * (width - 1 - display_width(cell))
|
||||
for cell, width in zip(row, widths, strict=True)
|
||||
)
|
||||
return " " + " ".join(cells) + " "
|
||||
|
||||
return table(border, [line(row) for row in [HEADER, *rows]])
|
||||
|
||||
|
||||
def padded(*cells: tuple[str, int]) -> str:
|
||||
"""Render one row from hand-counted trailing pads.
|
||||
|
||||
Args:
|
||||
cells: ``(text, pad)`` per column, ``pad`` being the spaces after it.
|
||||
|
||||
Returns:
|
||||
The row as Symfony prints it.
|
||||
"""
|
||||
return " " + " ".join(f" {text}{' ' * pad}" for text, pad in cells) + " "
|
||||
|
||||
|
||||
class TestJoomlaUserAccounts(unittest.TestCase):
|
||||
def test_every_row_becomes_an_account_with_its_super_user_membership(self) -> None:
|
||||
self.assertEqual(
|
||||
MODULE.joomla_user_accounts(user_list([LEGACY, READER])),
|
||||
[
|
||||
{
|
||||
"login": "administrator",
|
||||
"email": "administrator@example.org",
|
||||
"admin": True,
|
||||
},
|
||||
{"login": "biber", "email": "biber@example.org", "admin": False},
|
||||
],
|
||||
)
|
||||
|
||||
def test_cjk_and_decomposed_names_keep_the_following_columns_aligned(
|
||||
self,
|
||||
) -> None:
|
||||
output = table(
|
||||
" ---- ---------- ---------- -------------------- --------- ------------- ",
|
||||
[
|
||||
padded(
|
||||
("ID", 1),
|
||||
("Username", 1),
|
||||
("Name", 5),
|
||||
("Email", 14),
|
||||
("Blocked", 1),
|
||||
("Groups", 6),
|
||||
),
|
||||
padded(
|
||||
("48", 1),
|
||||
("yamada", 3),
|
||||
("山田太郎", 1),
|
||||
("yamada@example.org", 1),
|
||||
("0", 7),
|
||||
("Super Users", 1),
|
||||
),
|
||||
padded(
|
||||
("49", 1),
|
||||
("renee", 4),
|
||||
("Renée", 4),
|
||||
("renee@example.org", 2),
|
||||
("0", 7),
|
||||
("Registered", 2),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
MODULE.joomla_user_accounts(output),
|
||||
[
|
||||
{"login": "yamada", "email": "yamada@example.org", "admin": True},
|
||||
{"login": "renee", "email": "renee@example.org", "admin": False},
|
||||
],
|
||||
)
|
||||
|
||||
def test_a_wide_username_is_read_whole(self) -> None:
|
||||
row = ["50", "山田", "Yamada", "y@example.org", "0", "Super Users"]
|
||||
self.assertEqual(
|
||||
MODULE.joomla_user_accounts(user_list([row])),
|
||||
[{"login": "山田", "email": "y@example.org", "admin": True}],
|
||||
)
|
||||
|
||||
def test_a_group_title_merely_containing_super_users_is_no_membership(self) -> None:
|
||||
row = ["44", "editor", "Editor", "editor@example.org", "0", "Super Users Lite"]
|
||||
self.assertEqual(
|
||||
MODULE.joomla_user_accounts(user_list([row]))[0]["admin"], False
|
||||
)
|
||||
|
||||
def test_output_without_a_table_is_refused(self) -> None:
|
||||
with self.assertRaisesRegex(AnsibleFilterError, "no account table"):
|
||||
MODULE.joomla_user_accounts("Error: could not connect to the database\n")
|
||||
|
||||
def test_a_table_with_other_columns_is_refused(self) -> None:
|
||||
output = user_list([LEGACY]).replace("Blocked", "Locked ")
|
||||
with self.assertRaisesRegex(AnsibleFilterError, "expected"):
|
||||
MODULE.joomla_user_accounts(output)
|
||||
|
||||
|
||||
class TestJoomlaPlatformAdminPlan(unittest.TestCase):
|
||||
def plan(self, rows: list[list[str]]) -> str:
|
||||
return platform_admin_plan(
|
||||
MODULE.joomla_user_accounts(user_list(rows)),
|
||||
"platformadmin",
|
||||
"platformadmin@example.org",
|
||||
"Joomla",
|
||||
False,
|
||||
)
|
||||
|
||||
def test_absent_platform_administrator_is_created_next_to_a_super_user(
|
||||
self,
|
||||
) -> None:
|
||||
self.assertEqual(self.plan([LEGACY, READER]), "create")
|
||||
|
||||
def test_present_super_user_is_realigned(self) -> None:
|
||||
row = [
|
||||
"45",
|
||||
"platformadmin",
|
||||
"Platformadmin",
|
||||
"platformadmin@example.org",
|
||||
"0",
|
||||
"Super Users",
|
||||
]
|
||||
self.assertEqual(self.plan([LEGACY, row]), "realign")
|
||||
|
||||
def test_site_without_a_super_user_fails(self) -> None:
|
||||
with self.assertRaisesRegex(AnsibleFilterError, "Joomla has no administrator"):
|
||||
self.plan([READER])
|
||||
|
||||
def test_email_held_by_another_account_fails_naming_it(self) -> None:
|
||||
row = [
|
||||
"46",
|
||||
"someone",
|
||||
"Someone",
|
||||
"PlatformAdmin@example.org",
|
||||
"0",
|
||||
"Registered",
|
||||
]
|
||||
with self.assertRaisesRegex(
|
||||
AnsibleFilterError, "held by the Joomla account someone"
|
||||
):
|
||||
self.plan([LEGACY, row])
|
||||
|
||||
def test_registered_holder_of_the_username_in_another_case_is_not_promoted(
|
||||
self,
|
||||
) -> None:
|
||||
row = ["47", "PlatformAdmin", "PA", "pa@example.org", "0", "Registered"]
|
||||
with self.assertRaisesRegex(AnsibleFilterError, "not promoted"):
|
||||
self.plan([LEGACY, row])
|
||||
|
||||
|
||||
ADD_FAILED = "\nAdd User\n========\n\n [ERROR] {}\n\n"
|
||||
|
||||
|
||||
class TestJoomlaUserAddConflict(unittest.TestCase):
|
||||
def conflict(self, output: str) -> str:
|
||||
return MODULE.joomla_user_add_conflict(
|
||||
output, "platformadmin", "platformadmin@example.org"
|
||||
)
|
||||
|
||||
def test_a_taken_username_names_the_group_less_account(self) -> None:
|
||||
message = self.conflict(ADD_FAILED.format("The username already exists!"))
|
||||
|
||||
self.assertIn("'platformadmin'", message)
|
||||
self.assertIn("belongs to no user group", message)
|
||||
self.assertIn("add it to Super Users", message)
|
||||
|
||||
def test_a_taken_email_names_the_address_of_the_group_less_account(self) -> None:
|
||||
message = self.conflict(ADD_FAILED.format("The email address already exists!"))
|
||||
|
||||
self.assertIn("'platformadmin@example.org'", message)
|
||||
self.assertIn("without any user group", message)
|
||||
|
||||
def test_any_other_refusal_is_left_to_the_task_itself(self) -> None:
|
||||
self.assertEqual(
|
||||
self.conflict(ADD_FAILED.format("The email address is invalid!")), ""
|
||||
)
|
||||
|
||||
def test_output_that_is_no_string_is_no_conflict(self) -> None:
|
||||
self.assertEqual(self.conflict(None), "")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,239 @@
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from utils import PROJECT_ROOT
|
||||
from utils.cache.files import read_text
|
||||
|
||||
SCRIPT = PROJECT_ROOT / "roles/web-app-mediawiki/files/shell/realign_admin_password.sh"
|
||||
STATE_SQL = PROJECT_ROOT / "roles/web-app-mediawiki/files/sql/admin_state.sql"
|
||||
NAME = "platformadmin"
|
||||
PASSWORD = "the-declared-password"
|
||||
EMAIL = "platformadmin@example.org"
|
||||
CREATED = "wikidb: Creating and promoting User:Platformadmin into sysop, bureaucrat...\ndone.\n"
|
||||
PROMOTED = "wikidb: Promoting User:Platformadmin into sysop, bureaucrat...\ndone."
|
||||
|
||||
STUB_PHP = """#!{python}
|
||||
import json, os, sys
|
||||
args = sys.argv[1:]
|
||||
with open(os.environ["STUB_LOG"], "a") as log:
|
||||
log.write(json.dumps(args) + "\\n")
|
||||
if args[1] == "sql":
|
||||
print("stdClass Object\\n(\\n [state] => " + os.environ["STUB_STATE"] + "\\n)")
|
||||
elif "--force" in args:
|
||||
print(os.environ["STUB_PROMOTE_OUTPUT"])
|
||||
else:
|
||||
print(os.environ["STUB_CREATE_OUTPUT"], end="")
|
||||
"""
|
||||
|
||||
|
||||
def _calls(log: Path) -> list[list[str]]:
|
||||
return [
|
||||
json.loads(line)
|
||||
for line in log.read_text().splitlines() # nocheck: cache-read tempdir fixture
|
||||
]
|
||||
|
||||
|
||||
class TestRealignAdminPassword(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self._tmp = tempfile.TemporaryDirectory()
|
||||
root = Path(self._tmp.name)
|
||||
self.log = root / "calls.jsonl"
|
||||
self.log.touch()
|
||||
self.bin = root / "bin"
|
||||
self.bin.mkdir()
|
||||
stub = self.bin / "php"
|
||||
stub.write_text(STUB_PHP.format(python=sys.executable))
|
||||
stub.chmod(0o755)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self._tmp.cleanup()
|
||||
|
||||
def _run(
|
||||
self, state: str, local_login: bool, promote_output: str, email: str
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
env = {
|
||||
"PATH": f"{self.bin}{os.pathsep}{os.environ['PATH']}",
|
||||
"STUB_LOG": str(self.log),
|
||||
"STUB_STATE": state,
|
||||
"STUB_PROMOTE_OUTPUT": promote_output,
|
||||
"STUB_CREATE_OUTPUT": CREATED,
|
||||
"MEDIAWIKI_HTML_DIR": "/var/www/html",
|
||||
"MEDIAWIKI_ADMIN_NAME": NAME,
|
||||
"MEDIAWIKI_ADMIN_PASSWORD": PASSWORD,
|
||||
"MEDIAWIKI_ADMIN_EMAIL": email,
|
||||
"MEDIAWIKI_LOCAL_LOGIN": "true" if local_login else "false",
|
||||
"MEDIAWIKI_ADMIN_STATE_SQL": read_text(str(STATE_SQL)),
|
||||
}
|
||||
return subprocess.run(
|
||||
["sh", "-s"],
|
||||
input=read_text(str(SCRIPT)),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env=env,
|
||||
check=False,
|
||||
)
|
||||
|
||||
def _promotions(self) -> list[list[str]]:
|
||||
return [call for call in _calls(self.log) if call[1] == "createAndPromote"]
|
||||
|
||||
def test_absent_account_under_sso_is_left_to_the_first_sso_login(self) -> None:
|
||||
result = self._run("absent", False, "", EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn("[UNCHANGED]", result.stdout)
|
||||
self.assertIn("provisioned by SSO", result.stdout)
|
||||
self.assertEqual(self._promotions(), [])
|
||||
|
||||
def test_absent_account_with_local_login_is_created_with_password_and_email(
|
||||
self,
|
||||
) -> None:
|
||||
result = self._run("absent", True, "", EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn("[CHANGED]", result.stdout)
|
||||
self.assertEqual(
|
||||
self._promotions(),
|
||||
[
|
||||
[
|
||||
"/var/www/html/maintenance/run.php",
|
||||
"createAndPromote",
|
||||
"--bureaucrat",
|
||||
"--sysop",
|
||||
"--email",
|
||||
EMAIL,
|
||||
NAME,
|
||||
PASSWORD,
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
def test_present_sysop_is_realigned_with_force_and_the_password(self) -> None:
|
||||
result = self._run("admin", True, "Password set.\ndone.", EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn("[CHANGED]", result.stdout)
|
||||
self.assertEqual(
|
||||
self._promotions()[0][2:],
|
||||
["--force", "--bureaucrat", "--sysop", NAME, PASSWORD],
|
||||
)
|
||||
|
||||
def test_present_sysop_under_sso_is_left_unchanged_without_a_password(
|
||||
self,
|
||||
) -> None:
|
||||
result = self._run("admin", False, "Account exists and nothing to do.", EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn("[UNCHANGED]", result.stdout)
|
||||
self.assertNotIn(PASSWORD, self._promotions()[0])
|
||||
|
||||
def test_wiki_without_any_sysop_fails_without_creating(self) -> None:
|
||||
result = self._run("no-admin", True, "", EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn("[FAIL]", result.stderr)
|
||||
self.assertIn("no sysop", result.stderr)
|
||||
self.assertEqual(self._promotions(), [])
|
||||
|
||||
def test_wiki_without_any_sysop_fails_under_sso_too(self) -> None:
|
||||
result = self._run("no-admin", False, "", EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn("no sysop", result.stderr)
|
||||
|
||||
def test_email_held_by_another_account_fails_naming_the_holder(self) -> None:
|
||||
result = self._run("email-held:Someone, Other", True, "", EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn("[FAIL]", result.stderr)
|
||||
self.assertIn("Someone, Other", result.stderr)
|
||||
self.assertEqual(self._promotions(), [])
|
||||
|
||||
def test_sso_account_with_the_confirmed_declared_email_is_promoted(self) -> None:
|
||||
result = self._run("not-admin:match", False, PROMOTED, EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(
|
||||
result.stdout.strip(),
|
||||
f"[CHANGED] promoted {NAME} (SSO account, email matches)",
|
||||
)
|
||||
self.assertEqual(
|
||||
self._promotions(),
|
||||
[
|
||||
[
|
||||
"/var/www/html/maintenance/run.php",
|
||||
"createAndPromote",
|
||||
"--force",
|
||||
"--bureaucrat",
|
||||
"--sysop",
|
||||
NAME,
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
def test_matching_account_is_not_promoted_while_local_login_is_on(self) -> None:
|
||||
result = self._run("not-admin:match", True, PROMOTED, EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn("not promoted (local login is on)", result.stderr)
|
||||
self.assertEqual(self._promotions(), [])
|
||||
|
||||
def test_sso_account_with_another_email_is_not_promoted(self) -> None:
|
||||
result = self._run("not-admin:mismatch", False, PROMOTED, EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn(f"its email differs from {EMAIL}", result.stderr)
|
||||
self.assertEqual(self._promotions(), [])
|
||||
|
||||
def test_sso_account_with_an_unconfirmed_email_is_not_promoted(self) -> None:
|
||||
result = self._run("not-admin:unconfirmed", False, PROMOTED, EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn("is not confirmed", result.stderr)
|
||||
self.assertEqual(self._promotions(), [])
|
||||
|
||||
def test_probe_without_a_state_fails(self) -> None:
|
||||
result = self._run("", True, "", EMAIL)
|
||||
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn("returned no state", result.stderr)
|
||||
self.assertEqual(self._promotions(), [])
|
||||
|
||||
def test_declared_values_reach_the_probe_only_hex_encoded(self) -> None:
|
||||
email = "o'brien@example.org"
|
||||
|
||||
self._run("admin", False, "Account exists and nothing to do.", email)
|
||||
|
||||
query = _calls(self.log)[0][3]
|
||||
self.assertNotIn("o'brien", query)
|
||||
self.assertIn(email.encode().hex(), query)
|
||||
self.assertIn(NAME.encode().hex(), query)
|
||||
self.assertNotIn("%(", query)
|
||||
|
||||
def test_empty_state_query_fails_before_any_call(self) -> None:
|
||||
result = subprocess.run(
|
||||
["sh", "-s"],
|
||||
input=read_text(str(SCRIPT)),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env={
|
||||
"PATH": f"{self.bin}{os.pathsep}{os.environ['PATH']}",
|
||||
"STUB_LOG": str(self.log),
|
||||
"MEDIAWIKI_HTML_DIR": "/var/www/html",
|
||||
"MEDIAWIKI_ADMIN_NAME": NAME,
|
||||
"MEDIAWIKI_ADMIN_EMAIL": EMAIL,
|
||||
},
|
||||
check=False,
|
||||
)
|
||||
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn("MEDIAWIKI_ADMIN_STATE_SQL is empty", result.stderr)
|
||||
self.assertEqual(_calls(self.log), [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user