mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudfront): echo TrustedSigners in cache behaviors so the AWS provider does not segfault (#3015)
Creating an aws_cloudfront_distribution against floci crashes the Terraform/
pulumi AWS provider on read-back: DefaultCacheBehavior (and CacheBehavior) omit
the TrustedSigners object, but the provider does len(dcb.TrustedSigners.Items)
with no nil guard (flattenDefaultCacheBehavior), so an omitted object is a nil
pointer dereference (SIGSEGV) that kills the apply and orphans the distribution.
Floci models only the modern TrustedKeyGroups, but real AWS always echoes a
TrustedSigners object even when unused ({Enabled:false, Quantity:0}). Emit that
disabled form in both cache-behavior writers, next to TrustedKeyGroups.
Refs #2767 (the TrustedSigners crash; the ForwardedValues/MinTTL and
AllowedMethods.CachedMethods fidelity gaps listed there are left as follow-ups).
Adds a regression test asserting getDistribution's DefaultCacheBehavior echoes a
disabled TrustedSigners; it fails (object absent) before the fix.
This commit is contained in:
1 parent
7b5c6e272d
commit
75e93e5e77
2 files changed
+47
No files matched your search
+33
@@ -158,6 +158,39 @@ class CloudFrontControllerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultCacheBehaviorEchoesTrustedSignersSoTheAwsProviderDoesNotSegfault() {
|
||||
CloudFrontService service = mock(CloudFrontService.class);
|
||||
CloudFrontController controller = new CloudFrontController(service);
|
||||
|
||||
String body = distributionConfigBody("");
|
||||
|
||||
ArgumentCaptor<Distribution> captor = ArgumentCaptor.forClass(Distribution.class);
|
||||
when(service.createDistribution(captor.capture(), any())).thenAnswer(inv -> {
|
||||
Distribution d = inv.getArgument(0);
|
||||
d.setId("dist-ts");
|
||||
d.setEtag("etag-ts");
|
||||
return d;
|
||||
});
|
||||
|
||||
try (Response created = controller.createDistribution(null, body)) {
|
||||
assertEquals(201, created.getStatus());
|
||||
}
|
||||
|
||||
when(service.getDistribution("dist-ts")).thenReturn(captor.getValue());
|
||||
|
||||
// The Terraform AWS provider reads DefaultCacheBehavior.TrustedSigners.Items with no nil
|
||||
// guard, so an omitted object segfaults it on read-back. AWS always echoes the disabled form.
|
||||
try (Response dist = controller.getDistribution("dist-ts")) {
|
||||
String xml = (String) dist.getEntity();
|
||||
int ts = xml.indexOf("<TrustedSigners>");
|
||||
assertTrue(ts >= 0, "DefaultCacheBehavior must echo a TrustedSigners object");
|
||||
String block = xml.substring(ts, xml.indexOf("</TrustedSigners>", ts));
|
||||
assertTrue(block.contains("<Enabled>false</Enabled>"), "TrustedSigners.Enabled=false");
|
||||
assertTrue(block.contains("<Quantity>0</Quantity>"), "TrustedSigners.Quantity=0");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void orderedCacheBehaviorRoundTripsLambdaFunctionAssociations() {
|
||||
CloudFrontService service = mock(CloudFrontService.class);
|
||||
|
||||
Reference in new issue
Block a user