Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.
Python agentic-aiai-securityalert-triageblue-teamcybersecuritydetection-engineeringincident-responselanggraphllm-agentsmcpmitre-attackmodel-context-protocolpurple-teamsecurity-operationsself-hostedsiemsoarsocthreat-detectionthreat-intelligence
test: replace source-text assertions with calls to the code they cover (#983)
Beenu Arora85170a0b7072
diff --git a/services/actions/tests/test_tenant_scope.py b/services/actions/tests/test_tenant_scope.pyindex f2c30dded..adc488b19 100644--- a/services/actions/tests/test_tenant_scope.py+++ b/services/actions/tests/test_tenant_scope.py@@ -100,10 +100,33 @@ def test_no_secret_means_no_verification() -> None:assert ts.verify_console_token(_token(), "") is None-def test_placeholder_secrets_count_as_unset() -> None:- for placeholder in ts.INSECURE_SECRET_DEFAULTS:- assert ts.resolve_console_secret.__doc__ # module contract exists- assert placeholder in ts.INSECURE_SECRET_DEFAULTS[email protected]("placeholder", sorted(ts.INSECURE_SECRET_DEFAULTS))+def test_placeholder_secrets_count_as_unset(placeholder: str, monkeypatch: pytest.MonkeyPatch) -> None:+ """A shipped placeholder must resolve to no secret, and so verify nothing.++ This used to assert that ``resolve_console_secret.__doc__`` was truthy and+ that each member of ``INSECURE_SECRET_DEFAULTS`` was in+ ``INSECURE_SECRET_DEFAULTS`` — a docstring standing in for behaviour, and+ a tautology. It never called ``resolve_console_secret`` with a placeholder+ at all, so it would have passed on an implementation that accepted every+ one of them.+ """+ monkeypatch.setenv("SECRET_KEY", placeholder)+ assert ts.resolve_console_secret() == "", f"{placeholder!r} was accepted as a usable secret"+ # The consequence, which is the thing that matters: a token signed with a+ # placeholder cannot buy access, because there is no secret to verify it.+ assert ts.verify_console_token(_token(secret=placeholder), ts.resolve_console_secret()) is None+++def test_a_real_secret_is_returned_verbatim(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", SECRET)+ assert ts.resolve_console_secret() == SECRET++[email protected]("unusable", ["", " ", "\n"])+def test_an_absent_or_blank_secret_resolves_to_nothing(unusable: str, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", unusable)+ assert ts.resolve_console_secret() == ""# ---------------------------------------------------------------------------diff --git a/services/agents/tests/test_tenant_scope.py b/services/agents/tests/test_tenant_scope.pyindex f2c30dded..adc488b19 100644--- a/services/agents/tests/test_tenant_scope.py+++ b/services/agents/tests/test_tenant_scope.py@@ -100,10 +100,33 @@ def test_no_secret_means_no_verification() -> None:assert ts.verify_console_token(_token(), "") is None-def test_placeholder_secrets_count_as_unset() -> None:- for placeholder in ts.INSECURE_SECRET_DEFAULTS:- assert ts.resolve_console_secret.__doc__ # module contract exists- assert placeholder in ts.INSECURE_SECRET_DEFAULTS[email protected]("placeholder", sorted(ts.INSECURE_SECRET_DEFAULTS))+def test_placeholder_secrets_count_as_unset(placeholder: str, monkeypatch: pytest.MonkeyPatch) -> None:+ """A shipped placeholder must resolve to no secret, and so verify nothing.++ This used to assert that ``resolve_console_secret.__doc__`` was truthy and+ that each member of ``INSECURE_SECRET_DEFAULTS`` was in+ ``INSECURE_SECRET_DEFAULTS`` — a docstring standing in for behaviour, and+ a tautology. It never called ``resolve_console_secret`` with a placeholder+ at all, so it would have passed on an implementation that accepted every+ one of them.+ """+ monkeypatch.setenv("SECRET_KEY", placeholder)+ assert ts.resolve_console_secret() == "", f"{placeholder!r} was accepted as a usable secret"+ # The consequence, which is the thing that matters: a token signed with a+ # placeholder cannot buy access, because there is no secret to verify it.+ assert ts.verify_console_token(_token(secret=placeholder), ts.resolve_console_secret()) is None+++def test_a_real_secret_is_returned_verbatim(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", SECRET)+ assert ts.resolve_console_secret() == SECRET++[email protected]("unusable", ["", " ", "\n"])+def test_an_absent_or_blank_secret_resolves_to_nothing(unusable: str, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", unusable)+ assert ts.resolve_console_secret() == ""# ---------------------------------------------------------------------------diff --git a/services/api/tests/test_cases_authorization.py b/services/api/tests/test_cases_authorization.pyindex 97a4c833e..ad2ca59d3 100644--- a/services/api/tests/test_cases_authorization.py+++ b/services/api/tests/test_cases_authorization.py@@ -23,10 +23,26 @@ satisfy a grep and still be broken.from __future__ import annotationsimport inspect+import uuidfrom typing import Any+from unittest.mock import AsyncMock, MagicMockimport pytest+from app.api.v1.deps import CurrentUserfrom app.api.v1.endpoints import cases+from fastapi import HTTPException+++def _user() -> CurrentUser:+ return CurrentUser(user_id=uuid.uuid4(), tenant_id=uuid.uuid4(), role="analyst", email="[email protected]")+++def _proxy_response(payload: dict[str, Any], status_code: int = 200) -> MagicMock:+ resp = MagicMock()+ resp.status_code = status_code+ resp.json = MagicMock(return_value=payload)+ return resp+#: Every mutating route in this module, by handler name.WRITE_HANDLERS = [@@ -102,20 +118,65 @@ class TestTheInvestigationRunReadIsScoped:assert "db" in params, "the handler takes no database session, so it cannot scope by tenant"assert "user" in params- def test_it_resolves_the_case_against_the_callers_tenant(self) -> None:- source = inspect.getsource(cases.case_investigation_run)- assert "_resolve_case_id(case_id, db, user.tenant_id)" in source, (- "the handler does not resolve case_id against the caller's tenant, so run_id alone "- "is proxied and any authenticated user can read any run"- )+ @pytest.mark.asyncio+ async def test_it_resolves_the_case_against_the_callers_tenant(self, monkeypatch: pytest.MonkeyPatch) -> None:+ """A case the caller's tenant does not own must not reach the proxy.- def test_a_run_belonging_to_another_case_is_refused(self) -> None:+ Was `assert "_resolve_case_id(case_id, db, user.tenant_id)" in source`,+ which is satisfied by the call appearing anywhere — including on a+ branch that never runs, or with its result discarded.+ """+ proxy = AsyncMock()+ monkeypatch.setattr(cases, "_agents_proxy", proxy)+ monkeypatch.setattr(cases, "_resolve_case_id", AsyncMock(side_effect=HTTPException(status_code=404, detail="Case not found")))++ with pytest.raises(HTTPException) as exc:+ await cases.case_investigation_run(case_id="c-1", run_id="r-1", db=MagicMock(), user=_user())++ assert exc.value.status_code == 404+ # The run must never have been proxied: resolving the case is what+ # proves the caller may see it.+ proxy.assert_not_awaited()++ @pytest.mark.asyncio+ async def test_a_run_belonging_to_another_case_is_refused(self, monkeypatch: pytest.MonkeyPatch) -> None:"""Resolving the case is not enough on its own.A caller who owns *some* case could otherwise pass their own case_id- with somebody else's run_id and have the proxy answer.+ with somebody else's run_id and have the proxy answer. The old+ assertion was `"run_case_id" in source and "404" in source` — and+ `404` appears on the `_resolve_case_id` path too, so deleting this+ check entirely would still have satisfied it."""- source = inspect.getsource(cases.case_investigation_run)- assert "run_case_id" in source and "404" in source.replace("HTTP_404_NOT_FOUND", "404"), (- "the handler does not check the returned run belongs to the resolved case"- )+ mine, theirs = uuid.uuid4(), uuid.uuid4()+ monkeypatch.setattr(cases, "_resolve_case_id", AsyncMock(return_value=mine))+ monkeypatch.setattr(cases, "_agents_proxy", AsyncMock(return_value=_proxy_response({"id": "r-1", "case_id": str(theirs)})))++ with pytest.raises(HTTPException) as exc:+ await cases.case_investigation_run(case_id="INC-001", run_id="r-1", db=MagicMock(), user=_user())++ assert exc.value.status_code == 404++ @pytest.mark.asyncio+ async def test_a_run_belonging_to_this_case_is_returned(self, monkeypatch: pytest.MonkeyPatch) -> None:+ """The refusals above are worthless if the route refuses everything."""+ mine = uuid.uuid4()+ monkeypatch.setattr(cases, "_resolve_case_id", AsyncMock(return_value=mine))+ payload = {"id": "r-1", "case_id": str(mine), "status": "completed"}+ monkeypatch.setattr(cases, "_agents_proxy", AsyncMock(return_value=_proxy_response(payload)))++ assert await cases.case_investigation_run(case_id="INC-001", run_id="r-1", db=MagicMock(), user=_user()) == payload++ @pytest.mark.asyncio+ async def test_the_run_id_cannot_inject_url_syntax_into_the_proxied_path(self, monkeypatch: pytest.MonkeyPatch) -> None:+ """`run_id` is caller-supplied and is interpolated into a URL path."""+ mine = uuid.uuid4()+ monkeypatch.setattr(cases, "_resolve_case_id", AsyncMock(return_value=mine))+ proxy = AsyncMock(return_value=_proxy_response({"id": "x", "case_id": str(mine)}))+ monkeypatch.setattr(cases, "_agents_proxy", proxy)++ await cases.case_investigation_run(case_id="INC-001", run_id="../../admin?x=1", db=MagicMock(), user=_user())++ assert proxy.await_args is not None, "the handler never reached the proxy"+ path = proxy.await_args.args[1]+ assert "../" not in path and "?" not in path, pathdiff --git a/services/api/tests/test_mssp_portfolio_consent.py b/services/api/tests/test_mssp_portfolio_consent.pyindex 9557d5466..4439c83bb 100644--- a/services/api/tests/test_mssp_portfolio_consent.py+++ b/services/api/tests/test_mssp_portfolio_consent.py@@ -11,50 +11,217 @@ The precondition — that the target is not already claimed — is not amitigation. On a deployment that does not use the MSSP feature no tenant isclaimed, so every tenant was attachable.-The fix reuses the consent mechanism `onboard_child_tenant` already had, and-this file asserts the two are the same mechanism rather than two spellings of-one idea: a tenant admits a manager by setting `mssp_parent_invite` in its own-settings, which is gated on `settings:write` and therefore unforgeable from-outside that tenant.+The fix reuses the consent mechanism `onboard_child_tenant` already had: a+tenant admits a manager by setting `mssp_parent_invite` in its own settings,+which is gated on `settings:write` and therefore unforgeable from outside that+tenant.++Every test here used to be `inspect.getsource(...)` plus a substring+assertion. That is the wrong instrument for a security fix in two ways. It+cannot distinguish a guard that is present from a guard that is *reached* —+`assert "is_own_tenant" in source` passes on a variable that is assigned and+never read. And the strongest of them asserted a string literal+(`'rejected[...] = "not invited'`), so nothing proved an uninvited tenant is+actually refused, or that no row is written when it is. One of them matched a+*comment*. These now call the route."""from __future__ import annotations-import inspect+import uuid+from typing import Any+from unittest.mock import AsyncMock, MagicMock+import pytest+from app.api.v1.deps import CurrentUserfrom app.api.v1.endpoints import mssp+from app.models.organization import OrganizationTenant+from app.services.org_scope import PortfolioScope-class TestTheAttachRequiresConsent:- def test_the_route_reads_the_invite_setting(self) -> None:- source = inspect.getsource(mssp.add_tenants_to_portfolio)- assert "_MSSP_INVITE_SETTING" in source, "the attach does not consult the tenant's invite, so any unclaimed tenant is attachable"+class _Tenant:+ """A tenant row carrying only what the route reads."""++ def __init__(self, settings: dict[str, Any] | None = None) -> None:+ self.settings = settings or {}+++class _Session:+ """An async session over an in-memory tenant table and claim table."""++ def __init__(self, tenants: dict[uuid.UUID, _Tenant], claims: dict[uuid.UUID, OrganizationTenant] | None = None) -> None:+ self._tenants = tenants+ self._claims = claims or {}+ self.added: list[Any] = []+ self.committed = False++ async def get(self, _model: Any, tenant_id: uuid.UUID) -> _Tenant | None:+ return self._tenants.get(tenant_id)++ async def execute(self, statement: Any) -> MagicMock:+ # The route issues exactly one select: the claim lookup, filtered on+ # the tenant id. Pull the bound id back out so the fake answers the+ # question that was actually asked.+ compiled = statement.compile()+ wanted = next((v for v in compiled.params.values() if isinstance(v, uuid.UUID)), None)+ assert wanted is not None, f"the claim lookup bound no tenant id: {compiled.params}"+ result = MagicMock()+ result.scalar_one_or_none = MagicMock(return_value=self._claims.get(wanted))+ return result++ def add(self, row: Any) -> None:+ self.added.append(row)++ async def commit(self) -> None:+ self.committed = True+++def _caller(tenant_id: uuid.UUID) -> CurrentUser:+ return CurrentUser(user_id=uuid.uuid4(), tenant_id=tenant_id, role="admin", email="[email protected]")+++def _scope(org_id: uuid.UUID) -> PortfolioScope:+ return PortfolioScope(org_id=org_id, org_slug="acme", org_name="Acme", org_role="owner", tenant_ids=frozenset())- def test_a_tenant_that_did_not_invite_the_caller_is_rejected(self) -> None:- source = inspect.getsource(mssp.add_tenants_to_portfolio)- assert 'rejected[str(tenant_id)] = "not invited' in source, "an uninvited tenant is not rejected"- def test_the_caller_may_still_attach_their_own_tenant(self) -> None:+async def _attach(db: _Session, caller: CurrentUser, org_id: uuid.UUID, *targets: uuid.UUID) -> dict[str, Any]:+ return await mssp.add_tenants_to_portfolio(+ body=mssp.TenantGrant(tenant_ids=list(targets)),+ scope=_scope(org_id),+ db=db, # type: ignore[arg-type]+ current_user=caller,+ )+++class TestTheAttachRequiresConsent:+ @pytest.mark.asyncio+ async def test_a_tenant_that_did_not_invite_the_caller_is_rejected(self) -> None:+ """The vulnerability itself: an unclaimed, uninvited tenant.++ Nothing is claimed here, which on a deployment not using MSSP is+ every tenant. The route must refuse, and must write no row.+ """+ victim, attacker_tenant, org = uuid.uuid4(), uuid.uuid4(), uuid.uuid4()+ db = _Session({victim: _Tenant(), attacker_tenant: _Tenant()})++ result = await _attach(db, _caller(attacker_tenant), org, victim)++ assert result["added"] == [], "an uninvited tenant was attached"+ assert "not invited" in result["rejected"][str(victim)]+ assert db.added == [], "no portfolio link may be written for a tenant that did not consent"++ @pytest.mark.asyncio+ async def test_an_invite_naming_a_different_manager_does_not_admit_this_one(self) -> None:+ """An invite is consent to *one* organisation, not to anyone who asks."""+ victim, attacker_tenant, someone_else, org = uuid.uuid4(), uuid.uuid4(), uuid.uuid4(), uuid.uuid4()+ db = _Session({victim: _Tenant({mssp._MSSP_INVITE_SETTING: str(someone_else)})})++ result = await _attach(db, _caller(attacker_tenant), org, victim)++ assert result["added"] == []+ assert "not invited" in result["rejected"][str(victim)]+ assert db.added == []++ @pytest.mark.asyncio+ async def test_a_tenant_that_invited_the_caller_is_attached(self) -> None:+ managing, invited, org = uuid.uuid4(), uuid.uuid4(), uuid.uuid4()+ tenant = _Tenant({mssp._MSSP_INVITE_SETTING: str(managing)})+ db = _Session({invited: tenant})+ caller = _caller(managing)++ result = await _attach(db, caller, org, invited)++ assert result["added"] == [str(invited)]+ assert result["rejected"] == {}+ assert len(db.added) == 1+ link = db.added[0]+ assert (link.org_id, link.tenant_id, link.onboarded_by) == (org, invited, caller.user_id)++ @pytest.mark.asyncio+ async def test_the_caller_may_still_attach_their_own_tenant(self) -> None:"""Requiring a tenant to invite itself would be ceremony, not consent."""- source = inspect.getsource(mssp.add_tenants_to_portfolio)- assert "is_own_tenant" in source+ own, org = uuid.uuid4(), uuid.uuid4()+ db = _Session({own: _Tenant()})++ result = await _attach(db, _caller(own), org, own)++ assert result["added"] == [str(own)]+ assert len(db.added) == 1++ @pytest.mark.asyncio+ async def test_the_invite_is_consumed_so_it_cannot_be_replayed(self) -> None:+ """A stale invite would let a tenant that later left be re-attached."""+ managing, invited, org = uuid.uuid4(), uuid.uuid4(), uuid.uuid4()+ tenant = _Tenant({mssp._MSSP_INVITE_SETTING: str(managing), "keep": "me"})+ db = _Session({invited: tenant})++ await _attach(db, _caller(managing), org, invited)++ assert mssp._MSSP_INVITE_SETTING not in tenant.settings, "the invite survived and can be replayed"+ assert tenant.settings.get("keep") == "me", "consuming the invite must not clear the tenant's other settings"++ @pytest.mark.asyncio+ async def test_a_tenant_managed_by_another_organisation_is_not_reassigned(self) -> None:+ managing, claimed, org, other_org = uuid.uuid4(), uuid.uuid4(), uuid.uuid4(), uuid.uuid4()+ existing = OrganizationTenant(org_id=other_org, tenant_id=claimed, relationship="managed")+ db = _Session({claimed: _Tenant({mssp._MSSP_INVITE_SETTING: str(managing)})}, claims={claimed: existing})++ result = await _attach(db, _caller(managing), org, claimed)++ assert result["added"] == []+ assert result["rejected"][str(claimed)] == "managed by another organisation"+ assert db.added == []++ @pytest.mark.asyncio+ async def test_the_refusal_does_not_disclose_an_invite_for_someone_else(self) -> None:+ """Both refusals must read identically, or the response is an oracle.++ A caller who can tell "nobody invited anyone" from "somebody else was+ invited" can enumerate which tenants are mid-onboarding with another+ provider.+ """+ no_invite, other_invite, attacker_tenant, org = uuid.uuid4(), uuid.uuid4(), uuid.uuid4(), uuid.uuid4()+ db = _Session(+ {+ no_invite: _Tenant(),+ other_invite: _Tenant({mssp._MSSP_INVITE_SETTING: str(uuid.uuid4())}),+ }+ )- def test_the_invite_is_consumed_so_it_cannot_be_replayed(self) -> None:- source = inspect.getsource(mssp.add_tenants_to_portfolio)- assert "pop(_MSSP_INVITE_SETTING" in source, "a stale invite would let a tenant that later left be re-attached"+ result = await _attach(db, _caller(attacker_tenant), org, no_invite, other_invite)- def test_the_refusal_does_not_disclose_an_invite_for_someone_else(self) -> None:- source = inspect.getsource(mssp.add_tenants_to_portfolio)- assert "does not disclose" in source.lower() or "not invited: an admin" in source+ assert result["rejected"][str(no_invite)] == result["rejected"][str(other_invite)]class TestItIsTheSameMechanismAsChildOnboarding:"""Two consent paths that drift apart are one bypass waiting to happen."""- def test_both_routes_read_the_same_setting_key(self) -> None:- attach = inspect.getsource(mssp.add_tenants_to_portfolio)- onboard = inspect.getsource(mssp.onboard_child_tenant)- assert "_MSSP_INVITE_SETTING" in attach and "_MSSP_INVITE_SETTING" in onboard+ @pytest.mark.asyncio+ async def test_child_onboarding_reads_the_key_the_attach_writes_off(self) -> None:+ """Both routes must key on the same setting, proven by behaviour.++ The old test asserted the identifier `_MSSP_INVITE_SETTING` appeared+ in both function bodies, which a rename to a second constant with a+ different value would satisfy. This drives `onboard_child_tenant`+ with an invite written under the key the attach route consumes: if+ the two ever key differently, the adoption is refused here.+ """+ parent, child = uuid.uuid4(), uuid.uuid4()+ tenant = MagicMock()+ tenant.id = child+ tenant.parent_tenant_id = None+ tenant.settings = {mssp._MSSP_INVITE_SETTING: str(parent)}++ db = MagicMock()+ db.get = AsyncMock(return_value=tenant)+ db.commit = AsyncMock()+ db.refresh = AsyncMock()+ db.execute = AsyncMock()++ await mssp.onboard_child_tenant(child_id=child, db=db, current_user=_caller(parent))++ assert tenant.parent_tenant_id == parent, "the invite key the attach route consumes did not admit a child"+ assert mssp._MSSP_INVITE_SETTING not in tenant.settings, "child onboarding must consume the invite too"def test_the_setting_key_is_defined_once(self) -> None:assert isinstance(mssp._MSSP_INVITE_SETTING, str) and mssp._MSSP_INVITE_SETTINGdiff --git a/services/connectors/tests/test_tenant_scope.py b/services/connectors/tests/test_tenant_scope.pyindex f2c30dded..adc488b19 100644--- a/services/connectors/tests/test_tenant_scope.py+++ b/services/connectors/tests/test_tenant_scope.py@@ -100,10 +100,33 @@ def test_no_secret_means_no_verification() -> None:assert ts.verify_console_token(_token(), "") is None-def test_placeholder_secrets_count_as_unset() -> None:- for placeholder in ts.INSECURE_SECRET_DEFAULTS:- assert ts.resolve_console_secret.__doc__ # module contract exists- assert placeholder in ts.INSECURE_SECRET_DEFAULTS[email protected]("placeholder", sorted(ts.INSECURE_SECRET_DEFAULTS))+def test_placeholder_secrets_count_as_unset(placeholder: str, monkeypatch: pytest.MonkeyPatch) -> None:+ """A shipped placeholder must resolve to no secret, and so verify nothing.++ This used to assert that ``resolve_console_secret.__doc__`` was truthy and+ that each member of ``INSECURE_SECRET_DEFAULTS`` was in+ ``INSECURE_SECRET_DEFAULTS`` — a docstring standing in for behaviour, and+ a tautology. It never called ``resolve_console_secret`` with a placeholder+ at all, so it would have passed on an implementation that accepted every+ one of them.+ """+ monkeypatch.setenv("SECRET_KEY", placeholder)+ assert ts.resolve_console_secret() == "", f"{placeholder!r} was accepted as a usable secret"+ # The consequence, which is the thing that matters: a token signed with a+ # placeholder cannot buy access, because there is no secret to verify it.+ assert ts.verify_console_token(_token(secret=placeholder), ts.resolve_console_secret()) is None+++def test_a_real_secret_is_returned_verbatim(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", SECRET)+ assert ts.resolve_console_secret() == SECRET++[email protected]("unusable", ["", " ", "\n"])+def test_an_absent_or_blank_secret_resolves_to_nothing(unusable: str, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", unusable)+ assert ts.resolve_console_secret() == ""# ---------------------------------------------------------------------------diff --git a/services/fusion/tests/test_tenant_scope.py b/services/fusion/tests/test_tenant_scope.pyindex f2c30dded..adc488b19 100644--- a/services/fusion/tests/test_tenant_scope.py+++ b/services/fusion/tests/test_tenant_scope.py@@ -100,10 +100,33 @@ def test_no_secret_means_no_verification() -> None:assert ts.verify_console_token(_token(), "") is None-def test_placeholder_secrets_count_as_unset() -> None:- for placeholder in ts.INSECURE_SECRET_DEFAULTS:- assert ts.resolve_console_secret.__doc__ # module contract exists- assert placeholder in ts.INSECURE_SECRET_DEFAULTS[email protected]("placeholder", sorted(ts.INSECURE_SECRET_DEFAULTS))+def test_placeholder_secrets_count_as_unset(placeholder: str, monkeypatch: pytest.MonkeyPatch) -> None:+ """A shipped placeholder must resolve to no secret, and so verify nothing.++ This used to assert that ``resolve_console_secret.__doc__`` was truthy and+ that each member of ``INSECURE_SECRET_DEFAULTS`` was in+ ``INSECURE_SECRET_DEFAULTS`` — a docstring standing in for behaviour, and+ a tautology. It never called ``resolve_console_secret`` with a placeholder+ at all, so it would have passed on an implementation that accepted every+ one of them.+ """+ monkeypatch.setenv("SECRET_KEY", placeholder)+ assert ts.resolve_console_secret() == "", f"{placeholder!r} was accepted as a usable secret"+ # The consequence, which is the thing that matters: a token signed with a+ # placeholder cannot buy access, because there is no secret to verify it.+ assert ts.verify_console_token(_token(secret=placeholder), ts.resolve_console_secret()) is None+++def test_a_real_secret_is_returned_verbatim(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", SECRET)+ assert ts.resolve_console_secret() == SECRET++[email protected]("unusable", ["", " ", "\n"])+def test_an_absent_or_blank_secret_resolves_to_nothing(unusable: str, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", unusable)+ assert ts.resolve_console_secret() == ""# ---------------------------------------------------------------------------diff --git a/services/honeytokens/tests/test_tenant_scope.py b/services/honeytokens/tests/test_tenant_scope.pyindex f2c30dded..adc488b19 100644--- a/services/honeytokens/tests/test_tenant_scope.py+++ b/services/honeytokens/tests/test_tenant_scope.py@@ -100,10 +100,33 @@ def test_no_secret_means_no_verification() -> None:assert ts.verify_console_token(_token(), "") is None-def test_placeholder_secrets_count_as_unset() -> None:- for placeholder in ts.INSECURE_SECRET_DEFAULTS:- assert ts.resolve_console_secret.__doc__ # module contract exists- assert placeholder in ts.INSECURE_SECRET_DEFAULTS[email protected]("placeholder", sorted(ts.INSECURE_SECRET_DEFAULTS))+def test_placeholder_secrets_count_as_unset(placeholder: str, monkeypatch: pytest.MonkeyPatch) -> None:+ """A shipped placeholder must resolve to no secret, and so verify nothing.++ This used to assert that ``resolve_console_secret.__doc__`` was truthy and+ that each member of ``INSECURE_SECRET_DEFAULTS`` was in+ ``INSECURE_SECRET_DEFAULTS`` — a docstring standing in for behaviour, and+ a tautology. It never called ``resolve_console_secret`` with a placeholder+ at all, so it would have passed on an implementation that accepted every+ one of them.+ """+ monkeypatch.setenv("SECRET_KEY", placeholder)+ assert ts.resolve_console_secret() == "", f"{placeholder!r} was accepted as a usable secret"+ # The consequence, which is the thing that matters: a token signed with a+ # placeholder cannot buy access, because there is no secret to verify it.+ assert ts.verify_console_token(_token(secret=placeholder), ts.resolve_console_secret()) is None+++def test_a_real_secret_is_returned_verbatim(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", SECRET)+ assert ts.resolve_console_secret() == SECRET++[email protected]("unusable", ["", " ", "\n"])+def test_an_absent_or_blank_secret_resolves_to_nothing(unusable: str, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", unusable)+ assert ts.resolve_console_secret() == ""# ---------------------------------------------------------------------------diff --git a/services/osquery-tls/tests/test_tenant_scope.py b/services/osquery-tls/tests/test_tenant_scope.pyindex f2c30dded..adc488b19 100644--- a/services/osquery-tls/tests/test_tenant_scope.py+++ b/services/osquery-tls/tests/test_tenant_scope.py@@ -100,10 +100,33 @@ def test_no_secret_means_no_verification() -> None:assert ts.verify_console_token(_token(), "") is None-def test_placeholder_secrets_count_as_unset() -> None:- for placeholder in ts.INSECURE_SECRET_DEFAULTS:- assert ts.resolve_console_secret.__doc__ # module contract exists- assert placeholder in ts.INSECURE_SECRET_DEFAULTS[email protected]("placeholder", sorted(ts.INSECURE_SECRET_DEFAULTS))+def test_placeholder_secrets_count_as_unset(placeholder: str, monkeypatch: pytest.MonkeyPatch) -> None:+ """A shipped placeholder must resolve to no secret, and so verify nothing.++ This used to assert that ``resolve_console_secret.__doc__`` was truthy and+ that each member of ``INSECURE_SECRET_DEFAULTS`` was in+ ``INSECURE_SECRET_DEFAULTS`` — a docstring standing in for behaviour, and+ a tautology. It never called ``resolve_console_secret`` with a placeholder+ at all, so it would have passed on an implementation that accepted every+ one of them.+ """+ monkeypatch.setenv("SECRET_KEY", placeholder)+ assert ts.resolve_console_secret() == "", f"{placeholder!r} was accepted as a usable secret"+ # The consequence, which is the thing that matters: a token signed with a+ # placeholder cannot buy access, because there is no secret to verify it.+ assert ts.verify_console_token(_token(secret=placeholder), ts.resolve_console_secret()) is None+++def test_a_real_secret_is_returned_verbatim(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", SECRET)+ assert ts.resolve_console_secret() == SECRET++[email protected]("unusable", ["", " ", "\n"])+def test_an_absent_or_blank_secret_resolves_to_nothing(unusable: str, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", unusable)+ assert ts.resolve_console_secret() == ""# ---------------------------------------------------------------------------diff --git a/services/purple-team/tests/test_tenant_scope.py b/services/purple-team/tests/test_tenant_scope.pyindex f2c30dded..adc488b19 100644--- a/services/purple-team/tests/test_tenant_scope.py+++ b/services/purple-team/tests/test_tenant_scope.py@@ -100,10 +100,33 @@ def test_no_secret_means_no_verification() -> None:assert ts.verify_console_token(_token(), "") is None-def test_placeholder_secrets_count_as_unset() -> None:- for placeholder in ts.INSECURE_SECRET_DEFAULTS:- assert ts.resolve_console_secret.__doc__ # module contract exists- assert placeholder in ts.INSECURE_SECRET_DEFAULTS[email protected]("placeholder", sorted(ts.INSECURE_SECRET_DEFAULTS))+def test_placeholder_secrets_count_as_unset(placeholder: str, monkeypatch: pytest.MonkeyPatch) -> None:+ """A shipped placeholder must resolve to no secret, and so verify nothing.++ This used to assert that ``resolve_console_secret.__doc__`` was truthy and+ that each member of ``INSECURE_SECRET_DEFAULTS`` was in+ ``INSECURE_SECRET_DEFAULTS`` — a docstring standing in for behaviour, and+ a tautology. It never called ``resolve_console_secret`` with a placeholder+ at all, so it would have passed on an implementation that accepted every+ one of them.+ """+ monkeypatch.setenv("SECRET_KEY", placeholder)+ assert ts.resolve_console_secret() == "", f"{placeholder!r} was accepted as a usable secret"+ # The consequence, which is the thing that matters: a token signed with a+ # placeholder cannot buy access, because there is no secret to verify it.+ assert ts.verify_console_token(_token(secret=placeholder), ts.resolve_console_secret()) is None+++def test_a_real_secret_is_returned_verbatim(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", SECRET)+ assert ts.resolve_console_secret() == SECRET++[email protected]("unusable", ["", " ", "\n"])+def test_an_absent_or_blank_secret_resolves_to_nothing(unusable: str, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", unusable)+ assert ts.resolve_console_secret() == ""# ---------------------------------------------------------------------------diff --git a/services/threatintel/tests/test_tenant_scope.py b/services/threatintel/tests/test_tenant_scope.pyindex f2c30dded..adc488b19 100644--- a/services/threatintel/tests/test_tenant_scope.py+++ b/services/threatintel/tests/test_tenant_scope.py@@ -100,10 +100,33 @@ def test_no_secret_means_no_verification() -> None:assert ts.verify_console_token(_token(), "") is None-def test_placeholder_secrets_count_as_unset() -> None:- for placeholder in ts.INSECURE_SECRET_DEFAULTS:- assert ts.resolve_console_secret.__doc__ # module contract exists- assert placeholder in ts.INSECURE_SECRET_DEFAULTS[email protected]("placeholder", sorted(ts.INSECURE_SECRET_DEFAULTS))+def test_placeholder_secrets_count_as_unset(placeholder: str, monkeypatch: pytest.MonkeyPatch) -> None:+ """A shipped placeholder must resolve to no secret, and so verify nothing.++ This used to assert that ``resolve_console_secret.__doc__`` was truthy and+ that each member of ``INSECURE_SECRET_DEFAULTS`` was in+ ``INSECURE_SECRET_DEFAULTS`` — a docstring standing in for behaviour, and+ a tautology. It never called ``resolve_console_secret`` with a placeholder+ at all, so it would have passed on an implementation that accepted every+ one of them.+ """+ monkeypatch.setenv("SECRET_KEY", placeholder)+ assert ts.resolve_console_secret() == "", f"{placeholder!r} was accepted as a usable secret"+ # The consequence, which is the thing that matters: a token signed with a+ # placeholder cannot buy access, because there is no secret to verify it.+ assert ts.verify_console_token(_token(secret=placeholder), ts.resolve_console_secret()) is None+++def test_a_real_secret_is_returned_verbatim(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", SECRET)+ assert ts.resolve_console_secret() == SECRET++[email protected]("unusable", ["", " ", "\n"])+def test_an_absent_or_blank_secret_resolves_to_nothing(unusable: str, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", unusable)+ assert ts.resolve_console_secret() == ""# ---------------------------------------------------------------------------diff --git a/services/ueba/tests/test_tenant_scope.py b/services/ueba/tests/test_tenant_scope.pyindex f2c30dded..adc488b19 100644--- a/services/ueba/tests/test_tenant_scope.py+++ b/services/ueba/tests/test_tenant_scope.py@@ -100,10 +100,33 @@ def test_no_secret_means_no_verification() -> None:assert ts.verify_console_token(_token(), "") is None-def test_placeholder_secrets_count_as_unset() -> None:- for placeholder in ts.INSECURE_SECRET_DEFAULTS:- assert ts.resolve_console_secret.__doc__ # module contract exists- assert placeholder in ts.INSECURE_SECRET_DEFAULTS[email protected]("placeholder", sorted(ts.INSECURE_SECRET_DEFAULTS))+def test_placeholder_secrets_count_as_unset(placeholder: str, monkeypatch: pytest.MonkeyPatch) -> None:+ """A shipped placeholder must resolve to no secret, and so verify nothing.++ This used to assert that ``resolve_console_secret.__doc__`` was truthy and+ that each member of ``INSECURE_SECRET_DEFAULTS`` was in+ ``INSECURE_SECRET_DEFAULTS`` — a docstring standing in for behaviour, and+ a tautology. It never called ``resolve_console_secret`` with a placeholder+ at all, so it would have passed on an implementation that accepted every+ one of them.+ """+ monkeypatch.setenv("SECRET_KEY", placeholder)+ assert ts.resolve_console_secret() == "", f"{placeholder!r} was accepted as a usable secret"+ # The consequence, which is the thing that matters: a token signed with a+ # placeholder cannot buy access, because there is no secret to verify it.+ assert ts.verify_console_token(_token(secret=placeholder), ts.resolve_console_secret()) is None+++def test_a_real_secret_is_returned_verbatim(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", SECRET)+ assert ts.resolve_console_secret() == SECRET++[email protected]("unusable", ["", " ", "\n"])+def test_an_absent_or_blank_secret_resolves_to_nothing(unusable: str, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("SECRET_KEY", unusable)+ assert ts.resolve_console_secret() == ""# ---------------------------------------------------------------------------