mirror of
https://github.com/floci-io/floci.git
synced 2026-12-06 11:38:06 -05:00
The Service Reference lists a tag key named after each DMS resource
type, dms:rep-tag/${TagKey} on a replication instance and
dms:endpoint-tag/${TagKey} on an endpoint, which Floci never filled, so
a condition on one never matched. The DMS User Guide says "The tag keys
are prefixed with "dms", the resource type, and the "tag" prefix", in
the format dms:{resource type}-tag/{tag key}, and that such a key
"matches a resource with the given tag".
A fetcher vendors that section of the guide. The request-resources
generator reads a key of the format the reference lists on a type as
that type's stored-tag prefix, leaving out dms:req-tag/, the request's
tags, and refusing a key listed on two types. It writes the format as
tagKeyFormats, which the reader checks those keys against.
The request-resources check now also runs when one of the vendored
sources its generator reads changes, several of which were missing from
the Makefile's paths and the drift workflow's triggers.
120 lines
5.9 KiB
Python
120 lines
5.9 KiB
Python
"""Exercise IAM gate selection without contacting the live AWS reference."""
|
|
import importlib
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
class IamDataVerifyTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.temporary = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.temporary.cleanup)
|
|
self.directory = Path(self.temporary.name)
|
|
self.calls = self.directory / "calls"
|
|
self.make = self.directory / "make"
|
|
self.make.write_text(
|
|
'#!/bin/sh\nprintf "%s\\n" "$*" >> "$CALLS"\n'
|
|
'[ "$*" != "--no-print-directory $FAIL_TARGET" ]\n'
|
|
)
|
|
self.make.chmod(0o700)
|
|
|
|
def run_gate(self, *arguments, fail_target=""):
|
|
result = subprocess.run(
|
|
["make", "--no-print-directory", "iam-data-verify", f"MAKE={self.make}", *arguments],
|
|
cwd=Path(__file__).resolve().parents[2],
|
|
env={**os.environ, "CALLS": str(self.calls), "FAIL_TARGET": fail_target},
|
|
text=True, capture_output=True,
|
|
)
|
|
calls = self.calls.read_text().splitlines() if self.calls.exists() else []
|
|
return result, [line.split()[-1] for line in calls]
|
|
|
|
def changed_file(self, text):
|
|
path = self.directory / "changed"
|
|
path.write_text(text)
|
|
return f"CHANGED_FILE={path}"
|
|
|
|
def test_large_diff_selects_only_affected_check(self):
|
|
paths = "".join(f"src/test/unrelated/path_{index}.java\n" for index in range(10000))
|
|
paths += "src/main/resources/aws/iam-service-namespaces.json\n"
|
|
self.assertGreater(len(paths), 131072)
|
|
result, calls = self.run_gate(self.changed_file(paths))
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertEqual(["iam-namespaces-verify"], calls)
|
|
|
|
def test_unrelated_diff_runs_no_checks(self):
|
|
result, calls = self.run_gate(self.changed_file("docs/index.md\n"))
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertEqual([], calls)
|
|
|
|
def test_empty_diff_keeps_full_verification(self):
|
|
result, calls = self.run_gate(self.changed_file(""))
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertEqual(15, len(calls))
|
|
|
|
def test_weekly_run_checks_every_file(self):
|
|
result, calls = self.run_gate()
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertEqual(15, len(calls))
|
|
|
|
def test_the_cloudtrail_s3_data_events_check_covers_its_fetcher(self):
|
|
result, calls = self.run_gate(self.changed_file("tools/aws/fetch_cloudtrail_s3_data_events.py\n"))
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertEqual(["cloudtrail-s3-data-events-verify"], calls)
|
|
|
|
def test_the_cloudwatch_otel_enrichment_check_covers_its_generator(self):
|
|
result, calls = self.run_gate(self.changed_file("tools/aws/regen_cloudwatch_otel_enrichment.py\n"))
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertEqual(["cloudwatch-otel-enrichment-verify"], calls)
|
|
|
|
def test_the_elasticache_otel_metrics_check_covers_its_generator(self):
|
|
result, calls = self.run_gate(self.changed_file("tools/aws/regen_elasticache_otel_metrics.py\n"))
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertEqual(["elasticache-otel-metrics-verify"], calls)
|
|
|
|
def test_the_request_resources_check_covers_every_page_its_generator_vendors(self):
|
|
"""Each module the request-resources generator imports to vendor an AWS page, with its vendored file and its
|
|
tests, selects the generator's check and is a path the workflow runs on, and its tests run with the
|
|
generator's."""
|
|
root = Path(__file__).resolve().parents[2]
|
|
generator = (root / "tools/aws/regen_iam_request_resources.py").read_text(encoding="utf-8")
|
|
workflow = (root / ".github/workflows/iam-data-drift.yml").read_text(encoding="utf-8")
|
|
fetchers = re.findall(r"^import (fetch_\w+)$", generator, re.M)
|
|
self.assertIn("fetch_dms_tag_keys", fetchers)
|
|
tests = subprocess.run(["make", "--no-print-directory", "-n", "iam-request-resources-test"], cwd=root,
|
|
text=True, capture_output=True, check=True).stdout.split()
|
|
self.assertIn("tools/aws/test_regen_iam_request_resources.py", tests)
|
|
for fetcher in fetchers:
|
|
output = Path(importlib.import_module(fetcher).OUTPUT).resolve().relative_to(root)
|
|
for path in (str(output), f"tools/aws/{fetcher}.py", f"tools/aws/test_{fetcher}.py"):
|
|
self.calls.unlink(missing_ok=True)
|
|
result, calls = self.run_gate(self.changed_file(path + "\n"))
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertIn("iam-request-resources-verify", calls, path)
|
|
self.assertIn(f" - '{path}'\n", workflow, path)
|
|
self.assertIn(f"tools/aws/test_{fetcher}.py", tests, fetcher)
|
|
|
|
def test_legacy_changed_argument_still_selects(self):
|
|
result, calls = self.run_gate("CHANGED= tools/aws/regen_service_namespaces.py ")
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertEqual(["iam-namespaces-verify"], calls)
|
|
|
|
def test_missing_file_fails_without_silently_skipping(self):
|
|
result, calls = self.run_gate(f"CHANGED_FILE={self.directory / 'missing'}")
|
|
self.assertNotEqual(0, result.returncode)
|
|
self.assertEqual([], calls)
|
|
|
|
def test_failed_check_does_not_hide_later_checks(self):
|
|
result, calls = self.run_gate(self.changed_file(
|
|
"tools/aws/regen_service_namespaces.py\ntools/aws/regen_iam_action_resources.py\n"
|
|
), fail_target="iam-namespaces-verify")
|
|
self.assertNotEqual(0, result.returncode)
|
|
self.assertEqual(["iam-namespaces-verify", "iam-action-resources-verify"], calls)
|
|
self.assertIn("the service namespace list", result.stdout)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|