Add certificate replacement lifecycle
This commit is contained in:
@@ -500,6 +500,121 @@ class EndpointPlanningTests(unittest.TestCase):
|
||||
desired.references,
|
||||
)
|
||||
|
||||
def test_older_certificate_is_replace_and_dependent_proxy_is_update(self):
|
||||
endpoint = Endpoint(
|
||||
"generic",
|
||||
"node.example:443",
|
||||
)
|
||||
|
||||
generic_adapter = adapter(
|
||||
"generic",
|
||||
"node.example:443",
|
||||
CERTIFICATES,
|
||||
PROXY_HOSTS,
|
||||
)
|
||||
|
||||
desired_certificate = NormalizedObject(
|
||||
object_type=CERTIFICATES,
|
||||
logical_key="app.example.com",
|
||||
payload={
|
||||
"domain_names": ["app.example.com"],
|
||||
"valid_from": "2026-09-20T00:00:00+00:00",
|
||||
"expires_on": "2026-12-20T00:00:00+00:00",
|
||||
},
|
||||
)
|
||||
|
||||
desired_proxy = NormalizedObject(
|
||||
object_type=PROXY_HOSTS,
|
||||
logical_key="app.example.com",
|
||||
payload={
|
||||
"domain_names": ["app.example.com"],
|
||||
"forward_scheme": "https",
|
||||
"forward_host": "backend.internal",
|
||||
"forward_port": 443,
|
||||
"enabled": True,
|
||||
},
|
||||
references=(
|
||||
ObjectReference(
|
||||
relation="certificate",
|
||||
object_type=CERTIFICATES,
|
||||
logical_key="app.example.com",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
current_certificate = NormalizedObject(
|
||||
object_type=CERTIFICATES,
|
||||
logical_key="app.example.com",
|
||||
local_key="67",
|
||||
payload={
|
||||
"domain_names": ["app.example.com"],
|
||||
"valid_from": "2026-08-20T00:00:00+00:00",
|
||||
"expires_on": "2026-11-20T00:00:00+00:00",
|
||||
},
|
||||
)
|
||||
|
||||
current_proxy = NormalizedObject(
|
||||
object_type=PROXY_HOSTS,
|
||||
logical_key="app.example.com",
|
||||
local_key="12",
|
||||
payload=dict(desired_proxy.payload),
|
||||
references=(
|
||||
ObjectReference(
|
||||
relation="certificate",
|
||||
object_type=CERTIFICATES,
|
||||
local_key="67",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
plans = build_endpoint_plans(
|
||||
[generic_adapter],
|
||||
[
|
||||
desired_certificate,
|
||||
desired_proxy,
|
||||
],
|
||||
[
|
||||
observed(
|
||||
endpoint.identity,
|
||||
current_certificate,
|
||||
),
|
||||
observed(
|
||||
endpoint.identity,
|
||||
current_proxy,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
self.assertEqual(len(plans), 1)
|
||||
|
||||
actions = plans[0].actions
|
||||
|
||||
self.assertEqual(
|
||||
[
|
||||
(
|
||||
action.operation,
|
||||
action.desired.object_type,
|
||||
)
|
||||
for action in actions
|
||||
],
|
||||
[
|
||||
(
|
||||
PlanOperation.REPLACE,
|
||||
CERTIFICATES,
|
||||
),
|
||||
(
|
||||
PlanOperation.UPDATE,
|
||||
PROXY_HOSTS,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
actions[1].reason,
|
||||
"referenced object is being replaced",
|
||||
)
|
||||
|
||||
|
||||
def test_duplicate_endpoint_objects_fail_without_payload_output(self):
|
||||
desired = [
|
||||
dns_object("app.example.com", "192.168.1.101")
|
||||
|
||||
Reference in New Issue
Block a user