fix(cloudfront): report Logging on distribution reads (#3318)

* fix(cloudfront): report Logging on distribution reads

GetDistribution and GetDistributionConfig omitted the Logging member of
DistributionConfig. It is "Required: No" on input, but CloudFront reports it on
every response with its defaults, and callers read it unconditionally: the AWS
SDKs and the Terraform provider both expect the element to be present.

Report it with the defaults CloudFront uses, a disabled configuration with an
empty bucket and prefix, and echo an explicitly supplied one back in full. The
model already carried the field; it was simply never written to the response.

Restrictions and OriginGroups had the same gap and are already handled, so only
Logging is added here.

Reference: the DistributionConfig members and their types
https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_DistributionConfig.html

* fix(cloudfront): parse the Logging block on distribution writes

Reads report Logging, but parseDistributionConfig never read it from the
request body, so CreateDistribution and UpdateDistribution dropped an
explicit block and the caller read the disabled defaults back. That is the
drift aws_cloudfront_distribution sees on logging_config: it sends a
configuration and gets defaults.

parseLogging follows parseGeoRestriction, extracting Enabled,
IncludeCookies, Bucket and Prefix. An absent block yields an empty map,
which xmlLogging still renders as today's disabled defaults.

The existing coverage built the model in Java and inserted it through
CloudFrontService, so it passed with the parser missing. The new tests POST
and PUT a DistributionConfig body over HTTP and read it back, which is what
puts the parser under test.

* test(cloudfront): take CloudFrontService through the constructor

AGENTS.md asks for constructor injection and this test used an @Inject field.

I had argued against changing it on the grounds that a @QuarkusTest cannot take
constructor injection, since JUnit 5 needs a registered ParameterResolver and I
believed Quarkus does not supply one for CDI beans. That is wrong. A probe with a
constructor taking CloudFrontService compiles and passes, so the 0-of-736 count in
this repo reflects habit rather than a constraint.

209 CloudFront tests still pass.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-09-10 10:14:32 -04:00
1 parent 49903ab9fe
commit d4e9dcbe55
2 files changed
+285

No files matched your search

@@ -1832,10 +1832,29 @@ public class CloudFrontController {
xml.raw(xmlViewerCertificate(cfg.getViewerCertificate()));
xml.raw(xmlRestrictions(cfg.getGeoRestriction()));
xml.raw(xmlLogging(cfg.getLogging()));
return xml.build();
}
/**
* Logging is always present on a real DistributionConfig response, disabled by
* default. Callers read it unconditionally, so omitting it when the caller did not
* supply one leaves the member missing from every read.
*/
private String xmlLogging(Map<String, Object> logging) {
return new XmlBuilder()
.start("Logging")
.elem("Enabled", logging != null
&& Boolean.parseBoolean(str(logging.get("Enabled"))))
.elem("IncludeCookies", logging != null
&& Boolean.parseBoolean(str(logging.get("IncludeCookies"))))
.elem("Bucket", logging != null ? str(logging.get("Bucket")) : "")
.elem("Prefix", logging != null ? str(logging.get("Prefix")) : "")
.end("Logging")
.build();
}
private String xmlEmptyOriginGroups() {
// Presence-only OriginGroups is intentional for Terraform compatibility; round-tripping groups is deferred.
return new XmlBuilder()
@@ -2478,6 +2497,7 @@ public class CloudFrontController {
cfg.setViewerCertificate(parseViewerCertificate(body));
cfg.setCustomErrorResponses(parseCustomErrorResponses(body));
cfg.setGeoRestriction(parseGeoRestriction(body));
cfg.setLogging(parseLogging(body));
return cfg;
}
@@ -2610,6 +2630,20 @@ public class CloudFrontController {
return result;
}
/**
* Parses the optional {@code Logging} block into {@code Enabled}, {@code IncludeCookies},
* {@code Bucket} and {@code Prefix} (values kept as strings). A request that omits the block
* yields an empty map rather than {@code null}, which {@link #xmlLogging} renders as the
* disabled defaults CloudFront reports for a distribution that never asked for access logs.
*/
private Map<String, Object> parseLogging(String body) {
List<Map<String, String>> groups = XmlParser.extractGroups(body, "Logging");
if (groups.isEmpty()) {
return Map.of();
}
return new LinkedHashMap<>(groups.getFirst());
}
private Map<String, Object> parseGeoRestriction(String body) {
List<Map<String, String>> groups = XmlParser.extractGroups(body, GEO_RESTRICTION);
if (groups.isEmpty()) {