Skip to content

fix(cdn): move a Fastly domain to the configured service before requesting its certificate - #303

Merged
Meldiron merged 2 commits into
fix/cdn-fastly-blocked-authorizationsfrom
fix/cdn-fastly-reassign-before-tls
Sep 21, 2026
Merged

Meldiron merged 2 commits into
fix/cdn-fastly-blocked-authorizationsfrom
fix/cdn-fastly-reassign-before-tls

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

Stacked on #300 so the diff is only this change; the base switches to main once that merges. #222 rewrites the same block for orphaned domains and will conflict with either.

Problem

In Fastly::issueCertificate, a versionless domain attached to another service was moved only after its TLS subscription reported issued or renewing. A fresh subscription is always pending, so on the call that creates it the move is skipped, and nothing revisits it: the consumer's status sync marks the rule verified once the certificate issues but never touches the domain record, and a verified rule does not request issuance again. isRenewRequired does report true for the wrong service, but only maintenance asks it, and only for rows whose renew date has passed. So a hostname that arrives on the wrong service stays there until someone moves it by hand.

The gate was guarding against a coupling that does not exist. service_id on a domain-management record decides which service's origin answers the hostname, nothing more. The TLS subscription belongs to the account and a TLS configuration, keyed by hostname, so moving the domain changes nothing about its certificate, and a pending or blocked subscription is exactly as pending or blocked on either service.

Change

  • Reassign first, unconditionally, then run the subscription flow. The ISSUED/RENEWING check and the catch (Certificate) that fix(cdn): report blocked Fastly domain validation instead of pending #300 added around it go away, since nothing reads the status in this method anymore.
  • A refused PATCH still throws, before any TLS call, so the next attempt finds the same state and retries the move.
  • The classic-domain branch is unchanged: moving one of those means cloning and activating a service version, a different operation.
  • README: one sentence on the managed provider's behaviour for a domain found on another service.

Tests

FastlyTest.php, all scripted through the existing TestClient, asserting the call sequence and outcome:

  • issued subscription: GET domains, PATCH to the configured service, GET subscriptions
  • pending subscription: same sequence, returns null
  • blocked authorization (the fix(cdn): report blocked Fastly domain validation instead of pending #300 case): same sequence, returns null
  • PATCH refused: throws reassign Fastly domain, no TLS call made
  • TLS lookup fails after the move: throws fetch Fastly TLS subscriptions, the move stands

bin/monorepo check cdn passes (Pint, PHPStan, Rector). Vale passes on the README. Tests were not run locally.

🤖 Generated with Claude Code

…sting its certificate

A domain attached to another service was moved only once its TLS subscription
reported issued. A fresh subscription is always pending, so the move almost
never happened on that call, and nothing revisits it: the consumer's status
sync marks the rule verified when the certificate issues but never touches the
domain record. Hostnames stayed on the old service for good.

The service decides routing only; the subscription belongs to the account and
follows the hostname. Issuance is requested by the one rule that owns the
domain, after its DNS verified, so the configured service is where the hostname
belongs whatever the certificate is doing. Reassign first, then run the
subscription flow. A refused PATCH throws before any TLS call, so the next
attempt finds the same state and retries the move.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The implementation appears safe to merge, although the non-blocking test-quality concern from the previous review remains unresolved.

Fix All in Claude CodeFindings

  1. P2 Tests mirror HTTP choreography ▶
Fix with agent prompt
### Issue 1
packages/cdn/tests/Cdn/Certificates/Provider/FastlyTest.php:76-80
These tests hard-code exact call counts, array positions, methods, URLs, payloads, and ordering. This violates the repository directive to test observable behavior instead of mirroring source implementation. An equivalent client refactor would fail these tests even if domain ownership and certificate behavior stayed correct, while the canned response queue still does not prove the resulting provider state. Replace this request choreography with a stateful fake that verifies the resulting domain ownership and TLS behavior. The same problem appears in the pending, reassignment-failure, and TLS-failure cases. This repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR changes Fastly certificate issuance so a versionless domain attached to another service is reassigned to the configured service before the TLS subscription flow begins.

  • Removes certificate-status gating from domain reassignment.
  • Preserves early failure when Fastly refuses the reassignment.
  • Documents that service assignment controls routing independently of the account-level TLS subscription.
  • Updates tests for issued, pending, blocked, reassignment-failure, and TLS-failure paths.

Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/fix..."

Comment on lines +76 to 80
$this->assertCount(3, $client->calls);
$this->assertSame('PATCH', $client->calls[1]['method']);
$this->assertSame('https://api.fastly.com/domain-management/v1/domains/domain_1', $client->calls[1]['url']);
$this->assertSame(['service_id' => 'new_service'], $client->calls[1]['body']);
$this->assertStringStartsWith('https://api.fastly.com/tls/subscriptions?', $client->calls[2]['url']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests mirror HTTP choreography

These tests hard-code exact call counts, array positions, methods, URLs, payloads, and ordering. This violates the repository directive to test observable behavior instead of mirroring source implementation. An equivalent client refactor would fail these tests even if domain ownership and certificate behavior stayed correct, while the canned response queue still does not prove the resulting provider state. Replace this request choreography with a stateful fake that verifies the resulting domain ownership and TLS behavior. The same problem appears in the pending, reassignment-failure, and TLS-failure cases. This repository requirement must be satisfied before merging.

Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cdn/tests/Cdn/Certificates/Provider/FastlyTest.php
Line: 76-80

Comment:
**Tests mirror HTTP choreography**

These tests hard-code exact call counts, array positions, methods, URLs, payloads, and ordering. This violates the repository directive to test observable behavior instead of mirroring source implementation. An equivalent client refactor would fail these tests even if domain ownership and certificate behavior stayed correct, while the canned response queue still does not prove the resulting provider state. Replace this request choreography with a stateful fake that verifies the resulting domain ownership and TLS behavior. The same problem appears in the pending, reassignment-failure, and TLS-failure cases. This repository requirement must be satisfied before merging.

**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

…tions' into fix/cdn-fastly-reassign-before-tls

# Conflicts:
#	packages/cdn/src/Cdn/Certificates/Provider/Fastly.php
@Meldiron
Meldiron merged commit 5a36d83 into fix/cdn-fastly-blocked-authorizations Sep 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant