Some checks failed
CI / skinny-install (aco) (push) Successful in 1m30s
CI / lint-test (push) Failing after 1m57s
CI / skinny-install (api) (push) Successful in 26s
CI / skinny-install (bcda) (push) Successful in 29s
CI / skinny-install (bib) (push) Successful in 32s
CI / skinny-install (bls) (push) Successful in 23s
CI / skinny-install (ccw) (push) Successful in 29s
CI / skinny-install (cli) (push) Successful in 31s
CI / skinny-install (cms) (push) Successful in 27s
CI / skinny-install (conf) (push) Successful in 28s
CI / skinny-install (opps) (push) Successful in 28s
CI / skinny-install (perf) (push) Successful in 32s
CI / skinny-install (pfs) (push) Successful in 32s
CI / skinny-install (rex) (push) Successful in 28s
Infra CI / notebooks (push) Failing after 3m43s
Infra CI / zotero (push) Failing after 0s
Infra CI / docs (push) Failing after 0s
Infra CI / api (push) Failing after 0s
Infra CI / mc (push) Failing after 0s
Package Supply Chain / pkg-supply-chain (push) Failing after 0s
Deploy / build-scan-report (push) Failing after 4m23s
- OPPS express functions: adjusted_payment, skin_sub_impact wrapping calcs - OPPS pipe module registered in aco.pipe.registry (2 exprs, auto-discovered by CLI/API) - Output table models: OppsAdjustedPayment, OppsSkinSubImpact - deploy.sh: tiered rollout (infra → gitea → apps → CI → observability) with context-aware image check (local → build if missing) - compose.yml: pull_policy: if_not_present + build sections for all fhirworx images, gateway IPAM subnet for CoreDNS static IP, removed nested loch.css bind mount - CI: opps added to skinny-install matrix, generated configs regenerated - Coverage: 98.46% → 99.04% (sigv4, cclf, diag, provision, auth, cms_quality tests)
232 lines
7.5 KiB
Python
232 lines
7.5 KiB
Python
"""Tests for api.auth.__main__ CLI entry point."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture()
|
|
def _valid_env(monkeypatch):
|
|
monkeypatch.setenv("ROOT_KEY", "aa" * 16)
|
|
|
|
|
|
class TestMain:
|
|
def test_no_args(self):
|
|
from api.auth.__main__ import main
|
|
|
|
with patch.object(sys, "argv", ["prog"]):
|
|
assert main() == 1
|
|
|
|
def test_bad_command(self):
|
|
from api.auth.__main__ import main
|
|
|
|
with patch.object(sys, "argv", ["prog", "bad", "abc123"]):
|
|
assert main() == 1
|
|
|
|
def test_missing_root_key(self, monkeypatch):
|
|
monkeypatch.delenv("ROOT_KEY", raising=False)
|
|
from api.auth.__main__ import main
|
|
|
|
with patch.object(sys, "argv", ["prog", "derive", "abc123"]):
|
|
assert main() == 1
|
|
|
|
def test_invalid_hex_root_key(self, monkeypatch):
|
|
monkeypatch.setenv("ROOT_KEY", "not-hex")
|
|
from api.auth.__main__ import main
|
|
|
|
with patch.object(sys, "argv", ["prog", "derive", "abc123"]):
|
|
assert main() == 1
|
|
|
|
def test_short_root_key(self, monkeypatch):
|
|
monkeypatch.setenv("ROOT_KEY", "aabb")
|
|
from api.auth.__main__ import main
|
|
|
|
with patch.object(sys, "argv", ["prog", "derive", "abc123"]):
|
|
assert main() == 1
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_derive(self, capsys):
|
|
from api.auth.__main__ import main
|
|
|
|
with patch.object(sys, "argv", ["prog", "derive", "abc123"]):
|
|
assert main() == 0
|
|
|
|
out = capsys.readouterr().out
|
|
assert "=" in out
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_derive_redacted(self, capsys):
|
|
from api.auth.__main__ import main
|
|
|
|
with patch.object(sys, "argv", ["prog", "derive", "abc123", "--redact"]):
|
|
assert main() == 0
|
|
|
|
out = capsys.readouterr().out
|
|
assert "..." in out
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_provision(self, tmp_path):
|
|
from api.auth.__main__ import main
|
|
|
|
env_file = tmp_path / ".env"
|
|
with (
|
|
patch.object(sys, "argv", ["prog", "provision", "abc123"]),
|
|
patch("api.auth.__main__.Path", return_value=env_file),
|
|
patch("api.auth.provision.provision") as mock_prov,
|
|
):
|
|
from api.auth.provision import ProvisionResult
|
|
|
|
mock_prov.return_value = ProvisionResult(
|
|
postgres=True, gitea=True, env_written=True
|
|
)
|
|
result = main()
|
|
assert result == 0
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_bootstrap(self, tmp_path):
|
|
from api.auth.__main__ import main
|
|
|
|
env_file = tmp_path / ".env"
|
|
with (
|
|
patch.object(sys, "argv", ["prog", "bootstrap", "abc123"]),
|
|
patch("api.auth.__main__.Path", return_value=env_file),
|
|
patch("api.auth.provision.bootstrap") as mock_boot,
|
|
):
|
|
from api.auth.provision import ProvisionResult
|
|
|
|
mock_boot.return_value = ProvisionResult(env_written=True)
|
|
assert main() == 0
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_provision_with_errors(self, tmp_path):
|
|
"""provision command returns non-zero when both postgres and gitea fail."""
|
|
from api.auth.__main__ import main
|
|
|
|
env_file = tmp_path / ".env"
|
|
with (
|
|
patch.object(sys, "argv", ["prog", "provision", "abc123"]),
|
|
patch("api.auth.__main__.Path", return_value=env_file),
|
|
patch("api.auth.provision.provision") as mock_prov,
|
|
):
|
|
from api.auth.provision import ProvisionResult
|
|
|
|
mock_prov.return_value = ProvisionResult(
|
|
postgres=False,
|
|
gitea=False,
|
|
env_written=True,
|
|
errors=[
|
|
("postgres", Exception("pg down")),
|
|
("gitea", Exception("g down")),
|
|
],
|
|
)
|
|
result = main()
|
|
assert result == 1
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_provision_partial_success(self, tmp_path):
|
|
"""provision returns 0 when postgres fails but gitea succeeds."""
|
|
from api.auth.__main__ import main
|
|
|
|
env_file = tmp_path / ".env"
|
|
with (
|
|
patch.object(sys, "argv", ["prog", "provision", "abc123"]),
|
|
patch("api.auth.__main__.Path", return_value=env_file),
|
|
patch("api.auth.provision.provision") as mock_prov,
|
|
):
|
|
from api.auth.provision import ProvisionResult
|
|
|
|
mock_prov.return_value = ProvisionResult(
|
|
postgres=False,
|
|
gitea=True,
|
|
env_written=True,
|
|
errors=[("postgres", Exception("pg down"))],
|
|
)
|
|
result = main()
|
|
assert result == 0
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_deploy(self, tmp_path):
|
|
from api.auth.__main__ import main
|
|
|
|
env_file = tmp_path / ".env"
|
|
with (
|
|
patch.object(sys, "argv", ["prog", "deploy", "abc123"]),
|
|
patch("api.auth.__main__.Path", return_value=env_file),
|
|
patch("api.auth.deploy.deploy") as mock_deploy,
|
|
):
|
|
from api.auth.provision import ProvisionResult
|
|
|
|
mock_deploy.return_value = ProvisionResult(env_written=True)
|
|
result = main()
|
|
assert result == 0
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_deploy_with_errors(self, tmp_path):
|
|
from api.auth.__main__ import main
|
|
|
|
env_file = tmp_path / ".env"
|
|
with (
|
|
patch.object(sys, "argv", ["prog", "deploy", "abc123"]),
|
|
patch("api.auth.__main__.Path", return_value=env_file),
|
|
patch("api.auth.deploy.deploy") as mock_deploy,
|
|
):
|
|
from api.auth.provision import ProvisionResult
|
|
|
|
mock_deploy.return_value = ProvisionResult(
|
|
env_written=False,
|
|
errors=[("provision", Exception("fail"))],
|
|
)
|
|
result = main()
|
|
assert result == 1
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_verify_success(self):
|
|
from api.auth.__main__ import main
|
|
|
|
with (
|
|
patch.object(sys, "argv", ["prog", "verify", "abc123"]),
|
|
patch("api.auth.deploy.verify_all", return_value=[]),
|
|
):
|
|
result = main()
|
|
assert result == 0
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_verify_failure(self):
|
|
from api.auth.__main__ import main
|
|
|
|
with (
|
|
patch.object(sys, "argv", ["prog", "verify", "abc123"]),
|
|
patch("api.auth.deploy.verify_all", return_value=["check failed"]),
|
|
):
|
|
result = main()
|
|
assert result == 1
|
|
|
|
@pytest.mark.usefixtures("_valid_env")
|
|
def test_bootstrap_with_errors(self, tmp_path):
|
|
from api.auth.__main__ import main
|
|
|
|
env_file = tmp_path / ".env"
|
|
with (
|
|
patch.object(sys, "argv", ["prog", "bootstrap", "abc123"]),
|
|
patch("api.auth.__main__.Path", return_value=env_file),
|
|
patch("api.auth.provision.bootstrap") as mock_boot,
|
|
):
|
|
from api.auth.provision import ProvisionResult
|
|
|
|
mock_boot.return_value = ProvisionResult(
|
|
env_written=True,
|
|
errors=[("postgres", Exception("pg down"))],
|
|
)
|
|
result = main()
|
|
assert result == 0
|
|
|
|
def test_dunder_main_line(self):
|
|
"""__main__ block is reachable (pragma: test run via subprocess not needed)."""
|
|
|
|
import api.auth.__main__ as m
|
|
|
|
assert callable(m.main)
|