refactoring

This commit is contained in:
Maxim Devaev
2025-02-09 23:20:28 +02:00
parent 302e7c2877
commit 97b405297b
4 changed files with 44 additions and 44 deletions

View File

@@ -53,10 +53,10 @@ def _htpasswd_fixture(request) -> Generator[passlib.apache.HtpasswdFile, None, N
os.remove(path)
def _run_htpasswd(cmd: list[str], htpasswd_path: str, internal_type: str="htpasswd") -> None:
def _run_htpasswd(cmd: list[str], htpasswd_path: str, int_type: str="htpasswd") -> None:
cmd = ["kvmd-htpasswd", *cmd, "--set-options"]
if internal_type != "htpasswd": # By default
cmd.append("kvmd/auth/internal/type=" + internal_type)
if int_type != "htpasswd": # By default
cmd.append("kvmd/auth/internal/type=" + int_type)
if htpasswd_path:
cmd.append("kvmd/auth/internal/file=" + htpasswd_path)
main(cmd)
@@ -153,12 +153,12 @@ def test_ok__del(htpasswd: passlib.apache.HtpasswdFile) -> None:
# =====
def test_fail__not_htpasswd() -> None:
with pytest.raises(SystemExit, match="Error: KVMD internal auth not using 'htpasswd'"):
_run_htpasswd(["list"], "", internal_type="http")
_run_htpasswd(["list"], "", int_type="http")
def test_fail__unknown_plugin() -> None:
with pytest.raises(SystemExit, match="ConfigError: Unknown plugin 'auth/foobar'"):
_run_htpasswd(["list"], "", internal_type="foobar")
_run_htpasswd(["list"], "", int_type="foobar")
def test_fail__invalid_passwd(mocker, tmpdir) -> None: # type: ignore

View File

@@ -54,9 +54,9 @@ def _make_service_kwargs(path: str) -> dict:
@contextlib.asynccontextmanager
async def _get_configured_manager(
unauth_paths: list[str],
internal_path: str,
external_path: str="",
force_internal_users: (list[str] | None)=None,
int_path: str,
ext_path: str="",
force_int_users: (list[str] | None)=None,
) -> AsyncGenerator[AuthManager, None]:
manager = AuthManager(
@@ -64,12 +64,12 @@ async def _get_configured_manager(
expire=0,
unauth_paths=unauth_paths,
internal_type="htpasswd",
internal_kwargs=_make_service_kwargs(internal_path),
force_internal_users=(force_internal_users or []),
int_type="htpasswd",
int_kwargs=_make_service_kwargs(int_path),
force_int_users=(force_int_users or []),
external_type=("htpasswd" if external_path else ""),
external_kwargs=(_make_service_kwargs(external_path) if external_path else {}),
ext_type=("htpasswd" if ext_path else ""),
ext_kwargs=(_make_service_kwargs(ext_path) if ext_path else {}),
totp_secret_path="",
)
@@ -264,12 +264,12 @@ async def test_ok__disabled() -> None:
expire=0,
unauth_paths=[],
internal_type="foobar",
internal_kwargs={},
force_internal_users=[],
int_type="foobar",
int_kwargs={},
force_int_users=[],
external_type="",
external_kwargs={},
ext_type="",
ext_kwargs={},
totp_secret_path="",
)