test: validate grpc data connections with local docker and opcua cli
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
"""Credential-only mutations require fresh numeric evidence from the actual seeder path."""
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
import scenarios
|
||||
|
||||
|
||||
def receipt():
|
||||
revisions = {"Connection": 7, "Mappings": {"map-raw": 11, "map-uns": 12},
|
||||
"Exports": {"export-raw": 13, "export-uns": 14}}
|
||||
return {"keyAction": "rotate", "revisions": {"CredentialOnly": True, "Before": revisions, "After": deepcopy(revisions)}}
|
||||
|
||||
|
||||
class KeyOnlyRevisionEvidenceTests(unittest.TestCase):
|
||||
def test_only_matching_credential_action_and_unchanged_numeric_revisions_pass(self):
|
||||
valid = receipt()
|
||||
self.assertIs(scenarios.validate_key_only_revision_receipt(valid, action="rotate"), valid)
|
||||
invalid = []
|
||||
for field, value in (("Connection", 8), ("Mappings", {"map-raw": 12, "map-uns": 12}),
|
||||
("Exports", {"export-raw": 14, "export-uns": 14}), ("Connection", True)):
|
||||
actual = deepcopy(valid)
|
||||
actual["revisions"]["After"][field] = value
|
||||
invalid.append(actual)
|
||||
invalid += [dict(valid, keyAction="revoke"), {"keyAction": "rotate", "revisions": {}},
|
||||
{"keyAction": "rotate", "revisions": dict(valid["revisions"], CredentialOnly=False)}]
|
||||
for actual in invalid:
|
||||
with self.subTest(actual=actual), self.assertRaises(scenarios.ScenarioError):
|
||||
scenarios.validate_key_only_revision_receipt(actual, action="rotate")
|
||||
|
||||
def runner(self, folder):
|
||||
runner = object.__new__(scenarios.ScenarioRunner)
|
||||
runner.active, runner.timeline, runner.secrets = "D06", [], []
|
||||
runner.rig = Mock(folder=folder)
|
||||
runner.rig.deploy.return_value = {"credentials": {"data_key_files": {}}, "deployment": {"revision_hash": "current"}}
|
||||
runner.remaining = Mock(side_effect=lambda maximum: maximum)
|
||||
runner.save = Mock()
|
||||
(folder / "seed").mkdir()
|
||||
return runner
|
||||
|
||||
def test_key_only_requires_fresh_actual_seeder_receipt_before_deploy_and_copies_evidence(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
runner = self.runner(Path(temporary))
|
||||
path = Path(temporary) / "seed/mutation-revisions.json"
|
||||
scenarios.rig.atomic_write_secret(path, scenarios.json.dumps(receipt()))
|
||||
def seed(action):
|
||||
self.assertEqual(action, "mutate")
|
||||
self.assertFalse(path.exists(), "a prior mutation receipt cannot satisfy the current mutation")
|
||||
scenarios.rig.atomic_write_secret(path, scenarios.json.dumps(receipt()))
|
||||
runner.rig.seed_helper.side_effect = seed
|
||||
runner.mutate(key_action="rotate")
|
||||
runner.rig.deploy.assert_called_once()
|
||||
self.assertEqual(runner.save.call_count, 1)
|
||||
self.assertEqual(runner.save.call_args.args[1], receipt())
|
||||
|
||||
def test_missing_key_only_receipt_prevents_deploy_but_mixed_configuration_uses_normal_path(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
runner = self.runner(Path(temporary))
|
||||
with self.assertRaises(scenarios.ScenarioError):
|
||||
runner.mutate(key_action="rotate")
|
||||
runner.rig.deploy.assert_not_called()
|
||||
runner.mutate(key_action="rotate", mapping_enabled=False)
|
||||
runner.rig.deploy.assert_called_once()
|
||||
runner.save.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user