mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iot): domain configurations (#3008)
* feat(iot): add the domain configuration model and service Stores AWS IoT Core domain configurations the way the API reports them: a new configuration is ENABLED and CUSTOMER_MANAGED (ENDPOINT without a domain name), carries one VALID server certificate, the default TLS policy and an ARN with the short id AWS appends. Update changes the status, authorizer, TLS, certificate and protocol settings; delete refuses an ENABLED configuration, as AWS does; list filters by service type and pages with marker and pageSize. Tags work on the ARN. * feat(iot): serve the domain configuration API Adds the REST-JSON routes CreateDomainConfiguration, DescribeDomainConfiguration, UpdateDomainConfiguration, DeleteDomainConfiguration and ListDomainConfigurations under /domainConfigurations, registered with the IoT service so the X-Amzn-Errortype header is set for unsigned callers too. Tags on a configuration ARN go through IotTagHandler; the IoT /untag route now uses the same handler as /tags instead of calling IotService directly. DescribeEndpoint accepts iot:CredentialProvider, the endpoint type that pairs with the CREDENTIAL_PROVIDER service type. * feat(iot): provision AWS::IoT::DomainConfiguration Adds IotDomainConfigurationCfnProvisioner over the domain configuration service. Ref is the configuration name; Fn::GetAtt Arn, DomainType and ServerCertificates resolve to what DescribeDomainConfiguration reports (ServerCertificates as a JSON string, since attributes are strings). Like the CloudFormation handler, a configuration is created ENABLED and a DomainConfigurationStatus of DISABLED is applied with a follow-up update; tags go through TagResource and are reconciled on update; a delete disables the configuration first because the API refuses to delete an ENABLED one. UpdateStack keeps the configuration when the createOnly properties (DomainName, ServiceType, ValidationCertificateArn, ServerCertificateArns) are unchanged and replaces it otherwise, with a fresh generated name when the template names none. Inventory TSV, fixture wiring and the generated resource-type table updated. * docs(iot): describe domain configurations and add the stack integration test IotDomainConfigurationCfnIntegrationTest provisions the type through a stack and asserts Ref and every Fn::GetAtt attribute against DescribeDomainConfiguration, the in-place status update, and that DeleteStack removes the configuration. * test(iot): cover domain configurations in the Java and Go SDK suites Both cases create, describe, list, update and delete a configuration through the real SDK clients and check the AWS error types on the duplicate create, the refused delete of an ENABLED configuration and the describe after deletion. * fix(iot): remove a renamed domain configuration and keep the status when the template omits it A template that changes DomainConfigurationName creates the new configuration and now removes the previous one, as the generated-name replacement already did; before, the old configuration outlived the stack. An update without DomainConfigurationStatus no longer forces ENABLED: the field is omitted and the current status stays, as the AWS handler does. The service rejects a structured JSON value where a string, boolean, list or object is expected instead of turning it into an empty string or silently clearing the authorizer, and validates the whole update before touching the stored record. * fix(iot): let stack rollback remove a domain configuration and make same-name creates atomic A configuration created by a stack is recorded, with the owned marker, before the follow-up status update, so a failure there still lets the create rollback delete it. A replacement that fails after the new configuration exists removes it again, re-enables the previous one if it had been disabled on the way out, and marks the resource restored, as the other provisioners do. CreateDomainConfiguration checks and stores the name in one step, so two overlapping creates of the same name cannot both succeed. A tags value that is not a list is rejected. The Java SDK compatibility case looks for a leftover configuration instead of swallowing every cleanup exception. * fix(iot): point the resource back at the prior domain configuration after a failed replacement After the unwind removes the replacement and re-enables the previous configuration, the resource now carries the previous name and attributes again, without the owned marker, so it describes the configuration that is still there rather than the one just removed. * feat(iot): serve the AWS-managed domain configurations Every AWS account has iot:Data-ATS, iot:Data, iot:CredentialProvider and iot:Jobs without creating them. They now exist in every region on first use: AWS_MANAGED, ENABLED, no server certificate, and the address DescribeEndpoint returns as their domain name. They can be updated and tagged like any other configuration, but not deleted, as on AWS. A client that starts by describing iot:Data-ATS gets an answer instead of a 404. * fix(iot): report a failed replacement cleanup as a rollback failure When the unwind of a failed replacement cannot remove the new domain configuration, the resource now carries the rollback-failure marker with the reason, so the stack ends in UPDATE_ROLLBACK_FAILED instead of reporting a clean rollback while the configuration is still there. The marker moves next to the restored one in CfnRollback so extracted provisioners can set it; the legacy provisioner keeps its alias. * fix(iot): serialise every read-modify-write on a domain configuration Update, delete, tag and untag read a record, change it and write it back. Two overlapping writers lost each other's changes: sixteen tag writers on one configuration left seven keys. All of them now run under the lock the create already used, and a test pins the invariant. A JSON round trip with the mapper setup persistent storage uses pins that the model reloads intact. * fix(iot): keep the prior status the unwind compares against and never delete a same-name replacement The store hands out its live record, so disabling the prior on the way to deleting it changed the very object the unwind later compared against, and a prior whose delete failed half way was left DISABLED while the stack reported a clean rollback. The status seen at the start is now kept and used. The test reproduces the aliasing instead of handing the provisioner a fresh copy per call. A replacement under the same explicit name normally fails on the create; if it goes through because the prior vanished in between, the prior is no longer deleted, which would have removed the configuration just created. * fix(iot): tolerate a domain configuration that vanishes while a stack delete disables it The disable that precedes the delete now treats ResourceNotFoundException as already deleted, the way the delete itself does. The SDK cases also enable an already ENABLED configuration, the call a client makes when it only wants to be sure the configuration is on.
This commit is contained in:
1 parent
f3c251ef20
commit
9220c057b7
21 files changed
+2896
-11
No files matched your search
+11
@@ -37,6 +37,7 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.EcrCfnPro
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.EcsCapacityCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.FirehoseCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.IamRoleCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.IotDomainConfigurationCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.KinesisCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.KmsCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaAddressingCfnProvisioner;
|
||||
@@ -64,6 +65,7 @@ import io.github.hectorvent.floci.services.elbv2.ElbV2Service;
|
||||
import io.github.hectorvent.floci.services.eventbridge.EventBridgeService;
|
||||
import io.github.hectorvent.floci.services.firehose.FirehoseService;
|
||||
import io.github.hectorvent.floci.services.iam.IamService;
|
||||
import io.github.hectorvent.floci.services.iot.IotDomainConfigurationService;
|
||||
import io.github.hectorvent.floci.services.kinesis.KinesisService;
|
||||
import io.github.hectorvent.floci.services.kms.KmsService;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaLayerService;
|
||||
@@ -145,6 +147,7 @@ final class CfnProvisionerFixture {
|
||||
// Services that back a provisioner without being a constructor argument of the
|
||||
// dispatcher. They exist only so inferredProvisioners() can wire their provisioner.
|
||||
private FlowLogService flowLogService;
|
||||
private IotDomainConfigurationService iotDomainConfigurationService;
|
||||
private LambdaMicrovmsService lambdaMicrovmsService;
|
||||
private AwsConfigService awsConfigService;
|
||||
private OrganizationsService organizationsService;
|
||||
@@ -244,6 +247,9 @@ final class CfnProvisionerFixture {
|
||||
if (flowLogService != null) {
|
||||
discovered.add(new Ec2FlowLogCfnProvisioner(flowLogService));
|
||||
}
|
||||
if (iotDomainConfigurationService != null) {
|
||||
discovered.add(new IotDomainConfigurationCfnProvisioner(iotDomainConfigurationService));
|
||||
}
|
||||
if (lambdaMicrovmsService != null) {
|
||||
discovered.add(new LambdaMicrovmsCfnProvisioner(lambdaMicrovmsService));
|
||||
}
|
||||
@@ -456,6 +462,11 @@ final class CfnProvisionerFixture {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder iotDomainConfiguration(IotDomainConfigurationService v) {
|
||||
this.iotDomainConfigurationService = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lambdaMicrovms(LambdaMicrovmsService v) {
|
||||
this.lambdaMicrovmsService = v;
|
||||
return this;
|
||||
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.XmlParser;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Provisions an {@code AWS::IoT::DomainConfiguration} through a CloudFormation stack and asserts
|
||||
* that {@code Ref} and every {@code Fn::GetAtt} attribute carry what {@code DescribeDomainConfiguration}
|
||||
* reports, rather than the literal {@code Domain.Arn} the stub arm would leave behind. Also
|
||||
* covers the in-place status update and that deleting the stack removes the configuration.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class IotDomainConfigurationCfnIntegrationTest {
|
||||
|
||||
private static final String CFN_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260903/us-east-1/cloudformation/aws4_request";
|
||||
private static final String STACK = "iot-domain-cfn-it";
|
||||
private static final String NAME = "iot-cfn-it-domain";
|
||||
private static final String CERTIFICATE_ARN =
|
||||
"arn:aws:acm:us-east-1:000000000000:certificate/11111111-1111-1111-1111-111111111111";
|
||||
|
||||
private static String template(String status) {
|
||||
return """
|
||||
{
|
||||
"Resources": {
|
||||
"Domain": {
|
||||
"Type": "AWS::IoT::DomainConfiguration",
|
||||
"Properties": {
|
||||
"DomainConfigurationName": "%s",
|
||||
"DomainName": "iot.cfn-it.example.com",
|
||||
"ServiceType": "DATA",
|
||||
"ServerCertificateArns": ["%s"],
|
||||
"AuthorizerConfig": {"DefaultAuthorizerName": "cfn-it-authorizer", "AllowAuthorizerOverride": true},
|
||||
"DomainConfigurationStatus": "%s",
|
||||
"Tags": [{"Key": "stack", "Value": "iot-domain-cfn-it"}]
|
||||
}
|
||||
}
|
||||
},
|
||||
"Outputs": {
|
||||
"DomainRef": {"Value": {"Ref": "Domain"}},
|
||||
"DomainArn": {"Value": {"Fn::GetAtt": ["Domain", "Arn"]}},
|
||||
"DomainType": {"Value": {"Fn::GetAtt": ["Domain", "DomainType"]}},
|
||||
"ServerCertificates": {"Value": {"Fn::GetAtt": ["Domain", "ServerCertificates"]}}
|
||||
}
|
||||
}
|
||||
""".formatted(NAME, CERTIFICATE_ARN, status);
|
||||
}
|
||||
|
||||
@Test
|
||||
void domainConfigurationStackExposesRealAttributesUpdatesInPlaceAndDeletesTheConfiguration() throws Exception {
|
||||
cloudFormation("CreateStack", template("ENABLED"));
|
||||
|
||||
String stacks = describeStacks("CREATE_COMPLETE");
|
||||
String arn = outputValue(stacks, "DomainArn");
|
||||
assertEquals(NAME, outputValue(stacks, "DomainRef"));
|
||||
assertTrue(arn.startsWith("arn:aws:iot:us-east-1:000000000000:domainconfiguration/" + NAME + "/"),
|
||||
"Fn::GetAtt Arn must be the configuration ARN: " + arn);
|
||||
assertEquals("CUSTOMER_MANAGED", outputValue(stacks, "DomainType"));
|
||||
JsonNode certificates = new ObjectMapper().readTree(outputValue(stacks, "ServerCertificates"));
|
||||
assertEquals(CERTIFICATE_ARN, certificates.get(0).path("ServerCertificateArn").asText());
|
||||
assertEquals("VALID", certificates.get(0).path("ServerCertificateStatus").asText());
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurationArn", equalTo(arn))
|
||||
.body("domainConfigurationStatus", equalTo("ENABLED"))
|
||||
.body("domainName", equalTo("iot.cfn-it.example.com"))
|
||||
.body("domainType", equalTo("CUSTOMER_MANAGED"))
|
||||
.body("authorizerConfig.defaultAuthorizerName", equalTo("cfn-it-authorizer"))
|
||||
.body("authorizerConfig.allowAuthorizerOverride", equalTo(true));
|
||||
given()
|
||||
.queryParam("resourceArn", arn)
|
||||
.when()
|
||||
.get("/tags")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.Key", hasItem("stack"));
|
||||
|
||||
cloudFormation("UpdateStack", template("DISABLED"));
|
||||
|
||||
describeStacks("UPDATE_COMPLETE");
|
||||
given()
|
||||
.when()
|
||||
.get("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurationArn", equalTo(arn))
|
||||
.body("domainConfigurationStatus", equalTo("DISABLED"));
|
||||
|
||||
cloudFormation("DeleteStack", null);
|
||||
awaitStackDeleted();
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
private static void cloudFormation(String action, String templateBody) {
|
||||
RequestSpecification request = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", action)
|
||||
.formParam("StackName", STACK);
|
||||
if (templateBody != null) {
|
||||
request.formParam("TemplateBody", templateBody);
|
||||
}
|
||||
request.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
private static String describeStacks(String expectedStatus) {
|
||||
return given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", STACK)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<StackStatus>" + expectedStatus + "</StackStatus>"))
|
||||
.extract().asString();
|
||||
}
|
||||
|
||||
/** DeleteStack runs asynchronously; a successful delete removes the stack entirely. */
|
||||
private static void awaitStackDeleted() throws InterruptedException {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String body = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", STACK)
|
||||
.when().post("/").then().extract().asString();
|
||||
if (body.contains("does not exist")) {
|
||||
return;
|
||||
}
|
||||
if (body.contains("<StackStatus>DELETE_FAILED</StackStatus>")) {
|
||||
fail("stack delete failed: " + body);
|
||||
}
|
||||
Thread.sleep(50);
|
||||
}
|
||||
fail("stack " + STACK + " was not deleted within the timeout");
|
||||
}
|
||||
|
||||
private static String outputValue(String xml, String key) {
|
||||
return XmlParser.extractPairs(xml, "Outputs", "OutputKey", "OutputValue").get(key);
|
||||
}
|
||||
}
|
||||
+554
@@ -0,0 +1,554 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation.provisioners;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
|
||||
import io.github.hectorvent.floci.services.iot.IotDomainConfigurationService;
|
||||
import io.github.hectorvent.floci.services.iot.model.IotDomainConfiguration;
|
||||
import io.github.hectorvent.floci.services.iot.model.IotDomainConfiguration.AuthorizerConfig;
|
||||
import io.github.hectorvent.floci.services.iot.model.IotDomainConfiguration.ServerCertificateSummary;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* The IoT domain configuration CFN provisioner in isolation: one mocked service. Every case
|
||||
* asserts the exact physical id and the exact {@code Fn::GetAtt} attribute keys, because an
|
||||
* unmapped type still reports CREATE_COMPLETE through the dispatcher's stub arm.
|
||||
*/
|
||||
class IotDomainConfigurationCfnProvisionerTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String TYPE = "AWS::IoT::DomainConfiguration";
|
||||
private static final String NAME = "iot-domain";
|
||||
private static final String CERTIFICATE_ARN =
|
||||
"arn:aws:acm:us-east-1:000000000000:certificate/11111111-1111-1111-1111-111111111111";
|
||||
private static final String ARN = "arn:aws:iot:us-east-1:000000000000:domainconfiguration/iot-domain/abcde";
|
||||
private static final String SERVER_CERTIFICATES_JSON =
|
||||
"[{\"ServerCertificateArn\":\"" + CERTIFICATE_ARN + "\",\"ServerCertificateStatus\":\"VALID\"}]";
|
||||
|
||||
private final IotDomainConfigurationService service = mock(IotDomainConfigurationService.class);
|
||||
private final IotDomainConfigurationCfnProvisioner provisioner = new IotDomainConfigurationCfnProvisioner(service);
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private ProvisionContext ctx() {
|
||||
return ctx(null);
|
||||
}
|
||||
|
||||
private ProvisionContext ctx(String priorPhysicalId) {
|
||||
CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
|
||||
when(engine.resolve(any())).thenAnswer(inv -> {
|
||||
JsonNode node = inv.getArgument(0);
|
||||
return node == null || node.isMissingNode() || node.isNull() ? null : node.asText();
|
||||
});
|
||||
when(engine.resolveNode(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
return new ProvisionContext(engine, REGION, "000000000000", "my-stack", priorPhysicalId);
|
||||
}
|
||||
|
||||
private static StackResource resource() {
|
||||
StackResource r = new StackResource();
|
||||
r.setLogicalId("Domain");
|
||||
r.setResourceType(TYPE);
|
||||
r.setAttributes(new HashMap<>());
|
||||
return r;
|
||||
}
|
||||
|
||||
private ObjectNode customDomainProps(String name) {
|
||||
ObjectNode props = mapper.createObjectNode().put("DomainName", "iot.example.com");
|
||||
if (name != null) {
|
||||
props.put("DomainConfigurationName", name);
|
||||
}
|
||||
props.putArray("ServerCertificateArns").add(CERTIFICATE_ARN);
|
||||
return props;
|
||||
}
|
||||
|
||||
private static IotDomainConfiguration stored(String name, String arn, String domainName, String status) {
|
||||
IotDomainConfiguration configuration = new IotDomainConfiguration();
|
||||
configuration.setDomainConfigurationName(name);
|
||||
configuration.setDomainConfigurationArn(arn);
|
||||
configuration.setDomainName(domainName);
|
||||
configuration.setServiceType("DATA");
|
||||
configuration.setDomainConfigurationStatus(status);
|
||||
configuration.setDomainType(domainName == null ? "ENDPOINT" : "CUSTOMER_MANAGED");
|
||||
configuration.setServerCertificates(domainName == null
|
||||
? List.of()
|
||||
: List.of(new ServerCertificateSummary(CERTIFICATE_ARN, "VALID", null)));
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private JsonNode capturedCreateBody(String name) {
|
||||
ArgumentCaptor<JsonNode> captor = ArgumentCaptor.forClass(JsonNode.class);
|
||||
verify(service).createDomainConfiguration(eq(name), captor.capture(), eq(REGION));
|
||||
return captor.getValue();
|
||||
}
|
||||
|
||||
private JsonNode capturedUpdateBody(String name) {
|
||||
ArgumentCaptor<JsonNode> captor = ArgumentCaptor.forClass(JsonNode.class);
|
||||
verify(service).updateDomainConfiguration(eq(name), captor.capture(), eq(REGION));
|
||||
return captor.getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createSetsTheNameAsPhysicalIdAndTheThreeSchemaAttributes() {
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
StackResource r = resource();
|
||||
|
||||
provisioner.provision(r, customDomainProps(NAME), ctx());
|
||||
|
||||
assertEquals(NAME, r.getPhysicalId());
|
||||
assertEquals(Map.of("Arn", ARN, "DomainType", "CUSTOMER_MANAGED", "ServerCertificates", SERVER_CERTIFICATES_JSON),
|
||||
r.getAttributes());
|
||||
verify(service, never()).updateDomainConfiguration(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createPassesTemplatePropertiesToTheServiceInApiShape() {
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
ObjectNode props = customDomainProps(NAME)
|
||||
.put("ServiceType", "JOBS")
|
||||
.put("ValidationCertificateArn", CERTIFICATE_ARN)
|
||||
.put("AuthenticationType", "CUSTOM_AUTH")
|
||||
.put("ApplicationProtocol", "MQTT_WSS");
|
||||
props.putObject("AuthorizerConfig").put("DefaultAuthorizerName", "my-authorizer").put("AllowAuthorizerOverride", true);
|
||||
props.putObject("TlsConfig").put("SecurityPolicy", "IoTSecurityPolicy_TLS12_1_2_2022_10");
|
||||
props.putObject("ServerCertificateConfig").put("EnableOCSPCheck", true)
|
||||
.put("OcspLambdaArn", "arn:aws:lambda:us-east-1:000000000000:function:ocsp");
|
||||
props.putObject("ClientCertificateConfig")
|
||||
.put("ClientCertificateCallbackArn", "arn:aws:lambda:us-east-1:000000000000:function:callback");
|
||||
props.putArray("Tags").addObject().put("Key", "env").put("Value", "test");
|
||||
|
||||
provisioner.provision(resource(), props, ctx());
|
||||
|
||||
JsonNode body = capturedCreateBody(NAME);
|
||||
assertEquals("iot.example.com", body.path("domainName").asText());
|
||||
assertEquals("JOBS", body.path("serviceType").asText());
|
||||
assertEquals(CERTIFICATE_ARN, body.path("serverCertificateArns").get(0).asText());
|
||||
assertEquals(CERTIFICATE_ARN, body.path("validationCertificateArn").asText());
|
||||
assertEquals("my-authorizer", body.path("authorizerConfig").path("defaultAuthorizerName").asText());
|
||||
assertTrue(body.path("authorizerConfig").path("allowAuthorizerOverride").isBoolean());
|
||||
assertTrue(body.path("authorizerConfig").path("allowAuthorizerOverride").asBoolean());
|
||||
assertEquals("IoTSecurityPolicy_TLS12_1_2_2022_10", body.path("tlsConfig").path("securityPolicy").asText());
|
||||
assertTrue(body.path("serverCertificateConfig").path("enableOCSPCheck").asBoolean());
|
||||
assertEquals("arn:aws:lambda:us-east-1:000000000000:function:ocsp",
|
||||
body.path("serverCertificateConfig").path("ocspLambdaArn").asText());
|
||||
assertEquals("CUSTOM_AUTH", body.path("authenticationType").asText());
|
||||
assertEquals("MQTT_WSS", body.path("applicationProtocol").asText());
|
||||
assertEquals("arn:aws:lambda:us-east-1:000000000000:function:callback",
|
||||
body.path("clientCertificateConfig").path("clientCertificateCallbackArn").asText());
|
||||
assertEquals("env", body.path("tags").get(0).path("Key").asText());
|
||||
assertEquals("test", body.path("tags").get(0).path("Value").asText());
|
||||
assertFalse(body.has("domainConfigurationName"));
|
||||
assertFalse(body.has("domainConfigurationStatus"));
|
||||
assertFalse(body.has("Tags"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointConfigurationWithoutADomainNameReportsItsTypeAndAnEmptyCertificateList() {
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, null, "ENABLED"));
|
||||
StackResource r = resource();
|
||||
|
||||
provisioner.provision(r, mapper.createObjectNode().put("DomainConfigurationName", NAME), ctx());
|
||||
|
||||
assertEquals(Map.of("Arn", ARN, "DomainType", "ENDPOINT", "ServerCertificates", "[]"), r.getAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void disabledStatusIsAppliedWithAFollowUpUpdateLikeTheCloudFormationHandler() {
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
when(service.updateDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "DISABLED"));
|
||||
StackResource r = resource();
|
||||
|
||||
provisioner.provision(r, customDomainProps(NAME).put("DomainConfigurationStatus", "DISABLED"), ctx());
|
||||
|
||||
InOrder order = inOrder(service);
|
||||
order.verify(service).createDomainConfiguration(eq(NAME), any(), eq(REGION));
|
||||
order.verify(service).updateDomainConfiguration(eq(NAME), any(), eq(REGION));
|
||||
JsonNode update = capturedUpdateBody(NAME);
|
||||
assertEquals("DISABLED", update.path("domainConfigurationStatus").asText());
|
||||
assertEquals(1, update.size());
|
||||
assertEquals(NAME, r.getPhysicalId());
|
||||
assertEquals(ARN, r.getAttributes().get("Arn"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void enabledStatusNeedsNoFollowUpUpdate() {
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
|
||||
provisioner.provision(resource(), customDomainProps(NAME).put("DomainConfigurationStatus", "ENABLED"), ctx());
|
||||
|
||||
verify(service, never()).updateDomainConfiguration(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void nameIsGeneratedWhenTheTemplateGivesNone() {
|
||||
when(service.createDomainConfiguration(anyString(), any(), eq(REGION)))
|
||||
.thenAnswer(inv -> stored(inv.getArgument(0), ARN, "iot.example.com", "ENABLED"));
|
||||
StackResource r = resource();
|
||||
|
||||
provisioner.provision(r, customDomainProps(null), ctx());
|
||||
|
||||
assertTrue(r.getPhysicalId().matches("my-stack-Domain-[0-9a-f]{12}"), r.getPhysicalId());
|
||||
verify(service).createDomainConfiguration(eq(r.getPhysicalId()), any(), eq(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWithUnchangedCreateOnlyPropertiesUpdatesInPlaceAndReconcilesTags() {
|
||||
IotDomainConfiguration existing = stored(NAME, ARN, "iot.example.com", "ENABLED");
|
||||
existing.setAuthorizerConfig(new AuthorizerConfig("old-authorizer", true));
|
||||
existing.setTags(Map.of("stale", "x", "env", "old"));
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(existing);
|
||||
when(service.updateDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "DISABLED"));
|
||||
ObjectNode props = customDomainProps(NAME).put("DomainConfigurationStatus", "DISABLED");
|
||||
props.putObject("TlsConfig").put("SecurityPolicy", "IoTSecurityPolicy_TLS12_1_2_2022_10");
|
||||
props.putArray("Tags").addObject().put("Key", "env").put("Value", "test");
|
||||
StackResource r = resource();
|
||||
|
||||
provisioner.provision(r, props, ctx(NAME));
|
||||
|
||||
verify(service, never()).createDomainConfiguration(any(), any(), any());
|
||||
verify(service, never()).deleteDomainConfiguration(any(), any());
|
||||
JsonNode update = capturedUpdateBody(NAME);
|
||||
assertEquals("DISABLED", update.path("domainConfigurationStatus").asText());
|
||||
assertEquals("IoTSecurityPolicy_TLS12_1_2_2022_10", update.path("tlsConfig").path("securityPolicy").asText());
|
||||
assertTrue(update.path("removeAuthorizerConfig").asBoolean(),
|
||||
"the template dropped AuthorizerConfig, so the update must remove it");
|
||||
assertFalse(update.has("authorizerConfig"));
|
||||
assertFalse(update.has("domainName"));
|
||||
assertFalse(update.has("serverCertificateArns"));
|
||||
verify(service).untagResource(ARN, List.of("stale"));
|
||||
verify(service).tagResource(ARN, Map.of("env", "test"));
|
||||
assertEquals(NAME, r.getPhysicalId());
|
||||
assertEquals(Map.of("Arn", ARN, "DomainType", "CUSTOMER_MANAGED", "ServerCertificates", SERVER_CERTIFICATES_JSON),
|
||||
r.getAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateKeepingTheAuthorizerSendsItWithoutTheRemoveFlag() {
|
||||
IotDomainConfiguration existing = stored(NAME, ARN, "iot.example.com", "ENABLED");
|
||||
existing.setAuthorizerConfig(new AuthorizerConfig("old-authorizer", true));
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(existing);
|
||||
when(service.updateDomainConfiguration(eq(NAME), any(), eq(REGION))).thenReturn(existing);
|
||||
ObjectNode props = customDomainProps(NAME);
|
||||
props.putObject("AuthorizerConfig").put("DefaultAuthorizerName", "new-authorizer");
|
||||
|
||||
provisioner.provision(resource(), props, ctx(NAME));
|
||||
|
||||
JsonNode update = capturedUpdateBody(NAME);
|
||||
assertEquals("new-authorizer", update.path("authorizerConfig").path("defaultAuthorizerName").asText());
|
||||
assertFalse(update.has("removeAuthorizerConfig"));
|
||||
// No DomainConfigurationStatus in the template leaves the status alone, as the AWS handler does.
|
||||
assertFalse(update.has("domainConfigurationStatus"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWithoutANameKeepsTheGeneratedNameAndUpdatesInPlace() {
|
||||
String generated = "my-stack-Domain-aaaaaaaaaaaa";
|
||||
when(service.describeDomainConfiguration(generated, REGION))
|
||||
.thenReturn(stored(generated, ARN, "iot.example.com", "ENABLED"));
|
||||
when(service.updateDomainConfiguration(eq(generated), any(), eq(REGION)))
|
||||
.thenReturn(stored(generated, ARN, "iot.example.com", "ENABLED"));
|
||||
StackResource r = resource();
|
||||
|
||||
provisioner.provision(r, customDomainProps(null), ctx(generated));
|
||||
|
||||
verify(service, never()).createDomainConfiguration(any(), any(), any());
|
||||
verify(service, never()).deleteDomainConfiguration(any(), any());
|
||||
verify(service).updateDomainConfiguration(eq(generated), any(), eq(REGION));
|
||||
assertEquals(generated, r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateRenamingTheConfigurationCreatesTheNewOneAndRemovesTheOld() {
|
||||
// DomainConfigurationName is createOnly: a new name is a replacement, and the previous
|
||||
// configuration must not outlive the stack that created it.
|
||||
String oldArn = "arn:aws:iot:us-east-1:000000000000:domainconfiguration/old-name/aaaaa";
|
||||
when(service.describeDomainConfiguration("old-name", REGION))
|
||||
.thenReturn(stored("old-name", oldArn, "iot.example.com", "ENABLED"));
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
StackResource r = resource();
|
||||
|
||||
provisioner.provision(r, customDomainProps(NAME), ctx("old-name"));
|
||||
|
||||
InOrder order = inOrder(service);
|
||||
order.verify(service).createDomainConfiguration(eq(NAME), any(), eq(REGION));
|
||||
order.verify(service).updateDomainConfiguration(eq("old-name"),
|
||||
argThat(body -> "DISABLED".equals(body.path("domainConfigurationStatus").asText())), eq(REGION));
|
||||
order.verify(service).deleteDomainConfiguration("old-name", REGION);
|
||||
assertEquals(NAME, r.getPhysicalId());
|
||||
assertEquals(ARN, r.getAttributes().get("Arn"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateChangingACreateOnlyPropertyUnderAnExplicitNameFailsOnTheCreateAsOnAws() {
|
||||
// DomainName is createOnly. CloudFormation creates the replacement before deleting the
|
||||
// original, and the explicit name is already taken, so the update fails like it does on AWS.
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(stored(NAME, ARN, "old.example.com", "ENABLED"));
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenThrow(new AwsException("ResourceAlreadyExistsException", "exists", 409));
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class,
|
||||
() -> provisioner.provision(resource(), customDomainProps(NAME), ctx(NAME)));
|
||||
|
||||
assertEquals("ResourceAlreadyExistsException", failure.getErrorCode());
|
||||
verify(service, never()).updateDomainConfiguration(any(), any(), any());
|
||||
verify(service, never()).deleteDomainConfiguration(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateChangingACreateOnlyPropertyUnderAGeneratedNameReplacesTheConfiguration() {
|
||||
String priorName = "my-stack-Domain-aaaaaaaaaaaa";
|
||||
String priorArn = "arn:aws:iot:us-east-1:000000000000:domainconfiguration/" + priorName + "/aaaaa";
|
||||
when(service.describeDomainConfiguration(priorName, REGION)).thenReturn(stored(priorName, priorArn, "old.example.com", "ENABLED"));
|
||||
when(service.createDomainConfiguration(anyString(), any(), eq(REGION)))
|
||||
.thenAnswer(inv -> stored(inv.getArgument(0), ARN, "iot.example.com", "ENABLED"));
|
||||
StackResource r = resource();
|
||||
|
||||
provisioner.provision(r, customDomainProps(null), ctx(priorName));
|
||||
|
||||
assertNotEquals(priorName, r.getPhysicalId());
|
||||
assertTrue(r.getPhysicalId().matches("my-stack-Domain-[0-9a-f]{12}"), r.getPhysicalId());
|
||||
verify(service).createDomainConfiguration(eq(r.getPhysicalId()), any(), eq(REGION));
|
||||
InOrder order = inOrder(service);
|
||||
order.verify(service).updateDomainConfiguration(eq(priorName),
|
||||
argThat(body -> "DISABLED".equals(body.path("domainConfigurationStatus").asText())), eq(REGION));
|
||||
order.verify(service).deleteDomainConfiguration(priorName, REGION);
|
||||
assertEquals(ARN, r.getAttributes().get("Arn"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWhoseFollowUpDisableFailsLeavesAnOwnedResourceForTheRollback() {
|
||||
// The create rollback deletes only resources that have a physical id and carry the owned
|
||||
// marker, so both must be in place before the follow-up status update can fail.
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
when(service.updateDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenThrow(new AwsException("InternalFailureException", "boom", 500));
|
||||
StackResource r = resource();
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () -> provisioner.provision(
|
||||
r, customDomainProps(NAME).put("DomainConfigurationStatus", "DISABLED"), ctx()));
|
||||
|
||||
assertEquals("InternalFailureException", failure.getErrorCode());
|
||||
assertEquals(NAME, r.getPhysicalId());
|
||||
assertEquals(ARN, r.getAttributes().get("Arn"));
|
||||
assertEquals("true", r.getAttributes().get(CfnRollback.ROLLBACK_OWNED_ATTR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacementWhoseFollowUpDisableFailsRemovesTheNewConfigurationAndKeepsThePrior() {
|
||||
// CloudFormationService restores the previous StackResource on a failed update and never
|
||||
// learns the new name, so the configuration created here must not be left behind.
|
||||
String oldArn = "arn:aws:iot:us-east-1:000000000000:domainconfiguration/old-name/aaaaa";
|
||||
when(service.describeDomainConfiguration("old-name", REGION))
|
||||
.thenReturn(stored("old-name", oldArn, "iot.example.com", "ENABLED"));
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
when(service.updateDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenThrow(new AwsException("InternalFailureException", "boom", 500))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "DISABLED"));
|
||||
StackResource r = resource();
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () -> provisioner.provision(
|
||||
r, customDomainProps(NAME).put("DomainConfigurationStatus", "DISABLED"), ctx("old-name")));
|
||||
|
||||
assertEquals("InternalFailureException", failure.getErrorCode());
|
||||
verify(service).deleteDomainConfiguration(NAME, REGION);
|
||||
verify(service, never()).deleteDomainConfiguration("old-name", REGION);
|
||||
verify(service, never()).updateDomainConfiguration(eq("old-name"), any(), eq(REGION));
|
||||
assertEquals("true", r.getAttributes().get(CfnRollback.UPDATE_ROLLBACK_RESTORED_ATTR));
|
||||
// The resource describes the configuration that is still there, not the removed one.
|
||||
assertEquals("old-name", r.getPhysicalId());
|
||||
assertEquals(oldArn, r.getAttributes().get("Arn"));
|
||||
assertNull(r.getAttributes().get(CfnRollback.ROLLBACK_OWNED_ATTR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacementWhosePriorCannotBeDeletedRemovesTheNewConfigurationAndReEnablesThePrior() {
|
||||
String oldArn = "arn:aws:iot:us-east-1:000000000000:domainconfiguration/old-name/aaaaa";
|
||||
// The store hands out its live object, so the disable that precedes the delete changes the
|
||||
// very instance the provisioner captured as the prior. The status it saw at the start is
|
||||
// what the unwind must go back to.
|
||||
IotDomainConfiguration old = stored("old-name", oldArn, "iot.example.com", "ENABLED");
|
||||
when(service.describeDomainConfiguration("old-name", REGION)).thenReturn(old);
|
||||
when(service.updateDomainConfiguration(eq("old-name"), any(), eq(REGION))).thenAnswer(inv -> {
|
||||
JsonNode body = inv.getArgument(1);
|
||||
old.setDomainConfigurationStatus(body.path("domainConfigurationStatus").asText());
|
||||
return old;
|
||||
});
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
doThrow(new AwsException("InternalFailureException", "boom", 500))
|
||||
.when(service).deleteDomainConfiguration("old-name", REGION);
|
||||
StackResource r = resource();
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class,
|
||||
() -> provisioner.provision(r, customDomainProps(NAME), ctx("old-name")));
|
||||
|
||||
assertEquals("InternalFailureException", failure.getErrorCode());
|
||||
InOrder order = inOrder(service);
|
||||
order.verify(service).updateDomainConfiguration(eq(NAME),
|
||||
argThat(body -> "DISABLED".equals(body.path("domainConfigurationStatus").asText())), eq(REGION));
|
||||
order.verify(service).deleteDomainConfiguration(NAME, REGION);
|
||||
order.verify(service).updateDomainConfiguration(eq("old-name"),
|
||||
argThat(body -> "ENABLED".equals(body.path("domainConfigurationStatus").asText())), eq(REGION));
|
||||
assertEquals("ENABLED", old.getDomainConfigurationStatus());
|
||||
assertEquals("true", r.getAttributes().get(CfnRollback.UPDATE_ROLLBACK_RESTORED_ATTR));
|
||||
assertEquals("old-name", r.getPhysicalId());
|
||||
assertEquals(oldArn, r.getAttributes().get("Arn"));
|
||||
assertNull(r.getAttributes().get(CfnRollback.ROLLBACK_OWNED_ATTR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacementWhoseCleanupAlsoFailsReportsTheRollbackFailureInsteadOfClaimingARestore() {
|
||||
// If the new configuration cannot be removed, the engine must not report a clean rollback:
|
||||
// the failure marker makes it end in UPDATE_ROLLBACK_FAILED with the reason.
|
||||
String oldArn = "arn:aws:iot:us-east-1:000000000000:domainconfiguration/old-name/aaaaa";
|
||||
when(service.describeDomainConfiguration("old-name", REGION))
|
||||
.thenReturn(stored("old-name", oldArn, "iot.example.com", "ENABLED"));
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
// A fresh exception per call, as a real service raises: the follow-up disable fails, and so
|
||||
// does the disable the cleanup attempts.
|
||||
when(service.updateDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenAnswer(inv -> {
|
||||
throw new AwsException("InternalFailureException", "boom", 500);
|
||||
});
|
||||
StackResource r = resource();
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () -> provisioner.provision(
|
||||
r, customDomainProps(NAME).put("DomainConfigurationStatus", "DISABLED"), ctx("old-name")));
|
||||
|
||||
assertEquals("InternalFailureException", failure.getErrorCode());
|
||||
assertEquals(1, failure.getSuppressed().length);
|
||||
String reason = r.getAttributes().get(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR);
|
||||
assertNotNull(reason);
|
||||
assertTrue(reason.contains(NAME), reason);
|
||||
assertNull(r.getAttributes().get(CfnRollback.UPDATE_ROLLBACK_RESTORED_ATTR));
|
||||
verify(service, never()).deleteDomainConfiguration(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitNameReplacementWhoseCreateUnexpectedlySucceedsKeepsTheNewConfiguration() {
|
||||
// Under an explicit name the create normally fails with ResourceAlreadyExistsException. If
|
||||
// the prior vanished in between and the create went through, the configuration just
|
||||
// created must not be removed as if it were the prior.
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(stored(NAME, ARN, "old.example.com", "ENABLED"));
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
StackResource r = resource();
|
||||
|
||||
provisioner.provision(r, customDomainProps(NAME), ctx(NAME));
|
||||
|
||||
verify(service, never()).deleteDomainConfiguration(any(), any());
|
||||
verify(service, never()).updateDomainConfiguration(any(), any(), any());
|
||||
assertEquals(NAME, r.getPhysicalId());
|
||||
assertEquals(Map.of("Arn", ARN, "DomainType", "CUSTOMER_MANAGED", "ServerCertificates", SERVER_CERTIFICATES_JSON),
|
||||
r.getAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWhosePriorConfigurationIsGoneCreatesAFreshOne() {
|
||||
when(service.describeDomainConfiguration(NAME, REGION))
|
||||
.thenThrow(new AwsException("ResourceNotFoundException", "gone", 404));
|
||||
when(service.createDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
StackResource r = resource();
|
||||
|
||||
provisioner.provision(r, customDomainProps(NAME), ctx(NAME));
|
||||
|
||||
verify(service, never()).deleteDomainConfiguration(any(), any());
|
||||
verify(service, never()).updateDomainConfiguration(any(), any(), any());
|
||||
assertEquals(NAME, r.getPhysicalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteDisablesAnEnabledConfigurationBeforeDeletingIt() {
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
|
||||
provisioner.delete(TYPE, NAME, REGION);
|
||||
|
||||
InOrder order = inOrder(service);
|
||||
order.verify(service).updateDomainConfiguration(eq(NAME),
|
||||
argThat(body -> "DISABLED".equals(body.path("domainConfigurationStatus").asText())), eq(REGION));
|
||||
order.verify(service).deleteDomainConfiguration(NAME, REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOfADisabledConfigurationSkipsTheStatusUpdate() {
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(stored(NAME, ARN, "iot.example.com", "DISABLED"));
|
||||
|
||||
provisioner.delete(TYPE, NAME, REGION);
|
||||
|
||||
verify(service, never()).updateDomainConfiguration(any(), any(), any());
|
||||
verify(service).deleteDomainConfiguration(NAME, REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteToleratesAnAlreadyDeletedConfiguration() {
|
||||
when(service.describeDomainConfiguration(NAME, REGION))
|
||||
.thenThrow(new AwsException("ResourceNotFoundException", "gone", 404));
|
||||
|
||||
assertDoesNotThrow(() -> provisioner.delete(TYPE, NAME, REGION));
|
||||
|
||||
verify(service, never()).deleteDomainConfiguration(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteToleratesAConfigurationThatVanishesWhileBeingDisabled() {
|
||||
// Seen ENABLED, then gone by the time the disable runs: already deleted is the outcome the
|
||||
// stack wants, on the disable as much as on the delete itself.
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(stored(NAME, ARN, "iot.example.com", "ENABLED"));
|
||||
when(service.updateDomainConfiguration(eq(NAME), any(), eq(REGION)))
|
||||
.thenThrow(new AwsException("ResourceNotFoundException", "gone", 404));
|
||||
doThrow(new AwsException("ResourceNotFoundException", "gone", 404))
|
||||
.when(service).deleteDomainConfiguration(NAME, REGION);
|
||||
|
||||
assertDoesNotThrow(() -> provisioner.delete(TYPE, NAME, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePropagatesAFailureThatIsNotAlreadyGone() {
|
||||
when(service.describeDomainConfiguration(NAME, REGION)).thenReturn(stored(NAME, ARN, "iot.example.com", "DISABLED"));
|
||||
doThrow(new AwsException("InvalidRequestException", "refused", 400))
|
||||
.when(service).deleteDomainConfiguration(NAME, REGION);
|
||||
|
||||
assertThrows(AwsException.class, () -> provisioner.delete(TYPE, NAME, REGION));
|
||||
}
|
||||
}
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
package io.github.hectorvent.floci.services.iot;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* Drives the domain configuration routes the way the AWS SDKs do (REST-JSON under
|
||||
* {@code /domainConfigurations}) and checks the wire shapes and error codes AWS IoT returns.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class IotDomainConfigurationIntegrationTest {
|
||||
|
||||
private static final String NAME = "it-domain";
|
||||
private static final String CERTIFICATE_ARN =
|
||||
"arn:aws:acm:us-east-1:000000000000:certificate/11111111-1111-1111-1111-111111111111";
|
||||
|
||||
private static String createBody(String domainName, String serviceType) {
|
||||
return """
|
||||
{
|
||||
"domainName": "%s",
|
||||
"serverCertificateArns": ["%s"],
|
||||
"serviceType": "%s"
|
||||
}
|
||||
""".formatted(domainName, CERTIFICATE_ARN, serviceType);
|
||||
}
|
||||
|
||||
@Test
|
||||
void domainConfigurationLifecycleMatchesAws() {
|
||||
String arn = given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"domainName": "iot.it.example.com",
|
||||
"serverCertificateArns": ["%s"],
|
||||
"authorizerConfig": {"defaultAuthorizerName": "it-authorizer", "allowAuthorizerOverride": true},
|
||||
"tags": [{"Key": "env", "Value": "it"}]
|
||||
}
|
||||
""".formatted(CERTIFICATE_ARN))
|
||||
.when()
|
||||
.post("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurationName", equalTo(NAME))
|
||||
.body("domainConfigurationArn",
|
||||
startsWith("arn:aws:iot:us-east-1:000000000000:domainconfiguration/" + NAME + "/"))
|
||||
.extract().path("domainConfigurationArn");
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(createBody("iot.it.example.com", "DATA"))
|
||||
.when()
|
||||
.post("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(409)
|
||||
.body("__type", equalTo("ResourceAlreadyExistsException"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurationName", equalTo(NAME))
|
||||
.body("domainConfigurationArn", equalTo(arn))
|
||||
.body("domainName", equalTo("iot.it.example.com"))
|
||||
.body("domainConfigurationStatus", equalTo("ENABLED"))
|
||||
.body("serviceType", equalTo("DATA"))
|
||||
.body("domainType", equalTo("CUSTOMER_MANAGED"))
|
||||
.body("serverCertificates[0].serverCertificateArn", equalTo(CERTIFICATE_ARN))
|
||||
.body("serverCertificates[0].serverCertificateStatus", equalTo("VALID"))
|
||||
.body("authorizerConfig.defaultAuthorizerName", equalTo("it-authorizer"))
|
||||
.body("authorizerConfig.allowAuthorizerOverride", equalTo(true))
|
||||
.body("tlsConfig.securityPolicy", equalTo("IoTSecurityPolicy_TLS13_1_2_2022_10"))
|
||||
.body("serverCertificateConfig.enableOCSPCheck", equalTo(false))
|
||||
.body("lastStatusChangeDate", notNullValue());
|
||||
|
||||
given()
|
||||
.queryParam("resourceArn", arn)
|
||||
.when()
|
||||
.get("/tags")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.Key", hasItem("env"))
|
||||
.body("tags.Value", hasItem("it"));
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"resourceArn\": \"" + arn + "\", \"tags\": [{\"Key\": \"owner\", \"Value\": \"iot\"}]}")
|
||||
.when()
|
||||
.post("/tags")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"resourceArn\": \"" + arn + "\", \"tagKeys\": [\"env\"]}")
|
||||
.when()
|
||||
.post("/untag")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.queryParam("resourceArn", arn)
|
||||
.when()
|
||||
.get("/tags")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.Key", hasItem("owner"))
|
||||
.body("tags.Key", not(hasItem("env")));
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(createBody("jobs.it.example.com", "JOBS"))
|
||||
.when()
|
||||
.post("/domainConfigurations/" + NAME + "-jobs")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.queryParam("serviceType", "JOBS")
|
||||
.when()
|
||||
.get("/domainConfigurations")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurations.domainConfigurationName", hasItem(NAME + "-jobs"))
|
||||
.body("domainConfigurations.domainConfigurationName", not(hasItem(NAME)))
|
||||
.body("domainConfigurations[0].serviceType", equalTo("JOBS"))
|
||||
.body("domainConfigurations[0].domainConfigurationArn", notNullValue());
|
||||
|
||||
String marker = given()
|
||||
.queryParam("pageSize", 1)
|
||||
.when()
|
||||
.get("/domainConfigurations")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurations.size()", equalTo(1))
|
||||
.body("nextMarker", notNullValue())
|
||||
.extract().path("nextMarker");
|
||||
|
||||
given()
|
||||
.queryParam("pageSize", 1)
|
||||
.queryParam("marker", marker)
|
||||
.when()
|
||||
.get("/domainConfigurations")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurations.size()", equalTo(1));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"));
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"domainConfigurationStatus\": \"DISABLED\", \"removeAuthorizerConfig\": true}")
|
||||
.when()
|
||||
.put("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurationName", equalTo(NAME))
|
||||
.body("domainConfigurationArn", equalTo(arn));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurationStatus", equalTo("DISABLED"))
|
||||
.body("authorizerConfig", equalTo(null));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/domainConfigurations/" + NAME)
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.header("x-amzn-ErrorType", equalTo("ResourceNotFoundException"))
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"domainConfigurationStatus\": \"DISABLED\"}")
|
||||
.when()
|
||||
.put("/domainConfigurations/" + NAME + "-jobs")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
given()
|
||||
.when()
|
||||
.delete("/domainConfigurations/" + NAME + "-jobs")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsManagedConfigurationsExistWithoutBeingCreated() {
|
||||
given()
|
||||
.when()
|
||||
.get("/domainConfigurations/iot:Data-ATS")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurationName", equalTo("iot:Data-ATS"))
|
||||
.body("domainConfigurationArn",
|
||||
startsWith("arn:aws:iot:us-east-1:000000000000:domainconfiguration/iot:Data-ATS/"))
|
||||
.body("domainName", equalTo("localhost:4566"))
|
||||
.body("domainType", equalTo("AWS_MANAGED"))
|
||||
.body("serviceType", equalTo("DATA"))
|
||||
.body("domainConfigurationStatus", equalTo("ENABLED"))
|
||||
.body("serverCertificates.size()", equalTo(0))
|
||||
.body("tlsConfig.securityPolicy", equalTo("IoTSecurityPolicy_TLS13_1_2_2022_10"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/domainConfigurations")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurations.domainConfigurationName",
|
||||
hasItems("iot:Data-ATS", "iot:Data", "iot:CredentialProvider", "iot:Jobs"));
|
||||
|
||||
given()
|
||||
.queryParam("serviceType", "CREDENTIAL_PROVIDER")
|
||||
.when()
|
||||
.get("/domainConfigurations")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurations.domainConfigurationName", hasItem("iot:CredentialProvider"))
|
||||
.body("domainConfigurations.domainConfigurationName", not(hasItem("iot:Jobs")));
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"domainConfigurationStatus\": \"DISABLED\"}")
|
||||
.when()
|
||||
.put("/domainConfigurations/iot:Data")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurationName", equalTo("iot:Data"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/domainConfigurations/iot:Data")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainConfigurationStatus", equalTo("DISABLED"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/domainConfigurations/iot:Data")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"));
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"domainConfigurationStatus\": \"ENABLED\"}")
|
||||
.when()
|
||||
.put("/domainConfigurations/iot:Data")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownDomainConfigurationIsNotFoundOnEveryRoute() {
|
||||
given()
|
||||
.when()
|
||||
.get("/domainConfigurations/absent")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"domainConfigurationStatus\": \"ENABLED\"}")
|
||||
.when()
|
||||
.put("/domainConfigurations/absent")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/domainConfigurations/absent")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsAReservedNameAndListRejectsABadPageSize() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(createBody("data.it.example.com", "DATA"))
|
||||
.when()
|
||||
.post("/domainConfigurations/iot:Data-ATS")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"));
|
||||
|
||||
given()
|
||||
.queryParam("pageSize", 0)
|
||||
.when()
|
||||
.get("/domainConfigurations")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeEndpointAcceptsTheCredentialProviderEndpointType() {
|
||||
given()
|
||||
.queryParam("endpointType", "iot:CredentialProvider")
|
||||
.when()
|
||||
.get("/endpoint")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("endpointAddress", equalTo("localhost:4566"));
|
||||
}
|
||||
}
|
||||
+567
@@ -0,0 +1,567 @@
|
||||
package io.github.hectorvent.floci.services.iot;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.iot.model.IotDomainConfiguration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class IotDomainConfigurationServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String CERTIFICATE_ARN =
|
||||
"arn:aws:acm:us-east-1:000000000000:certificate/11111111-1111-1111-1111-111111111111";
|
||||
private static final String OTHER_CERTIFICATE_ARN =
|
||||
"arn:aws:acm:us-east-1:000000000000:certificate/22222222-2222-2222-2222-222222222222";
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private final IotDomainConfigurationService service = new IotDomainConfigurationService(
|
||||
new InMemoryStorage<>(), new RegionResolver(REGION, "000000000000"), endpointConfig());
|
||||
|
||||
private static EmulatorConfig endpointConfig() {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
when(config.effectiveBaseUrl()).thenReturn("http://localhost:4566");
|
||||
return config;
|
||||
}
|
||||
|
||||
private ObjectNode customDomainRequest() {
|
||||
ObjectNode request = mapper.createObjectNode().put("domainName", "iot.example.com");
|
||||
request.putArray("serverCertificateArns").add(CERTIFICATE_ARN);
|
||||
return request;
|
||||
}
|
||||
|
||||
private static AwsException assertAwsError(String code, int status, Runnable call) {
|
||||
AwsException failure = assertThrows(AwsException.class, call::run);
|
||||
assertEquals(code, failure.getErrorCode());
|
||||
assertEquals(status, failure.getHttpStatus());
|
||||
return failure;
|
||||
}
|
||||
|
||||
@Test
|
||||
void createReturnsAnEnabledCustomerManagedConfiguration() {
|
||||
IotDomainConfiguration created = service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION);
|
||||
|
||||
assertEquals("iot-domain", created.getDomainConfigurationName());
|
||||
assertTrue(created.getDomainConfigurationArn().matches(
|
||||
"arn:aws:iot:us-east-1:000000000000:domainconfiguration/iot-domain/[a-z0-9]{5}"),
|
||||
"AWS appends a short id to the ARN: " + created.getDomainConfigurationArn());
|
||||
assertEquals("iot.example.com", created.getDomainName());
|
||||
assertEquals("DATA", created.getServiceType());
|
||||
assertEquals("ENABLED", created.getDomainConfigurationStatus());
|
||||
assertEquals("CUSTOMER_MANAGED", created.getDomainType());
|
||||
assertEquals(List.of(new IotDomainConfiguration.ServerCertificateSummary(CERTIFICATE_ARN, "VALID", null)),
|
||||
created.getServerCertificates());
|
||||
assertEquals(new IotDomainConfiguration.TlsConfig("IoTSecurityPolicy_TLS13_1_2_2022_10"), created.getTlsConfig());
|
||||
assertEquals(new IotDomainConfiguration.ServerCertificateConfig(false, null, null), created.getServerCertificateConfig());
|
||||
assertNotNull(created.getLastStatusChangeDate());
|
||||
assertNull(created.getAuthorizerConfig());
|
||||
assertNull(created.getAuthenticationType());
|
||||
assertNull(created.getApplicationProtocol());
|
||||
assertNull(created.getClientCertificateConfig());
|
||||
assertTrue(created.getTags().isEmpty());
|
||||
assertEquals(created.getDomainConfigurationArn(),
|
||||
service.describeDomainConfiguration("iot-domain", REGION).getDomainConfigurationArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStoresEveryRequestField() {
|
||||
ObjectNode request = customDomainRequest()
|
||||
.put("serviceType", "JOBS")
|
||||
.put("validationCertificateArn", OTHER_CERTIFICATE_ARN)
|
||||
.put("authenticationType", "CUSTOM_AUTH")
|
||||
.put("applicationProtocol", "MQTT_WSS");
|
||||
request.putObject("authorizerConfig").put("defaultAuthorizerName", "my-authorizer").put("allowAuthorizerOverride", true);
|
||||
request.putObject("tlsConfig").put("securityPolicy", "IoTSecurityPolicy_TLS12_1_2_2022_10");
|
||||
request.putObject("serverCertificateConfig").put("enableOCSPCheck", true)
|
||||
.put("ocspLambdaArn", "arn:aws:lambda:us-east-1:000000000000:function:ocsp")
|
||||
.put("ocspAuthorizedResponderArn", OTHER_CERTIFICATE_ARN);
|
||||
request.putObject("clientCertificateConfig")
|
||||
.put("clientCertificateCallbackArn", "arn:aws:lambda:us-east-1:000000000000:function:callback");
|
||||
request.putArray("tags").addObject().put("Key", "env").put("Value", "test");
|
||||
|
||||
IotDomainConfiguration created = service.createDomainConfiguration("iot-domain", request, REGION);
|
||||
|
||||
assertEquals("JOBS", created.getServiceType());
|
||||
assertEquals(OTHER_CERTIFICATE_ARN, created.getValidationCertificateArn());
|
||||
assertEquals(new IotDomainConfiguration.AuthorizerConfig("my-authorizer", true), created.getAuthorizerConfig());
|
||||
assertEquals(new IotDomainConfiguration.TlsConfig("IoTSecurityPolicy_TLS12_1_2_2022_10"), created.getTlsConfig());
|
||||
assertEquals(new IotDomainConfiguration.ServerCertificateConfig(true,
|
||||
"arn:aws:lambda:us-east-1:000000000000:function:ocsp", OTHER_CERTIFICATE_ARN),
|
||||
created.getServerCertificateConfig());
|
||||
assertEquals("CUSTOM_AUTH", created.getAuthenticationType());
|
||||
assertEquals("MQTT_WSS", created.getApplicationProtocol());
|
||||
assertEquals(new IotDomainConfiguration.ClientCertificateConfig(
|
||||
"arn:aws:lambda:us-east-1:000000000000:function:callback"), created.getClientCertificateConfig());
|
||||
assertEquals(Map.of("env", "test"), created.getTags());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithoutADomainNameIsAnEndpointConfiguration() {
|
||||
IotDomainConfiguration created = service.createDomainConfiguration("default-endpoint", mapper.createObjectNode(), REGION);
|
||||
|
||||
assertEquals("ENDPOINT", created.getDomainType());
|
||||
assertNull(created.getDomainName());
|
||||
assertTrue(created.getServerCertificates().isEmpty());
|
||||
assertEquals("ENABLED", created.getDomainConfigurationStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTreatsAJsonNullAsAbsent() {
|
||||
ObjectNode request = customDomainRequest();
|
||||
request.putNull("authorizerConfig");
|
||||
request.putNull("validationCertificateArn");
|
||||
request.putNull("authenticationType");
|
||||
request.putNull("tags");
|
||||
|
||||
IotDomainConfiguration created = service.createDomainConfiguration("iot-domain", request, REGION);
|
||||
|
||||
assertNull(created.getAuthorizerConfig());
|
||||
assertNull(created.getValidationCertificateArn());
|
||||
assertNull(created.getAuthenticationType());
|
||||
assertTrue(created.getTags().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStoresATagWithoutAValueAsEmpty() {
|
||||
ObjectNode request = customDomainRequest();
|
||||
request.putArray("tags").addObject().put("Key", "env");
|
||||
|
||||
assertEquals(Map.of("env", ""), service.createDomainConfiguration("iot-domain", request, REGION).getTags());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsAStructuredValueWhereAStringIsExpected() {
|
||||
ObjectNode request = customDomainRequest();
|
||||
request.putObject("domainName");
|
||||
|
||||
assertAwsError("InvalidRequestException", 400,
|
||||
() -> service.createDomainConfiguration("iot-domain", request, REGION));
|
||||
assertAwsError("ResourceNotFoundException", 404, () -> service.describeDomainConfiguration("iot-domain", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateRejectsAnAuthorizerConfigThatIsNotAnObjectAndKeepsTheStoredOne() {
|
||||
ObjectNode create = customDomainRequest();
|
||||
create.putObject("authorizerConfig").put("defaultAuthorizerName", "first");
|
||||
service.createDomainConfiguration("iot-domain", create, REGION);
|
||||
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.updateDomainConfiguration("iot-domain",
|
||||
mapper.createObjectNode().put("authorizerConfig", "not-an-object"), REGION));
|
||||
assertEquals(new IotDomainConfiguration.AuthorizerConfig("first", null),
|
||||
service.describeDomainConfiguration("iot-domain", REGION).getAuthorizerConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsManagedConfigurationsExistInEveryRegionWithoutBeingCreated() {
|
||||
IotDomainConfiguration dataAts = service.describeDomainConfiguration("iot:Data-ATS", REGION);
|
||||
|
||||
assertTrue(dataAts.getDomainConfigurationArn().matches(
|
||||
"arn:aws:iot:us-east-1:000000000000:domainconfiguration/iot:Data-ATS/[a-z0-9]{5}"),
|
||||
dataAts.getDomainConfigurationArn());
|
||||
assertEquals("localhost:4566", dataAts.getDomainName());
|
||||
assertEquals("DATA", dataAts.getServiceType());
|
||||
assertEquals("AWS_MANAGED", dataAts.getDomainType());
|
||||
assertEquals("ENABLED", dataAts.getDomainConfigurationStatus());
|
||||
assertTrue(dataAts.getServerCertificates().isEmpty());
|
||||
assertEquals(new IotDomainConfiguration.TlsConfig("IoTSecurityPolicy_TLS13_1_2_2022_10"), dataAts.getTlsConfig());
|
||||
assertEquals(new IotDomainConfiguration.ServerCertificateConfig(false, null, null), dataAts.getServerCertificateConfig());
|
||||
assertNotNull(dataAts.getLastStatusChangeDate());
|
||||
assertEquals(dataAts.getDomainConfigurationArn(),
|
||||
service.describeDomainConfiguration("iot:Data-ATS", REGION).getDomainConfigurationArn(),
|
||||
"seeded once, so the ARN is stable");
|
||||
|
||||
assertEquals("DATA", service.describeDomainConfiguration("iot:Data", REGION).getServiceType());
|
||||
assertEquals("CREDENTIAL_PROVIDER",
|
||||
service.describeDomainConfiguration("iot:CredentialProvider", REGION).getServiceType());
|
||||
assertEquals("JOBS", service.describeDomainConfiguration("iot:Jobs", REGION).getServiceType());
|
||||
assertTrue(service.describeDomainConfiguration("iot:Jobs", "eu-west-1").getDomainConfigurationArn()
|
||||
.startsWith("arn:aws:iot:eu-west-1:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsManagedConfigurationsCanBeUpdatedAndTaggedButNotDeleted() {
|
||||
IotDomainConfiguration legacy = service.updateDomainConfiguration("iot:Data",
|
||||
mapper.createObjectNode().put("domainConfigurationStatus", "DISABLED"), REGION);
|
||||
assertEquals("DISABLED", legacy.getDomainConfigurationStatus());
|
||||
assertEquals("DISABLED", service.describeDomainConfiguration("iot:Data", REGION).getDomainConfigurationStatus());
|
||||
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.deleteDomainConfiguration("iot:Data", REGION));
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.deleteDomainConfiguration("iot:Data-ATS", REGION));
|
||||
assertEquals("AWS_MANAGED", service.describeDomainConfiguration("iot:Data", REGION).getDomainType());
|
||||
|
||||
String jobsArn = service.describeDomainConfiguration("iot:Jobs", REGION).getDomainConfigurationArn();
|
||||
service.tagResource(jobsArn, Map.of("team", "devices"));
|
||||
assertEquals(Map.of("team", "devices"), service.listTagsForResource(jobsArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configurationSurvivesTheJsonRoundTripPersistentStorageUses() throws Exception {
|
||||
ObjectNode request = customDomainRequest()
|
||||
.put("serviceType", "JOBS")
|
||||
.put("validationCertificateArn", OTHER_CERTIFICATE_ARN)
|
||||
.put("authenticationType", "CUSTOM_AUTH")
|
||||
.put("applicationProtocol", "MQTT_WSS");
|
||||
request.putObject("authorizerConfig").put("defaultAuthorizerName", "my-authorizer").put("allowAuthorizerOverride", true);
|
||||
request.putObject("serverCertificateConfig").put("enableOCSPCheck", true)
|
||||
.put("ocspLambdaArn", "arn:aws:lambda:us-east-1:000000000000:function:ocsp");
|
||||
request.putObject("clientCertificateConfig").put("clientCertificateCallbackArn", "arn:aws:lambda:us-east-1:000000000000:function:cb");
|
||||
request.putArray("tags").addObject().put("Key", "env").put("Value", "test");
|
||||
IotDomainConfiguration created = service.createDomainConfiguration("iot-domain", request, REGION);
|
||||
|
||||
// The same mapper setup PersistentStorage uses: defaults plus java.time, so an unmapped
|
||||
// property or an unreadable record would fail the reload of a persisted store.
|
||||
ObjectMapper persistence = new ObjectMapper().registerModule(new JavaTimeModule());
|
||||
String json = persistence.writeValueAsString(created);
|
||||
IotDomainConfiguration reloaded = persistence.readValue(json, IotDomainConfiguration.class);
|
||||
|
||||
assertEquals(json, persistence.writeValueAsString(reloaded));
|
||||
assertEquals(created.getDomainConfigurationArn(), reloaded.getDomainConfigurationArn());
|
||||
assertEquals(created.getServerCertificates(), reloaded.getServerCertificates());
|
||||
assertEquals(created.getAuthorizerConfig(), reloaded.getAuthorizerConfig());
|
||||
assertEquals(created.getTlsConfig(), reloaded.getTlsConfig());
|
||||
assertEquals(created.getServerCertificateConfig(), reloaded.getServerCertificateConfig());
|
||||
assertEquals(created.getClientCertificateConfig(), reloaded.getClientCertificateConfig());
|
||||
assertEquals(created.getLastStatusChangeDate(), reloaded.getLastStatusChangeDate());
|
||||
assertEquals(created.getTags(), reloaded.getTags());
|
||||
}
|
||||
|
||||
@Test
|
||||
void concurrentTagWritesOnOneConfigurationKeepEveryKey() throws Exception {
|
||||
String arn = service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION).getDomainConfigurationArn();
|
||||
int writers = 16;
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
ExecutorService pool = Executors.newFixedThreadPool(writers);
|
||||
try {
|
||||
List<Future<?>> writes = new ArrayList<>();
|
||||
for (int i = 0; i < writers; i++) {
|
||||
String tagKey = "key" + i;
|
||||
writes.add(pool.submit(() -> {
|
||||
start.await();
|
||||
service.tagResource(arn, Map.of(tagKey, "v"));
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
start.countDown();
|
||||
for (Future<?> write : writes) {
|
||||
write.get();
|
||||
}
|
||||
assertEquals(writers, service.listTagsForResource(arn).size(), "a concurrent tag write must not drop another writer's key");
|
||||
} finally {
|
||||
pool.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsADuplicateName() {
|
||||
service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION);
|
||||
|
||||
assertAwsError("ResourceAlreadyExistsException", 409,
|
||||
() -> service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void concurrentCreatesOfTheSameNameLetExactlyOneThrough() throws Exception {
|
||||
int callers = 16;
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
AtomicInteger conflicts = new AtomicInteger();
|
||||
List<Future<String>> results = new ArrayList<>();
|
||||
ExecutorService pool = Executors.newFixedThreadPool(callers);
|
||||
try {
|
||||
for (int i = 0; i < callers; i++) {
|
||||
results.add(pool.submit(() -> {
|
||||
start.await();
|
||||
try {
|
||||
return service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION)
|
||||
.getDomainConfigurationArn();
|
||||
} catch (AwsException e) {
|
||||
assertEquals("ResourceAlreadyExistsException", e.getErrorCode());
|
||||
conflicts.incrementAndGet();
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
}
|
||||
start.countDown();
|
||||
List<String> arns = new ArrayList<>();
|
||||
for (Future<String> result : results) {
|
||||
String arn = result.get();
|
||||
if (arn != null) {
|
||||
arns.add(arn);
|
||||
}
|
||||
}
|
||||
assertEquals(1, arns.size(), "exactly one create may succeed");
|
||||
assertEquals(callers - 1, conflicts.get());
|
||||
assertEquals(arns.get(0), service.describeDomainConfiguration("iot-domain", REGION).getDomainConfigurationArn());
|
||||
} finally {
|
||||
pool.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsTagsThatAreNotAList() {
|
||||
ObjectNode request = customDomainRequest();
|
||||
request.putObject("tags").put("env", "test");
|
||||
|
||||
assertAwsError("InvalidRequestException", 400,
|
||||
() -> service.createDomainConfiguration("iot-domain", request, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsNamesOutsideTheAwsPattern() {
|
||||
for (String name : List.of("", "has space", "iot:Data-ATS", "x".repeat(129))) {
|
||||
assertAwsError("InvalidRequestException", 400,
|
||||
() -> service.createDomainConfiguration(name, customDomainRequest(), REGION));
|
||||
}
|
||||
assertAwsError("InvalidRequestException", 400,
|
||||
() -> service.createDomainConfiguration(null, customDomainRequest(), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsMoreThanOneServerCertificate() {
|
||||
ObjectNode request = customDomainRequest();
|
||||
request.withArray("serverCertificateArns").add(OTHER_CERTIFICATE_ARN);
|
||||
|
||||
assertAwsError("InvalidRequestException", 400,
|
||||
() -> service.createDomainConfiguration("iot-domain", request, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsACustomDomainWithoutAServerCertificate() {
|
||||
ObjectNode request = mapper.createObjectNode().put("domainName", "iot.example.com");
|
||||
|
||||
assertAwsError("InvalidRequestException", 400,
|
||||
() -> service.createDomainConfiguration("iot-domain", request, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsValuesOutsideTheAwsEnums() {
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.createDomainConfiguration(
|
||||
"a", customDomainRequest().put("serviceType", "MQTT"), REGION));
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.createDomainConfiguration(
|
||||
"b", customDomainRequest().put("authenticationType", "NONE"), REGION));
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.createDomainConfiguration(
|
||||
"c", customDomainRequest().put("applicationProtocol", "AMQP"), REGION));
|
||||
assertAwsError("ResourceNotFoundException", 404, () -> service.describeDomainConfiguration("a", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeUnknownConfigurationIsNotFound() {
|
||||
assertAwsError("ResourceNotFoundException", 404,
|
||||
() -> service.describeDomainConfiguration("missing", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configurationsAreScopedToTheirRegion() {
|
||||
service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION);
|
||||
|
||||
assertAwsError("ResourceNotFoundException", 404,
|
||||
() -> service.describeDomainConfiguration("iot-domain", "eu-west-1"));
|
||||
IotDomainConfiguration other = service.createDomainConfiguration("iot-domain", customDomainRequest(), "eu-west-1");
|
||||
assertTrue(other.getDomainConfigurationArn().startsWith("arn:aws:iot:eu-west-1:"));
|
||||
assertFalse(other.getDomainConfigurationArn().equals(
|
||||
service.describeDomainConfiguration("iot-domain", REGION).getDomainConfigurationArn()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFlipsTheStatusAndRecordsWhenItChanged() throws InterruptedException {
|
||||
Instant createdAt = service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION)
|
||||
.getLastStatusChangeDate();
|
||||
Thread.sleep(10);
|
||||
|
||||
IotDomainConfiguration updated = service.updateDomainConfiguration("iot-domain",
|
||||
mapper.createObjectNode().put("domainConfigurationStatus", "DISABLED"), REGION);
|
||||
|
||||
assertEquals("DISABLED", updated.getDomainConfigurationStatus());
|
||||
assertTrue(updated.getLastStatusChangeDate().isAfter(createdAt));
|
||||
assertEquals("DISABLED", service.describeDomainConfiguration("iot-domain", REGION).getDomainConfigurationStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWithTheSameStatusKeepsLastStatusChangeDate() throws InterruptedException {
|
||||
Instant createdAt = service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION)
|
||||
.getLastStatusChangeDate();
|
||||
Thread.sleep(10);
|
||||
|
||||
IotDomainConfiguration updated = service.updateDomainConfiguration("iot-domain",
|
||||
mapper.createObjectNode().put("domainConfigurationStatus", "ENABLED"), REGION);
|
||||
|
||||
assertEquals(createdAt, updated.getLastStatusChangeDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateRejectsAnUnknownStatus() {
|
||||
service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION);
|
||||
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.updateDomainConfiguration("iot-domain",
|
||||
mapper.createObjectNode().put("domainConfigurationStatus", "PAUSED"), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateReplacesTheAuthorizerAndRemoveAuthorizerConfigClearsIt() {
|
||||
ObjectNode create = customDomainRequest();
|
||||
create.putObject("authorizerConfig").put("defaultAuthorizerName", "first");
|
||||
service.createDomainConfiguration("iot-domain", create, REGION);
|
||||
|
||||
ObjectNode replace = mapper.createObjectNode();
|
||||
replace.putObject("authorizerConfig").put("defaultAuthorizerName", "second").put("allowAuthorizerOverride", false);
|
||||
assertEquals(new IotDomainConfiguration.AuthorizerConfig("second", false),
|
||||
service.updateDomainConfiguration("iot-domain", replace, REGION).getAuthorizerConfig());
|
||||
|
||||
ObjectNode remove = mapper.createObjectNode().put("removeAuthorizerConfig", true);
|
||||
assertNull(service.updateDomainConfiguration("iot-domain", remove, REGION).getAuthorizerConfig());
|
||||
assertNull(service.describeDomainConfiguration("iot-domain", REGION).getAuthorizerConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAppliesTlsCertificateAndProtocolSettingsAndLeavesTheRestAlone() {
|
||||
IotDomainConfiguration created = service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION);
|
||||
ObjectNode request = mapper.createObjectNode()
|
||||
.put("authenticationType", "AWS_SIGV4")
|
||||
.put("applicationProtocol", "HTTPS");
|
||||
request.putObject("tlsConfig").put("securityPolicy", "IoTSecurityPolicy_TLS12_1_2_2022_10");
|
||||
request.putObject("serverCertificateConfig").put("enableOCSPCheck", true);
|
||||
request.putObject("clientCertificateConfig")
|
||||
.put("clientCertificateCallbackArn", "arn:aws:lambda:us-east-1:000000000000:function:callback");
|
||||
|
||||
IotDomainConfiguration updated = service.updateDomainConfiguration("iot-domain", request, REGION);
|
||||
|
||||
assertEquals(new IotDomainConfiguration.TlsConfig("IoTSecurityPolicy_TLS12_1_2_2022_10"), updated.getTlsConfig());
|
||||
assertEquals(new IotDomainConfiguration.ServerCertificateConfig(true, null, null), updated.getServerCertificateConfig());
|
||||
assertEquals("AWS_SIGV4", updated.getAuthenticationType());
|
||||
assertEquals("HTTPS", updated.getApplicationProtocol());
|
||||
assertEquals(new IotDomainConfiguration.ClientCertificateConfig(
|
||||
"arn:aws:lambda:us-east-1:000000000000:function:callback"), updated.getClientCertificateConfig());
|
||||
assertEquals(created.getDomainConfigurationArn(), updated.getDomainConfigurationArn());
|
||||
assertEquals("iot.example.com", updated.getDomainName());
|
||||
assertEquals("DATA", updated.getServiceType());
|
||||
assertEquals("ENABLED", updated.getDomainConfigurationStatus());
|
||||
assertEquals(created.getServerCertificates(), updated.getServerCertificates());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUnknownConfigurationIsNotFound() {
|
||||
assertAwsError("ResourceNotFoundException", 404, () -> service.updateDomainConfiguration("missing",
|
||||
mapper.createObjectNode().put("domainConfigurationStatus", "DISABLED"), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRefusesAnEnabledConfiguration() {
|
||||
service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION);
|
||||
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.deleteDomainConfiguration("iot-domain", REGION));
|
||||
assertEquals("ENABLED", service.describeDomainConfiguration("iot-domain", REGION).getDomainConfigurationStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRemovesADisabledConfiguration() {
|
||||
service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION);
|
||||
service.updateDomainConfiguration("iot-domain",
|
||||
mapper.createObjectNode().put("domainConfigurationStatus", "DISABLED"), REGION);
|
||||
|
||||
service.deleteDomainConfiguration("iot-domain", REGION);
|
||||
|
||||
assertAwsError("ResourceNotFoundException", 404, () -> service.describeDomainConfiguration("iot-domain", REGION));
|
||||
assertAwsError("ResourceNotFoundException", 404, () -> service.deleteDomainConfiguration("iot-domain", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listReturnsConfigurationsSortedByNameAndFiltersByServiceType() {
|
||||
service.createDomainConfiguration("zulu", customDomainRequest(), REGION);
|
||||
service.createDomainConfiguration("alpha", customDomainRequest().put("serviceType", "JOBS"), REGION);
|
||||
service.createDomainConfiguration("mike", customDomainRequest(), "eu-west-1");
|
||||
|
||||
IotService.Page<IotDomainConfiguration> all = service.listDomainConfigurations(REGION, null, null, null);
|
||||
assertEquals(List.of("alpha", "iot:CredentialProvider", "iot:Data", "iot:Data-ATS", "iot:Jobs", "zulu"),
|
||||
all.items().stream().map(IotDomainConfiguration::getDomainConfigurationName).toList());
|
||||
assertNull(all.nextToken());
|
||||
|
||||
IotService.Page<IotDomainConfiguration> jobs = service.listDomainConfigurations(REGION, "JOBS", null, null);
|
||||
assertEquals(List.of("alpha", "iot:Jobs"),
|
||||
jobs.items().stream().map(IotDomainConfiguration::getDomainConfigurationName).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listPagesWithMarkerAndPageSize() {
|
||||
for (String name : List.of("a", "b", "c")) {
|
||||
service.createDomainConfiguration(name, customDomainRequest(), REGION);
|
||||
}
|
||||
|
||||
IotService.Page<IotDomainConfiguration> first = service.listDomainConfigurations(REGION, null, null, 3);
|
||||
assertEquals(List.of("a", "b", "c"),
|
||||
first.items().stream().map(IotDomainConfiguration::getDomainConfigurationName).toList());
|
||||
assertNotNull(first.nextToken());
|
||||
|
||||
IotService.Page<IotDomainConfiguration> second =
|
||||
service.listDomainConfigurations(REGION, null, first.nextToken(), 3);
|
||||
assertEquals(List.of("iot:CredentialProvider", "iot:Data", "iot:Data-ATS"),
|
||||
second.items().stream().map(IotDomainConfiguration::getDomainConfigurationName).toList());
|
||||
assertNotNull(second.nextToken());
|
||||
|
||||
IotService.Page<IotDomainConfiguration> third =
|
||||
service.listDomainConfigurations(REGION, null, second.nextToken(), 3);
|
||||
assertEquals(List.of("iot:Jobs"),
|
||||
third.items().stream().map(IotDomainConfiguration::getDomainConfigurationName).toList());
|
||||
assertNull(third.nextToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listRejectsInvalidPagingAndFilterValues() {
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.listDomainConfigurations(REGION, null, null, 0));
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.listDomainConfigurations(REGION, null, null, 251));
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.listDomainConfigurations(REGION, null, "not-a-marker", null));
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.listDomainConfigurations(REGION, "MQTT", null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagsCanBeListedAddedAndRemovedByArn() {
|
||||
ObjectNode request = customDomainRequest();
|
||||
request.putArray("tags").addObject().put("Key", "env").put("Value", "test");
|
||||
String arn = service.createDomainConfiguration("iot-domain", request, REGION).getDomainConfigurationArn();
|
||||
|
||||
assertEquals(Map.of("env", "test"), service.listTagsForResource(arn));
|
||||
|
||||
service.tagResource(arn, Map.of("owner", "iot", "env", "prod"));
|
||||
assertEquals(Map.of("env", "prod", "owner", "iot"), service.listTagsForResource(arn));
|
||||
|
||||
service.untagResource(arn, List.of("env", "absent"));
|
||||
assertEquals(Map.of("owner", "iot"), service.listTagsForResource(arn));
|
||||
assertEquals(Map.of("owner", "iot"), service.describeDomainConfiguration("iot-domain", REGION).getTags());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagOperationsRejectArnsThatDoNotNameAStoredConfiguration() {
|
||||
String arn = service.createDomainConfiguration("iot-domain", customDomainRequest(), REGION).getDomainConfigurationArn();
|
||||
|
||||
assertAwsError("InvalidRequestException", 400,
|
||||
() -> service.listTagsForResource("arn:aws:iot:us-east-1:000000000000:thing/some-thing"));
|
||||
assertAwsError("InvalidRequestException", 400, () -> service.listTagsForResource("not-an-arn"));
|
||||
assertAwsError("ResourceNotFoundException", 404,
|
||||
() -> service.listTagsForResource("arn:aws:iot:us-east-1:000000000000:domainconfiguration/missing/abcde"));
|
||||
assertAwsError("ResourceNotFoundException", 404,
|
||||
() -> service.tagResource(arn.replaceAll("/[a-z0-9]{5}$", "/zzzzz"), Map.of("k", "v")));
|
||||
assertAwsError("ResourceNotFoundException", 404,
|
||||
() -> service.untagResource("arn:aws:iot:eu-west-1:000000000000:domainconfiguration/iot-domain/abcde", List.of("k")));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user