mirror of
https://github.com/element-hq/ess-helm.git
synced 2026-11-24 02:51:28 -08:00
Implement Secrets conflict resolution
This commit is contained in:
8 files changed
+406
-57
No files matched your search
@@ -0,0 +1,147 @@
|
||||
# Copyright 2026 Element Creations Ltd
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
|
||||
"""
|
||||
Conflict resolution utilities for migration.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from .models import DiscoveredSecretTracking, SecretSource, ValueSourceTracking
|
||||
from .utils import is_quiet_mode, prompt_choice, prompt_value, set_nested_value
|
||||
|
||||
|
||||
def prompt_for_conflict_resolution(
|
||||
pretty_logger: logging.Logger,
|
||||
conflict_key: str,
|
||||
value_to_strategies: dict[str, list[str]],
|
||||
display_value_max_length: int = 50,
|
||||
enable_custom: bool = False,
|
||||
) -> tuple[str | None, bool]:
|
||||
"""
|
||||
Prompt user to resolve a conflict.
|
||||
|
||||
Args:
|
||||
pretty_logger: Logger for displaying prompts
|
||||
conflict_key: The key/path being resolved (for display)
|
||||
value_to_strategies: Mapping of value strings to list of strategy names
|
||||
display_value_max_length: Max length for value display before truncation
|
||||
|
||||
Returns:
|
||||
Tuple of (selected_value, is_custom) where is_custom indicates user wants to enter custom value
|
||||
"""
|
||||
options = []
|
||||
for value in sorted(value_to_strategies):
|
||||
options.append(value)
|
||||
if enable_custom:
|
||||
options.append("Enter custom value")
|
||||
|
||||
choice = prompt_choice(pretty_logger, f"Select value for '{conflict_key}':", options)
|
||||
is_custom = choice == "Enter custom value"
|
||||
selected_value = choice if not is_custom else None
|
||||
return selected_value, is_custom
|
||||
|
||||
|
||||
def resolve_value_conflicts(
|
||||
pretty_logger: logging.Logger,
|
||||
value_source_tracking: ValueSourceTracking,
|
||||
ess_config: dict[str, Any],
|
||||
) -> None:
|
||||
"""Resolve conflicts where multiple strategies provide different values for same ESS path."""
|
||||
conflicts = value_source_tracking.get_conflicts()
|
||||
if not conflicts:
|
||||
return
|
||||
|
||||
for ess_path, sources in sorted(conflicts.items()):
|
||||
first_value = sources[0].value
|
||||
all_same = all(str(v.value) == str(first_value) for v in sources)
|
||||
|
||||
if all_same:
|
||||
logging.debug(f"Consistent values for {ess_path}: {first_value}")
|
||||
continue
|
||||
|
||||
if is_quiet_mode(pretty_logger):
|
||||
logging.info(f"Conflict detected for {ess_path}, using first value: {first_value}")
|
||||
continue
|
||||
|
||||
# Group by value
|
||||
value_to_strategies: dict[str, list[str]] = {}
|
||||
for source in sources:
|
||||
value_str = str(source.value)
|
||||
value_to_strategies.setdefault(value_str, []).append(source.strategy_name)
|
||||
|
||||
pretty_logger.info(f"\n⚠️ CONFLICT for '{ess_path}'")
|
||||
pretty_logger.info(" Multiple configurations provide different values:")
|
||||
for source in sources:
|
||||
pretty_logger.info(f" • {source.strategy_name} ({source.source_path}): {source.value}")
|
||||
|
||||
selected_value, is_custom = prompt_for_conflict_resolution(
|
||||
pretty_logger, ess_path, value_to_strategies, enable_custom=True
|
||||
)
|
||||
|
||||
if is_custom:
|
||||
selected_value = prompt_value(pretty_logger, "Enter custom value:")
|
||||
|
||||
set_nested_value(ess_config, ess_path, selected_value)
|
||||
logging.info(f"Resolved {ess_path} = {selected_value}")
|
||||
|
||||
|
||||
def resolve_secret_conflicts(
|
||||
pretty_logger: logging.Logger,
|
||||
secret_tracking: DiscoveredSecretTracking,
|
||||
) -> None:
|
||||
"""Resolve conflicts where multiple strategies discovered different values for the same secret."""
|
||||
conflicts = secret_tracking.get_conflicts()
|
||||
if not conflicts:
|
||||
return
|
||||
|
||||
logger = logging.getLogger("migration")
|
||||
|
||||
pretty_logger.info("")
|
||||
pretty_logger.info("=" * 60)
|
||||
pretty_logger.info("🔐 RESOLVING SECRET CONFLICTS")
|
||||
pretty_logger.info("=" * 60)
|
||||
pretty_logger.info("Some secrets were discovered by multiple strategies with different values.")
|
||||
pretty_logger.info("Please select which value to use for each:")
|
||||
pretty_logger.info("")
|
||||
|
||||
if is_quiet_mode(pretty_logger):
|
||||
for secret_key, sources in sorted(conflicts.items()):
|
||||
logger.info("Conflict for %s: using first value (from %s)", secret_key, sources[0].strategy_name)
|
||||
secret_tracking.sources[secret_key] = [sources[0]]
|
||||
return
|
||||
|
||||
for secret_key, sources in sorted(conflicts.items()):
|
||||
# Group by value
|
||||
value_to_strategies: dict[str, list[str]] = {}
|
||||
for source in sources:
|
||||
value_to_strategies.setdefault(source.value, []).append(source.strategy_name)
|
||||
|
||||
pretty_logger.info("⚠️ Conflict for secret: %s", secret_key)
|
||||
pretty_logger.info(" Discovered by multiple strategies with different values:")
|
||||
for value, strategies in sorted(value_to_strategies.items()):
|
||||
display_value = value if len(value) <= 50 else f"{value[:47]}..."
|
||||
pretty_logger.info(f" • {display_value} (from: {', '.join(strategies)})")
|
||||
|
||||
selected_value, is_custom = prompt_for_conflict_resolution(pretty_logger, secret_key, value_to_strategies)
|
||||
|
||||
if is_custom:
|
||||
new_value = prompt_value(pretty_logger, "Enter custom value:")
|
||||
secret_tracking.sources[secret_key] = [
|
||||
SecretSource(
|
||||
strategy_name="user-provided",
|
||||
secret_key=secret_key,
|
||||
value=new_value,
|
||||
source_path="user input",
|
||||
)
|
||||
]
|
||||
else:
|
||||
secret_tracking.sources[secret_key] = [s for s in sources if s.value == selected_value]
|
||||
|
||||
pretty_logger.info(f" ✅ Resolved {secret_key}")
|
||||
pretty_logger.info("")
|
||||
|
||||
pretty_logger.info("=" * 60)
|
||||
@@ -11,15 +11,15 @@ import logging
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from .conflicts import resolve_secret_conflicts, resolve_value_conflicts
|
||||
from .element_web import ElementWebMigration
|
||||
from .extra_files import GenericExtraFileDiscovery
|
||||
from .hookshot import HookshotExtraFileDiscovery, HookshotMigration, HookshotSecretDiscovery
|
||||
from .inputs import InputProcessor
|
||||
from .mas import MASExtraFileDiscovery, MASMigration, MASSecretDiscovery
|
||||
from .migration import MigrationService
|
||||
from .models import ConfigMap, DiscoveredSecret, GlobalOptions, Secret, ValueSourceTracking
|
||||
from .models import ConfigMap, DiscoveredSecret, DiscoveredSecretTracking, GlobalOptions, Secret, ValueSourceTracking
|
||||
from .synapse import SynapseExtraFileDiscovery, SynapseMigration, SynapseSecretDiscovery
|
||||
from .utils import resolve_value_conflicts
|
||||
from .well_known import WELL_KNOWN_COMPONENT_ROOT_KEY, WellKnownMigration
|
||||
|
||||
logger = logging.getLogger("migration")
|
||||
@@ -41,6 +41,7 @@ class MigrationEngine:
|
||||
migrators: list[MigrationService] = field(default_factory=list)
|
||||
global_options: GlobalOptions = field(default_factory=GlobalOptions)
|
||||
value_source_tracking: ValueSourceTracking = field(default_factory=ValueSourceTracking)
|
||||
secret_tracking: DiscoveredSecretTracking = field(default_factory=DiscoveredSecretTracking)
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
"""Initialize the migration engine."""
|
||||
@@ -106,6 +107,7 @@ class MigrationEngine:
|
||||
configmaps=self.configmaps,
|
||||
global_options=self.global_options,
|
||||
value_source_tracking=self.value_source_tracking,
|
||||
secret_tracking=self.secret_tracking,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -142,7 +144,10 @@ class MigrationEngine:
|
||||
# Handle any secrets that were just prompted for
|
||||
migrator.handle_secrets_phase()
|
||||
|
||||
# Resolve conflicts after all migrations
|
||||
# Resolve secret conflicts after all migrations
|
||||
resolve_secret_conflicts(self.pretty_logger, self.secret_tracking)
|
||||
|
||||
# Resolve value conflicts after all migrations
|
||||
resolve_value_conflicts(self.pretty_logger, self.value_source_tracking, self.ess_config)
|
||||
|
||||
# Disable any ESS component that was not migrated (absent from config)
|
||||
|
||||
@@ -18,6 +18,7 @@ from .interfaces import ExtraFilesDiscoveryStrategy, MigrationStrategy, SecretDi
|
||||
from .models import (
|
||||
ConfigMap,
|
||||
DiscoveredExtraFile,
|
||||
DiscoveredSecretTracking,
|
||||
GlobalOptions,
|
||||
MigrationInput,
|
||||
Secret,
|
||||
@@ -445,6 +446,9 @@ class MigrationService:
|
||||
extra_files_strategy: ExtraFilesDiscoveryStrategy = field(init=True) # Extra files discovery service
|
||||
secret_discovery_strategy: SecretDiscoveryStrategy | None = field(init=True) # Secret discovery service
|
||||
value_source_tracking: ValueSourceTracking = field(init=True) # Shared value source tracking instance
|
||||
secret_tracking: DiscoveredSecretTracking = field(
|
||||
default_factory=DiscoveredSecretTracking
|
||||
) # Global tracking of discovered secrets
|
||||
override_warnings: list[str] = field(default_factory=list) # Warnings about overridden configurations
|
||||
underride_warnings: list[str] = field(default_factory=list) # Warnings about ESS default configurations
|
||||
discovered_extra_files: list[DiscoveredExtraFile] = field(default_factory=list) # List of discovered secrets
|
||||
@@ -475,6 +479,7 @@ class MigrationService:
|
||||
source_file=self.input.config_path,
|
||||
pretty_logger=self.pretty_logger,
|
||||
global_options=self.global_options,
|
||||
secret_tracking=self.secret_tracking,
|
||||
)
|
||||
self.secret_discovery.discover_secrets(self.input.config)
|
||||
# Note: prompt_for_missing_secrets() and validate_required_secrets()
|
||||
|
||||
@@ -189,3 +189,62 @@ class ValueSourceTracking:
|
||||
for s in srcs
|
||||
if s.source_path is not None and s.strategy_name == strategy_name
|
||||
]
|
||||
|
||||
|
||||
@dataclass
|
||||
class SecretSource:
|
||||
"""Represents a source of a discovered secret value."""
|
||||
|
||||
strategy_name: str # Name of the strategy that discovered the secret
|
||||
secret_key: str # ESS secret key (e.g., "synapse.signingKey")
|
||||
value: str # The secret value
|
||||
source_path: str # Original configuration path in source file
|
||||
|
||||
|
||||
@dataclass
|
||||
class DiscoveredSecretTracking:
|
||||
"""Tracks all discovered secrets across strategies to prevent duplicate prompts and detect conflicts."""
|
||||
|
||||
sources: dict[str, list[SecretSource]] = field(default_factory=dict)
|
||||
|
||||
def add_source(self, secret_key: str, strategy_name: str, value: str, source_path: str) -> None:
|
||||
"""Add a discovered secret source to tracking."""
|
||||
if secret_key not in self.sources:
|
||||
self.sources[secret_key] = []
|
||||
self.sources[secret_key].append(
|
||||
SecretSource(
|
||||
strategy_name=strategy_name,
|
||||
secret_key=secret_key,
|
||||
value=value,
|
||||
source_path=source_path,
|
||||
)
|
||||
)
|
||||
|
||||
def is_discovered(self, secret_key: str) -> bool:
|
||||
"""Check if a secret has been discovered by any strategy."""
|
||||
return secret_key in self.sources and len(self.sources[secret_key]) > 0
|
||||
|
||||
def get_all_values(self, secret_key: str) -> list[str]:
|
||||
"""Get all discovered values for a secret key."""
|
||||
if not self.is_discovered(secret_key):
|
||||
return []
|
||||
return [s.value for s in self.sources[secret_key]]
|
||||
|
||||
def get_conflicts(self) -> dict[str, list[SecretSource]]:
|
||||
"""Get all secret keys that have multiple sources with different values from different strategies."""
|
||||
conflicts = {}
|
||||
for secret_key, sources in self.sources.items():
|
||||
# Get unique values
|
||||
unique_values = set(s.value for s in sources)
|
||||
if len(unique_values) > 1:
|
||||
# Check if different strategies discovered different values
|
||||
strategies = set(s.strategy_name for s in sources)
|
||||
if len(strategies) > 1:
|
||||
conflicts[secret_key] = sources
|
||||
return conflicts
|
||||
|
||||
def get_strategies_for_secret(self, secret_key: str) -> list[str]:
|
||||
"""Get all strategy names that discovered a particular secret."""
|
||||
if not self.is_discovered(secret_key):
|
||||
return []
|
||||
return [s.strategy_name for s in self.sources[secret_key]]
|
||||
@@ -10,7 +10,7 @@ import logging
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from .interfaces import SecretDiscoveryStrategy
|
||||
from .models import DiscoverableSecret, DiscoveredSecret, GlobalOptions, SecretConfig
|
||||
from .models import DiscoverableSecret, DiscoveredSecret, DiscoveredSecretTracking, GlobalOptions, SecretConfig
|
||||
from .utils import (
|
||||
find_matching_schema_key,
|
||||
get_nested_value,
|
||||
@@ -36,6 +36,7 @@ class SecretDiscovery:
|
||||
pretty_logger: logging.Logger = field(init=True)
|
||||
source_file: str = field(init=True) # Source configuration file name
|
||||
global_options: GlobalOptions = field(init=True) # Global migration options
|
||||
secret_tracking: DiscoveredSecretTracking = field(init=True) # Global tracking of discovered secrets
|
||||
|
||||
discovered_secrets: dict[str, DiscoveredSecret] = field(default_factory=dict) # Secrets with source tracking
|
||||
init_by_ess_secrets: list[str] = field(default_factory=list) # Secrets to be initialized by ESS
|
||||
@@ -61,6 +62,13 @@ class SecretDiscovery:
|
||||
raise RuntimeError(f"Discovered component-specific secret '{secret_key}' not found in schema")
|
||||
# Add the discovered secret
|
||||
self.discovered_secrets[secret_key] = discovered_secret
|
||||
# Register with global tracking
|
||||
self.secret_tracking.add_source(
|
||||
secret_key=secret_key,
|
||||
strategy_name=self.strategy.secret_name,
|
||||
value=discovered_secret.value,
|
||||
source_path=discovered_secret.config_key,
|
||||
)
|
||||
|
||||
# Process component-specific discovery failures
|
||||
for discovered_secret, error_message in component_failures:
|
||||
@@ -184,6 +192,13 @@ class SecretDiscovery:
|
||||
value=discovered_value,
|
||||
)
|
||||
self.discovered_secrets[secret_key] = discovered_secret
|
||||
# Register with global tracking
|
||||
self.secret_tracking.add_source(
|
||||
secret_key=secret_key,
|
||||
strategy_name=self.strategy.secret_name,
|
||||
value=discovered_value,
|
||||
source_path=config_key,
|
||||
)
|
||||
|
||||
def _handle_missing_secret(
|
||||
self,
|
||||
@@ -199,6 +214,11 @@ class SecretDiscovery:
|
||||
- Add to init_by_ess_secrets (if init_if_missing_from_source_cfg)
|
||||
- Add to missing_required_secrets (if required)
|
||||
"""
|
||||
# Check if already discovered by another strategy
|
||||
if self.secret_tracking.is_discovered(secret_key):
|
||||
# Don't add to missing_required_secrets or init_by_ess_secrets
|
||||
return
|
||||
|
||||
# Optional secrets are ignored if not found
|
||||
if discoverable_secret.optional:
|
||||
return
|
||||
|
||||
@@ -17,7 +17,7 @@ from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives.asymmetric import ec, rsa
|
||||
|
||||
from .models import MigrationError, ValueSourceTracking
|
||||
from .models import MigrationError
|
||||
|
||||
|
||||
def yaml_dump_with_pipe_for_multiline(data: Any) -> str:
|
||||
@@ -643,51 +643,3 @@ def prompt_yes_no(
|
||||
except EOFError as err:
|
||||
pretty_logger.info("\n ❌ End of input reached")
|
||||
raise MigrationError("End of input reached during prompt") from err
|
||||
|
||||
|
||||
def resolve_value_conflicts(
|
||||
pretty_logger: logging.Logger,
|
||||
value_source_tracking: ValueSourceTracking,
|
||||
ess_config: dict[str, Any],
|
||||
) -> None:
|
||||
"""Resolve conflicts where multiple strategies provide different values for same ESS path."""
|
||||
conflicts = value_source_tracking.get_conflicts()
|
||||
if not conflicts:
|
||||
return
|
||||
|
||||
for ess_path, sources in sorted(conflicts.items()):
|
||||
first_value = sources[0].value
|
||||
all_same = all(str(v.value) == str(first_value) for v in sources)
|
||||
|
||||
if all_same:
|
||||
logging.debug(f"Consistent values for {ess_path}: {first_value}")
|
||||
continue
|
||||
|
||||
if is_quiet_mode(pretty_logger):
|
||||
logging.info(f"Conflict detected for {ess_path}, using first value: {first_value}")
|
||||
continue
|
||||
|
||||
pretty_logger.info(f"\n⚠️ CONFLICT for '{ess_path}'")
|
||||
pretty_logger.info(" Multiple configurations provide different values:")
|
||||
for source in sources:
|
||||
pretty_logger.info(f" • {source.strategy_name} ({source.source_path}): {source.value}")
|
||||
|
||||
value_to_strategies: dict[str, list[str]] = {}
|
||||
for source in sources:
|
||||
value_str = str(source.value)
|
||||
value_to_strategies.setdefault(value_str, []).append(source.strategy_name)
|
||||
|
||||
options = [f"{v} (from: {', '.join(ss)})" for v, ss in value_to_strategies.items()]
|
||||
options.append("Enter custom value")
|
||||
|
||||
choice = prompt_choice(pretty_logger, f"Select value for '{ess_path}':", options)
|
||||
|
||||
if choice == "Enter custom value":
|
||||
new_value = prompt_value(pretty_logger, "Enter custom value:")
|
||||
set_nested_value(ess_config, ess_path, new_value)
|
||||
else:
|
||||
value_str = choice.split(" (")[0]
|
||||
final_value = next((s.value for s in sources if str(s.value) == value_str), first_value)
|
||||
set_nested_value(ess_config, ess_path, final_value)
|
||||
|
||||
logging.info(f"Resolved {ess_path} = {final_value}")
|
||||
@@ -867,14 +867,14 @@ def test_main_e2e_synapse_with_mas_different_server_name(
|
||||
|
||||
# Mock user inputs:
|
||||
# 1. Database choice - use existing database (default, empty string)
|
||||
# 2. Conflict resolution - select option 1 (synapse.example.com)
|
||||
# 2. Conflict resolution - select option 2 (synapse.example.com)
|
||||
# The prompt will be: "Select value for 'serverName':"
|
||||
# Options:
|
||||
# - "synapse.example.com (from: Synapse)"
|
||||
# - "mas.example.com (from: Matrix Authentication Service)"
|
||||
# - "synapse.example.com (from: Synapse)"
|
||||
# - "Enter custom value"
|
||||
# Selection "1" picks synapse.example.com
|
||||
side_effect = (n for n in ("", "1"))
|
||||
# Selection "2" picks synapse.example.com
|
||||
side_effect = (n for n in ("", "2"))
|
||||
monkeypatch.setattr(sys, "argv", test_args)
|
||||
monkeypatch.setattr("builtins.input", lambda _: next(side_effect))
|
||||
exit_code = __main__.main()
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
# Copyright 2026 Element Creations Ltd
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
"""
|
||||
Unit tests for secret conflict resolution functionality.
|
||||
Tests the DiscoveredSecretTracking class and integration with SecretDiscovery.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from ess_migration_tool.models import DiscoveredSecretTracking, GlobalOptions
|
||||
from ess_migration_tool.secrets import SecretDiscovery
|
||||
from ess_migration_tool.synapse import SynapseSecretDiscovery
|
||||
|
||||
|
||||
def test_add_source_and_is_discovered():
|
||||
"""Test adding a source and checking if secret is discovered."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
|
||||
assert not tracking.is_discovered("synapse.signingKey")
|
||||
|
||||
tracking.add_source("synapse.signingKey", "synapse", "test_key_value", "signing_key")
|
||||
|
||||
assert tracking.is_discovered("synapse.signingKey")
|
||||
|
||||
|
||||
def test_get_all_values():
|
||||
"""Test that get_all_values returns all discovered values."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
|
||||
tracking.add_source("synapse.signingKey", "synapse", "value1", "path1")
|
||||
tracking.add_source("synapse.signingKey", "synapse", "value2", "path2")
|
||||
|
||||
values = tracking.get_all_values("synapse.signingKey")
|
||||
assert len(values) == 2
|
||||
assert "value1" in values
|
||||
assert "value2" in values
|
||||
|
||||
|
||||
def test_get_all_values_empty():
|
||||
"""Test get_all_values for undiscovered secret."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
|
||||
values = tracking.get_all_values("synapse.signingKey")
|
||||
assert values == []
|
||||
|
||||
|
||||
def test_no_conflict_with_same_value():
|
||||
"""Test that no conflict is detected when all sources have the same value."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
|
||||
tracking.add_source("synapse.signingKey", "synapse", "same_value", "path1")
|
||||
tracking.add_source("synapse.signingKey", "mas", "same_value", "path2")
|
||||
|
||||
conflicts = tracking.get_conflicts()
|
||||
assert "synapse.signingKey" not in conflicts
|
||||
|
||||
|
||||
def test_conflict_with_different_values():
|
||||
"""Test that conflict is detected when sources have different values from different strategies."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
|
||||
tracking.add_source("synapse.signingKey", "synapse", "value1", "path1")
|
||||
tracking.add_source("synapse.signingKey", "mas", "value2", "path2")
|
||||
|
||||
conflicts = tracking.get_conflicts()
|
||||
assert "synapse.signingKey" in conflicts
|
||||
assert len(conflicts["synapse.signingKey"]) == 2
|
||||
|
||||
|
||||
def test_no_conflict_with_single_source():
|
||||
"""Test that no conflict is detected with a single source."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
|
||||
tracking.add_source("synapse.signingKey", "synapse", "value1", "path1")
|
||||
|
||||
conflicts = tracking.get_conflicts()
|
||||
assert "synapse.signingKey" not in conflicts
|
||||
|
||||
|
||||
def test_no_conflict_same_strategy_different_values():
|
||||
"""Test that same strategy with different values doesn't count as conflict."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
|
||||
tracking.add_source("synapse.signingKey", "synapse", "value1", "path1")
|
||||
tracking.add_source("synapse.signingKey", "synapse", "value2", "path2")
|
||||
|
||||
conflicts = tracking.get_conflicts()
|
||||
assert "synapse.signingKey" not in conflicts
|
||||
|
||||
|
||||
def test_get_strategies_for_secret():
|
||||
"""Test getting all strategies that discovered a secret."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
|
||||
tracking.add_source("synapse.signingKey", "synapse", "value1", "path1")
|
||||
tracking.add_source("synapse.signingKey", "mas", "value2", "path2")
|
||||
|
||||
strategies = tracking.get_strategies_for_secret("synapse.signingKey")
|
||||
assert len(strategies) == 2
|
||||
assert "synapse" in strategies
|
||||
assert "mas" in strategies
|
||||
|
||||
|
||||
def test_get_strategies_for_undiscovered_secret():
|
||||
"""Test getting strategies for an undiscovered secret."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
|
||||
strategies = tracking.get_strategies_for_secret("synapse.signingKey")
|
||||
assert strategies == []
|
||||
|
||||
|
||||
def test_secret_discovery_uses_tracking():
|
||||
"""Test that SecretDiscovery uses tracking when provided."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
global_options = GlobalOptions()
|
||||
strategy = SynapseSecretDiscovery(global_options)
|
||||
|
||||
discovery = SecretDiscovery(
|
||||
strategy=strategy,
|
||||
source_file="test.yaml",
|
||||
pretty_logger=logging.getLogger("test"),
|
||||
global_options=global_options,
|
||||
secret_tracking=tracking,
|
||||
)
|
||||
|
||||
assert discovery.secret_tracking is tracking
|
||||
|
||||
|
||||
def test_discovered_secret_registered_with_tracking():
|
||||
"""Test that discovered secrets are registered with tracking."""
|
||||
tracking = DiscoveredSecretTracking()
|
||||
global_options = GlobalOptions()
|
||||
strategy = SynapseSecretDiscovery(global_options)
|
||||
|
||||
discovery = SecretDiscovery(
|
||||
strategy=strategy,
|
||||
source_file="test.yaml",
|
||||
pretty_logger=logging.getLogger("test"),
|
||||
global_options=global_options,
|
||||
secret_tracking=tracking,
|
||||
)
|
||||
|
||||
test_config = {"signing_key": "test_signing_key_value"}
|
||||
|
||||
discovery.discover_secrets(test_config)
|
||||
|
||||
assert tracking.is_discovered("synapse.signingKey")
|
||||
|
||||
|
||||
def test_synapse_signing_key_not_optional():
|
||||
"""Test that synapse.signingKey is not optional in SynapseSecretDiscovery."""
|
||||
global_options = GlobalOptions()
|
||||
strategy = SynapseSecretDiscovery(global_options)
|
||||
|
||||
schema = strategy.ess_secret_schema
|
||||
signing_key_config = schema.get("synapse.signingKey")
|
||||
|
||||
assert signing_key_config is not None
|
||||
assert not signing_key_config.optional
|
||||
Reference in new issue
Block a user