mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(amazonmq): add Amazon MQ broker control plane backed by RabbitMQ (#1642)
* feat(amazonmq): add Amazon MQ broker control plane for RabbitMQ
* feat(amazonmq): provision RabbitMQ container with rollback
Back a broker with a real rabbitmq:3-management container, following the
MSK/ElastiCache container-manager pattern.
- RabbitMqManager starts the container, publishes AMQP (5672) and
management (15672) ports, and resolves the broker endpoints
- Service branches on the mock flag; real brokers stay
CREATION_IN_PROGRESS until a readiness poller observes the management
API answering, then flip to RUNNING
- Rollback on failed provisioning: the manager removes the half-built
container and the broker is persisted as CREATION_FAILED
- @PreDestroy stops containers on shutdown; DeleteBroker stops and
removes the container and its storage
Readiness probes the management UI root (no auth) to avoid RabbitMQ's
loopback-only guest user over Docker port mapping.
* feat(amazonmq): seed broker admin user and reject ActiveMQ-only User API
Amazon MQ's standalone User API (CreateUser/DescribeUser/ListUsers/
DeleteUser) applies only to ActiveMQ brokers; AWS rejects it for RabbitMQ
and directs callers to the RabbitMQ web console. CreateBroker now requires
exactly one broker user (validated against AWS password rules) which is
seeded into the container via RABBITMQ_DEFAULT_USER/PASS, sidestepping
RabbitMQ's loopback-only guest restriction.
* test(amazonmq): SDK compatibility test against live RabbitMQ broker
Adds AmazonMqTest exercising the real container path via the AWS SDK MqClient:
CreateBroker provisions a rabbitmq:3-management container, the broker
transitions to RUNNING once its management API answers, endpoints are
published, the ActiveMQ-only User API is rejected, and DeleteBroker tears the
container down. Uses JUnit Assumptions to skip cleanly when Docker is absent.
* fix(amazonmq): harden error handling, persistence, and shutdown teardown
- Redact the provisioning failure 500: log the cause, return a generic AWS
error envelope instead of leaking e.getMessage() (which can be null).
- Add @JsonIgnoreProperties(ignoreUnknown = true) to Broker, MqUser, and
BrokerInstance so old persisted snapshots survive field changes.
- Wire RabbitMQ container teardown into EmulatorLifecycle.onStop() via
RabbitMqManager.stopAll(), alongside the other container managers; the
service @PreDestroy now only stops the readiness poller.
* docs(amazonmq): add Amazon MQ service page and bump service count to 66
Adds docs/services/amazonmq.md, lists Amazon MQ in the services overview and
README service tables, and updates the "65 -> 66 AWS services" count across
docs/index.md, docs/services/index.md, and README.md.
* fix(amazonmq): reject RebootBroker unless the broker is RUNNING
RebootBroker unconditionally set the broker to RUNNING, so a non-RUNNING
broker (e.g. CREATION_FAILED, which has no backing container) was silently
promoted to RUNNING and never reconciled by the readiness poller. AWS allows
RebootBroker only on a broker in the RUNNING state; guard it and return a 400
otherwise, matching the Amazon MQ API ("You can reboot only a broker with the
RUNNING status").
* fix(amazonmq): close readiness-probe connection and log tolerated failures
isReady() opened an HttpURLConnection but never disconnected it; since the
probe runs every 2s per pending broker this leaked sockets. Disconnect in a
finally block, and log the tolerated failure at debug with broker/URL context
(AGENTS.md: no empty catch; avoid noise in hot paths) instead of swallowing it.
* fix(amazonmq): tear down broker container by deterministic name after restart
containerId is in-memory bookkeeping (intentionally not persisted, since the
Broker model is serialized straight to DescribeBroker and must not leak it).
After an emulator restart it is null, so stopContainer() previously returned
early and left the container running. It now falls back to the deterministic
container name (floci-amazonmq-{brokerId}) so an explicit DeleteBroker still
removes a container left over from a previous run. Documented the field and
added RabbitMqManagerTest covering both the id and name-fallback paths.
* fix(amazonmq): keep admin password in-memory only and fail loudly if absent
The admin password is a secret used solely to seed the RabbitMQ container at
create time. Persisting it (to make it survive a restart) would write the
credential in cleartext to amazonmq-brokers.json, which the project's security
rule prohibits. It stays in-memory only via @JsonIgnore; startContainer (the
only consumer, called from CreateBroker) now throws if the password is absent
rather than seeding a null credential. Added MqUserTest asserting the password
is never serialized and round-trips to null.
* fix(amazonmq): persist broker volumeId/accountId/containerId without leaking them
These internal fields were @JsonIgnore'd, so they were absent from
amazonmq-brokers.json. After a restart in persistent mode volumeId was null
(removeBrokerStorage could not locate the named volume, leaking it) and
accountId was null (the readiness poller wrote brokers via the non-account-aware
path). Unlike the admin password, these are not secrets, so they should persist.
Remove @JsonIgnore so they round-trip through storage, and build the
DescribeBroker response explicitly in the controller so they are still never
exposed to clients (matches MskCluster, which persists volumeId/containerId).
Adds BrokerTest (round-trip) and asserts the describe response omits them.
This commit is contained in:
1 parent
b3c54c1854
commit
188854f2df
26 files changed
+1744
-6
No files matched your search
@@ -65,6 +65,7 @@ class EmulatorLifecycleTest {
|
||||
@Mock private DocDbContainerManager docDbContainerManager;
|
||||
@Mock private NeptuneContainerManager neptuneContainerManager;
|
||||
@Mock private NeptuneProxyManager neptuneProxyManager;
|
||||
@Mock private io.github.hectorvent.floci.services.amazonmq.container.RabbitMqManager rabbitMqManager;
|
||||
@Mock private RdsService rdsService;
|
||||
@Mock private InitializationHooksRunner initializationHooksRunner;
|
||||
@Mock private SqsEventSourcePoller sqsPoller;
|
||||
@@ -92,7 +93,8 @@ class EmulatorLifecycleTest {
|
||||
elastiCacheContainerManager, elastiCacheMemcachedContainerManager,
|
||||
elastiCacheProxyManager, rdsContainerManager, rdsProxyManager,
|
||||
memoryDbContainerManager, memoryDbProxyManager,
|
||||
docDbContainerManager, neptuneContainerManager, neptuneProxyManager, rdsService,
|
||||
docDbContainerManager, neptuneContainerManager, neptuneProxyManager,
|
||||
rabbitMqManager, rdsService,
|
||||
initializationHooksRunner, sqsPoller, kinesisPoller, dynamodbStreamsPoller,
|
||||
pipesService, ec2MetadataServer, ecrRegistryManager, flociUiManager, initLifecycleState);
|
||||
}
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq;
|
||||
|
||||
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.nullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@QuarkusTest
|
||||
class AmazonMqControllerIntegrationTest {
|
||||
|
||||
private String createRabbitBroker(String name) {
|
||||
return given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{"brokerName": "%s", "engineType": "RABBITMQ",
|
||||
"deploymentMode": "SINGLE_INSTANCE", "hostInstanceType": "mq.t3.micro",
|
||||
"publiclyAccessible": false,
|
||||
"users": [{"username": "admin", "password": "AdminPass123", "consoleAccess": true}]}
|
||||
""".formatted(name))
|
||||
.when()
|
||||
.post("/v1/brokers")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("brokerId");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createThenDescribeBroker() {
|
||||
String brokerId = createRabbitBroker("it-describe");
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/v1/brokers/{id}", brokerId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("brokerName", equalTo("it-describe"))
|
||||
.body("engineType", equalTo("RABBITMQ"))
|
||||
.body("brokerState", equalTo("RUNNING"))
|
||||
.body("brokerInstances[0].endpoints[0]", startsWith("amqp://"))
|
||||
// internal bookkeeping is persisted but must never leak into the API
|
||||
.body("containerId", nullValue())
|
||||
.body("accountId", nullValue())
|
||||
.body("volumeId", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listBrokersIncludesCreated() {
|
||||
createRabbitBroker("it-list");
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/v1/brokers")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("brokerSummaries.brokerName", hasItem("it-list"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void userApiRejectedForRabbitMq() {
|
||||
// The standalone User API applies only to ActiveMQ; AWS rejects it for
|
||||
// RabbitMQ brokers. Users are managed through the RabbitMQ web console.
|
||||
String brokerId = createRabbitBroker("it-users");
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{"password": "AnotherPass99", "consoleAccess": false}
|
||||
""")
|
||||
.when()
|
||||
.post("/v1/brokers/{id}/users/alice", brokerId)
|
||||
.then()
|
||||
.statusCode(400);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/v1/brokers/{id}/users", brokerId)
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsBrokerWithoutUser() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{"brokerName": "it-nouser", "engineType": "RABBITMQ",
|
||||
"deploymentMode": "SINGLE_INSTANCE", "hostInstanceType": "mq.t3.micro",
|
||||
"publiclyAccessible": false}
|
||||
""")
|
||||
.when()
|
||||
.post("/v1/brokers")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsActiveMqEngine() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{"brokerName": "it-activemq", "engineType": "ACTIVEMQ",
|
||||
"deploymentMode": "SINGLE_INSTANCE", "hostInstanceType": "mq.t3.micro",
|
||||
"publiclyAccessible": false}
|
||||
""")
|
||||
.when()
|
||||
.post("/v1/brokers")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq;
|
||||
|
||||
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.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.amazonmq.container.RabbitMqManager;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.Broker;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.BrokerState;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.MqUser;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class AmazonMqServiceTest {
|
||||
|
||||
private AmazonMqService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
|
||||
.thenReturn(new InMemoryStorage<>());
|
||||
|
||||
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
|
||||
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
|
||||
var mqConfig = Mockito.mock(EmulatorConfig.AmazonMqServiceConfig.class);
|
||||
when(config.services()).thenReturn(servicesConfig);
|
||||
when(servicesConfig.amazonmq()).thenReturn(mqConfig);
|
||||
when(mqConfig.mock()).thenReturn(true);
|
||||
when(config.defaultRegion()).thenReturn("us-east-1");
|
||||
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
RabbitMqManager rabbitMqManager = Mockito.mock(RabbitMqManager.class);
|
||||
service = new AmazonMqService(storageFactory, config, regionResolver, rabbitMqManager);
|
||||
}
|
||||
|
||||
private CreateBrokerParams rabbitParams(String name) {
|
||||
return new CreateBrokerParams(name, "RABBITMQ", null, "SINGLE_INSTANCE",
|
||||
"mq.t3.micro", false, false,
|
||||
List.of(new MqUser("admin", "AdminPass123", true, null)), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBrokerComesUpRunningWithEndpoints() {
|
||||
Broker broker = service.createBroker(rabbitParams("orders"));
|
||||
|
||||
assertEquals("orders", broker.getBrokerName());
|
||||
assertEquals("RABBITMQ", broker.getEngineType());
|
||||
assertEquals(BrokerState.RUNNING, broker.getBrokerState());
|
||||
assertTrue(broker.getBrokerId().startsWith("b-"));
|
||||
assertTrue(broker.getBrokerArn().contains(":mq:"));
|
||||
assertTrue(broker.getBrokerArn().contains("orders"));
|
||||
assertFalse(broker.getBrokerInstances().isEmpty());
|
||||
assertFalse(broker.getBrokerInstances().get(0).getEndpoints().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBrokerDefaultsEngineVersionWhenAbsent() {
|
||||
Broker broker = service.createBroker(rabbitParams("orders"));
|
||||
assertEquals("3.13", broker.getEngineVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBrokerRejectsNonRabbitEngine() {
|
||||
CreateBrokerParams activeMq = new CreateBrokerParams("legacy", "ACTIVEMQ", null,
|
||||
"SINGLE_INSTANCE", "mq.t3.micro", false, false, null, null);
|
||||
assertThrows(AwsException.class, () -> service.createBroker(activeMq));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBrokerRejectsNonSingleInstanceDeployment() {
|
||||
CreateBrokerParams cluster = new CreateBrokerParams("ha", "RABBITMQ", null,
|
||||
"CLUSTER_MULTI_AZ", "mq.t3.micro", false, false, null, null);
|
||||
assertThrows(AwsException.class, () -> service.createBroker(cluster));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBrokerRejectsDuplicateName() {
|
||||
service.createBroker(rabbitParams("orders"));
|
||||
assertThrows(AwsException.class, () -> service.createBroker(rabbitParams("orders")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeBrokerThrowsWhenMissing() {
|
||||
assertThrows(AwsException.class, () -> service.describeBroker("b-does-not-exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteBrokerRemovesIt() {
|
||||
Broker broker = service.createBroker(rabbitParams("orders"));
|
||||
service.deleteBroker(broker.getBrokerId());
|
||||
assertTrue(service.listBrokers().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void userApiRejectedForRabbitMq() {
|
||||
// The standalone User API applies only to ActiveMQ; AWS rejects it for
|
||||
// RabbitMQ brokers, and every broker we host is RabbitMQ.
|
||||
Broker broker = service.createBroker(rabbitParams("orders"));
|
||||
String id = broker.getBrokerId();
|
||||
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.createUser(id, new MqUser("alice", "AnotherPass99", false, null)));
|
||||
assertThrows(AwsException.class, () -> service.listUsers(id));
|
||||
assertThrows(AwsException.class, () -> service.describeUser(id, "alice"));
|
||||
assertThrows(AwsException.class, () -> service.deleteUser(id, "alice"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBrokerSeedsAdminUser() {
|
||||
Broker broker = service.createBroker(rabbitParams("orders"));
|
||||
assertEquals(1, broker.getUsers().size());
|
||||
assertEquals("admin", broker.getUsers().get(0).getUsername());
|
||||
assertEquals("AdminPass123", broker.getUsers().get(0).getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBrokerRequiresExactlyOneUser() {
|
||||
CreateBrokerParams noUsers = new CreateBrokerParams("orders", "RABBITMQ", null,
|
||||
"SINGLE_INSTANCE", "mq.t3.micro", false, false, null, null);
|
||||
assertThrows(AwsException.class, () -> service.createBroker(noUsers));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBrokerRejectsWeakPassword() {
|
||||
CreateBrokerParams weak = new CreateBrokerParams("orders", "RABBITMQ", null,
|
||||
"SINGLE_INSTANCE", "mq.t3.micro", false, false,
|
||||
List.of(new MqUser("admin", "short", true, null)), null);
|
||||
assertThrows(AwsException.class, () -> service.createBroker(weak));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBrokerMarksFailedWhenProvisioningThrows() {
|
||||
AmazonMqService realModeService = realModeServiceWithFailingManager();
|
||||
|
||||
assertThrows(AwsException.class,
|
||||
() -> realModeService.createBroker(rabbitParams("orders")));
|
||||
|
||||
// The failed broker is persisted as CREATION_FAILED, not left dangling.
|
||||
List<Broker> brokers = realModeService.listBrokers();
|
||||
assertEquals(1, brokers.size());
|
||||
assertEquals(BrokerState.CREATION_FAILED, brokers.get(0).getBrokerState());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rebootRunningBrokerStaysRunning() {
|
||||
Broker broker = service.createBroker(rabbitParams("orders"));
|
||||
Broker rebooted = service.rebootBroker(broker.getBrokerId());
|
||||
assertEquals(BrokerState.RUNNING, rebooted.getBrokerState());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rebootRejectsNonRunningBroker() {
|
||||
// A failed-provisioning broker is CREATION_FAILED; AWS allows RebootBroker
|
||||
// only on a RUNNING broker, so rebooting it must throw rather than promote
|
||||
// it (with no backing container) to RUNNING.
|
||||
AmazonMqService realModeService = realModeServiceWithFailingManager();
|
||||
assertThrows(AwsException.class,
|
||||
() -> realModeService.createBroker(rabbitParams("orders")));
|
||||
Broker failed = realModeService.listBrokers().get(0);
|
||||
assertEquals(BrokerState.CREATION_FAILED, failed.getBrokerState());
|
||||
|
||||
assertThrows(AwsException.class, () -> realModeService.rebootBroker(failed.getBrokerId()));
|
||||
}
|
||||
|
||||
private AmazonMqService realModeServiceWithFailingManager() {
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
|
||||
.thenReturn(new InMemoryStorage<>());
|
||||
|
||||
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
|
||||
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
|
||||
var mqConfig = Mockito.mock(EmulatorConfig.AmazonMqServiceConfig.class);
|
||||
when(config.services()).thenReturn(servicesConfig);
|
||||
when(servicesConfig.amazonmq()).thenReturn(mqConfig);
|
||||
when(mqConfig.mock()).thenReturn(false);
|
||||
when(config.defaultRegion()).thenReturn("us-east-1");
|
||||
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
RabbitMqManager failingManager = Mockito.mock(RabbitMqManager.class);
|
||||
Mockito.doThrow(new RuntimeException("docker unavailable"))
|
||||
.when(failingManager).startContainer(Mockito.any());
|
||||
return new AmazonMqService(storageFactory, config, regionResolver, failingManager);
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq.container;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLogStreamer;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.Broker;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
class RabbitMqManagerTest {
|
||||
|
||||
private ContainerLifecycleManager lifecycleManager;
|
||||
private RabbitMqManager manager;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
lifecycleManager = Mockito.mock(ContainerLifecycleManager.class);
|
||||
manager = new RabbitMqManager(
|
||||
Mockito.mock(ContainerBuilder.class),
|
||||
lifecycleManager,
|
||||
Mockito.mock(ContainerLogStreamer.class),
|
||||
Mockito.mock(ContainerDetector.class),
|
||||
Mockito.mock(EmulatorConfig.class),
|
||||
Mockito.mock(RegionResolver.class));
|
||||
}
|
||||
|
||||
private Broker broker(String brokerId) {
|
||||
return new Broker(brokerId, "arn", "name", "RABBITMQ", "3.13",
|
||||
"SINGLE_INSTANCE", "mq.t3.micro");
|
||||
}
|
||||
|
||||
@Test
|
||||
void stopContainerUsesContainerIdWhenPresent() {
|
||||
Broker broker = broker("b-1");
|
||||
broker.setContainerId("container-abc");
|
||||
|
||||
manager.stopContainer(broker);
|
||||
|
||||
verify(lifecycleManager).stopAndRemove(Mockito.eq("container-abc"), Mockito.any());
|
||||
verifyNoMoreInteractions(lifecycleManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
void stopContainerFallsBackToDeterministicNameWhenIdMissing() {
|
||||
// After an emulator restart containerId is null (not persisted); teardown
|
||||
// must still remove the container by its deterministic name.
|
||||
Broker broker = broker("b-2");
|
||||
|
||||
manager.stopContainer(broker);
|
||||
|
||||
verify(lifecycleManager).removeIfExists("floci-amazonmq-b-2");
|
||||
verifyNoMoreInteractions(lifecycleManager);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class BrokerTest {
|
||||
|
||||
/**
|
||||
* containerId / accountId / volumeId are internal bookkeeping but must survive a
|
||||
* serialize -> deserialize round-trip so the broker stays manageable after an
|
||||
* emulator restart (volume cleanup, container teardown, account-aware routing).
|
||||
* They are kept out of the API by the controller's explicit DescribeBroker
|
||||
* response, not by dropping them from storage.
|
||||
*/
|
||||
@Test
|
||||
void internalFieldsPersistAcrossSerialization() throws Exception {
|
||||
ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
|
||||
Broker broker = new Broker("b-1", "arn:aws:mq:us-east-1:000000000000:broker:n:b-1",
|
||||
"n", "RABBITMQ", "3.13", "SINGLE_INSTANCE", "mq.t3.micro");
|
||||
broker.setContainerId("container-xyz");
|
||||
broker.setAccountId("000000000000");
|
||||
broker.setVolumeId("a1b2c3");
|
||||
|
||||
Broker roundTripped = mapper.readValue(mapper.writeValueAsString(broker), Broker.class);
|
||||
|
||||
assertEquals("container-xyz", roundTripped.getContainerId());
|
||||
assertEquals("000000000000", roundTripped.getAccountId());
|
||||
assertEquals("a1b2c3", roundTripped.getVolumeId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class MqUserTest {
|
||||
|
||||
/**
|
||||
* The admin password is a secret: it must never be written to JSON (neither the
|
||||
* API response nor StorageBackend's amazonmq-brokers.json). A serialize ->
|
||||
* deserialize round-trip therefore drops it, by design — persisting it would
|
||||
* store the credential in cleartext.
|
||||
*/
|
||||
@Test
|
||||
void passwordIsNeverSerialized() throws Exception {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
MqUser user = new MqUser("admin", "AdminPass123", true, List.of("admin"));
|
||||
|
||||
String json = mapper.writeValueAsString(user);
|
||||
assertFalse(json.contains("AdminPass123"), "password value must not be serialized");
|
||||
assertFalse(json.toLowerCase().contains("password"), "password key must not be serialized");
|
||||
|
||||
MqUser roundTripped = mapper.readValue(json, MqUser.class);
|
||||
assertNull(roundTripped.getPassword(), "password is in-memory only; not restored from JSON");
|
||||
assertEquals("admin", roundTripped.getUsername());
|
||||
assertTrue(roundTripped.isConsoleAccess());
|
||||
assertEquals(List.of("admin"), roundTripped.getGroups());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user