Files
ss-tools/backend/tests/services/clean_release/test_source_isolation.py
busya ce0369ae5c test(backend): add 55+ test files to push coverage to 98%
Subagents delivered tests across all uncovered backend modules:

Schemas (100%): agent, auth, health, profile, settings, validation
Services (98-100%): auth, profile, health, llm, mapping, resource,
  security, git, superset_lookup, sql_table_extractor, rbac
API routes (new): auth, admin, health, environments, plugins,
  dashboards (helpers, projection, actions, listing),
  git (config, deps, env, helpers)
Clean Release (100%): DTO, facade, policy_engine, stages,
  repos, preparation, source_isolation, compliance
Git services: base, remote_providers
Agent module: app, run, middleware, langgraph_setup
Core: trace, cleanup, ws_log_handler, timezone, auth (config/oauth/security), matching
Reports: normalizer, report_service, type_profiles
Notifications: service, providers

Also:
- .gitignore: add .coverage, *.cover, coverage-* dirs
- src/schemas/auth.py: fix AD group DN regex (comma in CN=...)
- Remove co-located src/services/__tests__/ (caused pytest module collision)
2026-06-15 13:55:57 +03:00

92 lines
3.8 KiB
Python

# #region Test.CleanRelease.SourceIsolation [C:2] [TYPE Module] [SEMANTICS test,clean-release,source,isolation]
# @BRIEF Tests for validate_internal_sources — endpoint validation against registry.
# @RELATION BINDS_TO -> [SourceIsolation]
from datetime import UTC, datetime
import pytest
from src.models.clean_release import ResourceSourceEntry, ResourceSourceRegistry
from src.services.clean_release.source_isolation import validate_internal_sources
def _make_registry(hosts: list[str] | None = None) -> ResourceSourceRegistry:
"""Create a ResourceSourceRegistry with entries."""
if hosts is None:
hosts = ["internal.local", "repo.internal.local"]
now = datetime.now(UTC)
entries = [
ResourceSourceEntry(
source_id=f"src-{i}", host=h, protocol="https",
purpose="internal", enabled=True,
)
for i, h in enumerate(hosts)
]
return ResourceSourceRegistry(
registry_id="reg-1", name="Test Registry", entries=entries,
updated_at=now, updated_by="system", status="ACTIVE",
)
class TestValidateInternalSources:
"""validate_internal_sources — endpoint validation."""
# #region test_all_internal [C:2] [TYPE Function]
def test_all_internal(self):
"""All endpoints in allowed list → ok=True."""
registry = _make_registry()
result = validate_internal_sources(registry, ["internal.local", "repo.internal.local"])
assert result["ok"] is True
assert result["violations"] == []
# #endregion test_all_internal
# #region test_some_external [C:2] [TYPE Function]
def test_some_external(self):
"""External endpoint → violation reported."""
registry = _make_registry()
result = validate_internal_sources(registry, ["internal.local", "external.bad.com"])
assert result["ok"] is False
assert len(result["violations"]) == 1
assert result["violations"][0]["location"] == "external.bad.com"
assert result["violations"][0]["blocked_release"] is True
# #endregion test_some_external
# #region test_empty_endpoint [C:2] [TYPE Function]
def test_empty_endpoint(self):
"""Empty endpoint → violation with empty-endpoint placeholder."""
registry = _make_registry()
result = validate_internal_sources(registry, [""])
assert result["ok"] is False
assert result["violations"][0]["location"] == "<empty-endpoint>"
# #endregion test_empty_endpoint
# #region test_disabled_entries_ignored [C:2] [TYPE Function]
def test_disabled_entries_ignored(self):
"""Disabled registry entries are not included in allowed hosts."""
entries = [
ResourceSourceEntry(source_id="s1", host="internal.local", protocol="https", purpose="internal", enabled=False),
]
registry = ResourceSourceRegistry(
registry_id="reg-1", name="Test", entries=entries,
updated_at=None, updated_by="system",
)
result = validate_internal_sources(registry, ["internal.local"])
assert result["ok"] is False
assert len(result["violations"]) == 1
# #endregion test_disabled_entries_ignored
# #region test_case_insensitive_matching [C:2] [TYPE Function]
def test_case_insensitive_matching(self):
"""Endpoint matching is case-insensitive."""
registry = _make_registry(hosts=["Internal.Local"])
result = validate_internal_sources(registry, ["INTERNAL.LOCAL"])
assert result["ok"] is True
# #endregion test_case_insensitive_matching
# #region test_no_endpoints [C:2] [TYPE Function]
def test_no_endpoints(self):
"""No endpoints provided → ok=True (nothing to check)."""
registry = _make_registry()
result = validate_internal_sources(registry, [])
assert result["ok"] is True
# #endregion test_no_endpoints