mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(secretsmanager): publish secret write events through CloudTrail (#6623)
This commit is contained in:
1 parent
fb1d2d1fdb
commit
57c4a20dde
14 files changed
+1278
-16
No files matched your search
+128
@@ -0,0 +1,128 @@
|
||||
package io.github.hectorvent.floci.services.cloudtrail;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.cloudtrail.model.AdvancedEventSelector;
|
||||
import io.github.hectorvent.floci.services.cloudtrail.model.AdvancedFieldSelector;
|
||||
import io.github.hectorvent.floci.services.cloudtrail.model.EventSelector;
|
||||
import io.github.hectorvent.floci.services.iam.IamService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class CloudTrailManagementEventTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT = "661100000002";
|
||||
private static final String SOURCE = "secretsmanager.amazonaws.com";
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
private CloudTrailService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
StorageFactory factory = mock(StorageFactory.class);
|
||||
when(factory.create(anyString(), anyString(), any())).thenReturn(AccountAwareStorageBackend.inMemory(ACCOUNT));
|
||||
service = new CloudTrailService(factory, new RegionResolver(REGION, ACCOUNT), mock(IamService.class), MAPPER);
|
||||
}
|
||||
|
||||
private void trail(boolean multiRegion) {
|
||||
service.createTrail(REGION, "management-trail", "example-audit-logs", null, null,
|
||||
false, multiRegion, false, false);
|
||||
}
|
||||
|
||||
private CloudTrailService.ManagementEventInput event(String region) {
|
||||
return new CloudTrailService.ManagementEventInput(SOURCE, "PutSecretValue", region, "test",
|
||||
MAPPER.createObjectNode().put("secretId", "example"),
|
||||
MAPPER.createObjectNode().put("arn", "arn:aws:secretsmanager:" + region + ":" + ACCOUNT + ":secret:example"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void loggingIsRequiredAndTheDefaultSelectorIncludesManagementWrites() {
|
||||
assertTrue(service.emitManagementEvent(event(REGION)).isEmpty());
|
||||
trail(false);
|
||||
assertTrue(service.emitManagementEvent(event(REGION)).isEmpty());
|
||||
service.startLogging(REGION, "management-trail");
|
||||
ObjectNode record = service.emitManagementEvent(event(REGION)).orElseThrow();
|
||||
assertEquals("Management", record.path("eventCategory").asText());
|
||||
assertEquals("AwsApiCall", record.path("eventType").asText());
|
||||
assertEquals(ACCOUNT, record.path("recipientAccountId").asText());
|
||||
assertTrue(record.path("managementEvent").asBoolean());
|
||||
assertFalse(record.path("readOnly").asBoolean());
|
||||
assertEquals(1, service.pendingRecordCount(new CloudTrailService.TrailKey(REGION, "management-trail", REGION)));
|
||||
service.stopLogging(REGION, "management-trail");
|
||||
assertTrue(service.emitManagementEvent(event(REGION)).isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"All,true,true", "WriteOnly,true,true", "ReadOnly,true,false", "All,false,false"})
|
||||
void basicSelectorsRespectManagementAndWriteFilters(String mode, boolean management, boolean expected) {
|
||||
trail(false);
|
||||
service.startLogging(REGION, "management-trail");
|
||||
service.putEventSelectors(REGION, "management-trail",
|
||||
List.of(new EventSelector(mode, management, List.of(), List.of())));
|
||||
assertEquals(expected, service.emitManagementEvent(event(REGION)).isPresent());
|
||||
}
|
||||
|
||||
private static AdvancedFieldSelector equalsField(String field, String value) {
|
||||
return new AdvancedFieldSelector(field, List.of(value), null, null, null, null, null);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"eventCategory,Management,true", "eventCategory,Data,false", "eventSource,secretsmanager.amazonaws.com,true",
|
||||
"eventSource,kms.amazonaws.com,false", "eventName,PutSecretValue,true", "eventName,UpdateSecret,false",
|
||||
"readOnly,false,true", "readOnly,true,false", "eventType,AwsApiCall,true", "unknown,anything,false"})
|
||||
void advancedSelectorsEvaluateManagementFields(String field, String value, boolean expected) {
|
||||
trail(false);
|
||||
service.startLogging(REGION, "management-trail");
|
||||
service.putAdvancedEventSelectors(REGION, "management-trail", List.of(new AdvancedEventSelector("management",
|
||||
List.of(equalsField("eventCategory", "Management"), equalsField(field, value)))));
|
||||
assertEquals(expected, service.emitManagementEvent(event(REGION)).isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void advancedExclusionsAndSourceExclusionsSuppressEvents() {
|
||||
trail(false);
|
||||
service.startLogging(REGION, "management-trail");
|
||||
service.putEventSelectors(REGION, "management-trail", List.of(new EventSelector("All", true, List.of(), List.of(SOURCE))));
|
||||
assertTrue(service.emitManagementEvent(event(REGION)).isEmpty());
|
||||
service.putAdvancedEventSelectors(REGION, "management-trail", List.of(new AdvancedEventSelector("excluded",
|
||||
List.of(equalsField("eventCategory", "Management"), new AdvancedFieldSelector("eventName", null,
|
||||
List.of("PutSecretValue"), null, null, null, null)))));
|
||||
assertTrue(service.emitManagementEvent(event(REGION)).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void multiRegionTrailsStayWithinTheirPartition() {
|
||||
trail(false);
|
||||
service.startLogging(REGION, "management-trail");
|
||||
assertTrue(service.emitManagementEvent(event("eu-west-1")).isEmpty());
|
||||
service.updateTrail(REGION, "management-trail", null, null, null, null, true, null, null);
|
||||
assertTrue(service.emitManagementEvent(event("eu-west-1")).isPresent());
|
||||
assertTrue(service.emitManagementEvent(event("cn-north-1")).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipleTrailsRecordTheSameEventIdAndKeepIndependentCopies() {
|
||||
trail(false);
|
||||
service.createTrail(REGION, "another-trail", "example-audit-logs", null, null, false, false, false, false);
|
||||
service.startLogging(REGION, "management-trail");
|
||||
service.startLogging(REGION, "another-trail");
|
||||
ObjectNode returned = service.emitManagementEvent(event(REGION)).orElseThrow();
|
||||
String id = returned.path("eventID").asText();
|
||||
returned.put("eventName", "changed-by-caller");
|
||||
for (String name : List.of("management-trail", "another-trail")) {
|
||||
ObjectNode queued = service.drainPendingRecords(new CloudTrailService.TrailKey(REGION, name, REGION)).getFirst();
|
||||
assertEquals(id, queued.path("eventID").asText());
|
||||
assertEquals("PutSecretValue", queued.path("eventName").asText());
|
||||
}
|
||||
}
|
||||
}
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
package io.github.hectorvent.floci.services.secretsmanager;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AccountResolver;
|
||||
import io.github.hectorvent.floci.core.common.ContainerTeardown;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.lifecycle.EmulatorInfoController;
|
||||
import io.github.hectorvent.floci.services.cloudtrail.CloudTrailService;
|
||||
import io.github.hectorvent.floci.services.eventbridge.EventBridgeService;
|
||||
import jakarta.enterprise.inject.Instance;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class SecretsManagerEventPublisherResetTest {
|
||||
private static final String ACCOUNT = "661100000003";
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ARN = "arn:aws:secretsmanager:us-east-1:661100000003:secret:example";
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private final CloudTrailService trails = mock(CloudTrailService.class);
|
||||
private final EventBridgeService events = mock(EventBridgeService.class);
|
||||
private final StorageFactory storage = mock(StorageFactory.class);
|
||||
private final Deque<Runnable> queued = new ArrayDeque<>();
|
||||
private SecretsManagerEventPublisher publisher;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
publisher = new SecretsManagerEventPublisher(trails, events, new AccountResolver(ACCOUNT), mapper, queued::addLast);
|
||||
when(trails.emitManagementEvent(any())).thenAnswer(call -> {
|
||||
CloudTrailService.ManagementEventInput input = call.getArgument(0);
|
||||
return Optional.of(mapper.createObjectNode().put("recipientAccountId", ACCOUNT).put("awsRegion", REGION)
|
||||
.put("eventID", input.requestParameters().path("clientRequestToken").asText()));
|
||||
});
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void stop() {
|
||||
publisher.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
void queuedEventsCannotReachRulesCreatedAfterReset() {
|
||||
write("before-reset");
|
||||
Runnable oldDelivery = queued.removeFirst();
|
||||
|
||||
controller().reset();
|
||||
oldDelivery.run();
|
||||
|
||||
verifyNoInteractions(events);
|
||||
write("after-reset");
|
||||
queued.removeFirst().run();
|
||||
verify(events).publishServiceEvent(eq("aws.secretsmanager"), eq("AWS API Call via CloudTrail"),
|
||||
contains("after-reset"), eq(ARN), eq(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetDrainsActiveDeliveriesBeforeWipeDiscardsQueuedEventsAndReusesWorkers() throws Exception {
|
||||
publisher = new SecretsManagerEventPublisher(trails, events, new AccountResolver(ACCOUNT), mapper);
|
||||
CountDownLatch active = new CountDownLatch(2);
|
||||
CountDownLatch release = new CountDownLatch(1);
|
||||
CountDownLatch fresh = new CountDownLatch(1);
|
||||
List<String> stored = new CopyOnWriteArrayList<>();
|
||||
doAnswer(call -> {
|
||||
String id = mapper.readTree((String) call.getArgument(2)).path("eventID").asText();
|
||||
if (id.startsWith("active-")) {
|
||||
active.countDown();
|
||||
assertTrue(release.await(5, TimeUnit.SECONDS), "blocked targets must be released by the test");
|
||||
}
|
||||
stored.add(id);
|
||||
if ("after-reset".equals(id)) {
|
||||
fresh.countDown();
|
||||
}
|
||||
return null;
|
||||
}).when(events).publishServiceEvent(anyString(), anyString(), anyString(), anyString(), anyString());
|
||||
doAnswer(call -> { stored.clear(); return null; }).when(storage).clearAll();
|
||||
ExecutorService resets = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
write("active-first");
|
||||
write("active-second");
|
||||
assertTrue(active.await(5, TimeUnit.SECONDS));
|
||||
write("queued-before-reset");
|
||||
|
||||
Future<?> reset = resets.submit(() -> controller().reset());
|
||||
assertThrows(TimeoutException.class, () -> reset.get(200, TimeUnit.MILLISECONDS),
|
||||
"reset must wait for active target deliveries before wiping storage");
|
||||
verify(storage, never()).clearAll();
|
||||
release.countDown();
|
||||
reset.get(5, TimeUnit.SECONDS);
|
||||
assertTrue(stored.isEmpty(), "active deliveries must finish before their state is wiped");
|
||||
|
||||
write("after-reset");
|
||||
assertTrue(fresh.await(5, TimeUnit.SECONDS), "the same publisher must deliver new events after reset");
|
||||
assertEquals(List.of("after-reset"), stored);
|
||||
verify(events, times(3)).publishServiceEvent(anyString(), anyString(), anyString(), anyString(), anyString());
|
||||
} finally {
|
||||
release.countDown();
|
||||
resets.shutdownNow();
|
||||
assertTrue(resets.awaitTermination(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void notificationsAreDroppedDuringWipeAndResumeAfterward() throws Exception {
|
||||
CountDownLatch wiping = new CountDownLatch(1);
|
||||
CountDownLatch finishWipe = new CountDownLatch(1);
|
||||
doAnswer(call -> {
|
||||
wiping.countDown();
|
||||
assertTrue(finishWipe.await(5, TimeUnit.SECONDS));
|
||||
return null;
|
||||
}).when(storage).clearAll();
|
||||
ExecutorService resets = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
Future<?> reset = resets.submit(() -> controller().reset());
|
||||
assertTrue(wiping.await(5, TimeUnit.SECONDS));
|
||||
write("during-reset");
|
||||
assertTrue(queued.isEmpty(), "notifications must not enter the queue during the storage wipe");
|
||||
verifyNoInteractions(trails, events);
|
||||
finishWipe.countDown();
|
||||
reset.get(5, TimeUnit.SECONDS);
|
||||
write("after-reset");
|
||||
queued.removeFirst().run();
|
||||
verify(events).publishServiceEvent(anyString(), anyString(), contains("after-reset"), eq(ARN), eq(REGION));
|
||||
} finally {
|
||||
finishWipe.countDown();
|
||||
resets.shutdownNow();
|
||||
assertTrue(resets.awaitTermination(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedStorageWipeStillDiscardsOldEventsAndResumesNotifications() {
|
||||
write("before-reset");
|
||||
Runnable oldDelivery = queued.removeFirst();
|
||||
doThrow(new IllegalStateException("example storage failure")).when(storage).clearAll();
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> controller().reset());
|
||||
oldDelivery.run();
|
||||
verifyNoInteractions(events);
|
||||
write("after-failed-reset");
|
||||
queued.removeFirst().run();
|
||||
verify(events).publishServiceEvent(anyString(), anyString(), contains("after-failed-reset"), eq(ARN), eq(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void interruptedDrainRefusesTheWipeAndRestoresPublication() throws Exception {
|
||||
publisher = new SecretsManagerEventPublisher(trails, events, new AccountResolver(ACCOUNT), mapper);
|
||||
CountDownLatch active = new CountDownLatch(1);
|
||||
CountDownLatch release = new CountDownLatch(1);
|
||||
CountDownLatch fresh = new CountDownLatch(1);
|
||||
doAnswer(call -> {
|
||||
if (((String) call.getArgument(2)).contains("active-before-reset")) {
|
||||
active.countDown();
|
||||
assertTrue(release.await(5, TimeUnit.SECONDS));
|
||||
} else {
|
||||
fresh.countDown();
|
||||
}
|
||||
return null;
|
||||
}).when(events).publishServiceEvent(anyString(), anyString(), anyString(), anyString(), anyString());
|
||||
try {
|
||||
write("active-before-reset");
|
||||
assertTrue(active.await(5, TimeUnit.SECONDS));
|
||||
Thread.currentThread().interrupt();
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class, () -> controller().reset());
|
||||
assertInstanceOf(InterruptedException.class, failure.getCause());
|
||||
assertTrue(Thread.currentThread().isInterrupted());
|
||||
verify(storage, never()).clearAll();
|
||||
} finally {
|
||||
Thread.interrupted();
|
||||
release.countDown();
|
||||
}
|
||||
write("after-failed-reset");
|
||||
assertTrue(fresh.await(5, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetCannotRestartAShutDownPublisher() {
|
||||
write("before-shutdown");
|
||||
Runnable oldDelivery = queued.removeFirst();
|
||||
publisher.shutdown();
|
||||
controller().reset();
|
||||
oldDelivery.run();
|
||||
write("after-shutdown");
|
||||
assertTrue(queued.isEmpty());
|
||||
verifyNoInteractions(events);
|
||||
}
|
||||
|
||||
private void write(String id) {
|
||||
ObjectNode request = mapper.createObjectNode().put("SecretId", ARN).put("ClientRequestToken", id);
|
||||
publisher.secretWritten("PutSecretValue", request, mapper.createObjectNode().put("ARN", ARN), REGION, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private EmulatorInfoController controller() {
|
||||
Instance<Resettable> services = mock(Instance.class);
|
||||
when(services.iterator()).thenAnswer(call -> Resettable.class.isInstance(publisher)
|
||||
? List.of(Resettable.class.cast(publisher)).iterator() : List.<Resettable>of().iterator());
|
||||
Instance<ContainerTeardown> teardowns = mock(Instance.class);
|
||||
when(teardowns.iterator()).thenAnswer(call -> List.<ContainerTeardown>of().iterator());
|
||||
return new EmulatorInfoController(null, null, storage, services, teardowns, null, null, null);
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
package io.github.hectorvent.floci.services.secretsmanager;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AccountResolver;
|
||||
import io.github.hectorvent.floci.services.cloudtrail.CloudTrailService;
|
||||
import io.github.hectorvent.floci.services.eventbridge.EventBridgeService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class SecretsManagerEventPublisherTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT = "661100000003";
|
||||
private static final String ARN = "arn:aws:secretsmanager:us-east-1:661100000003:secret:example";
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private CloudTrailService trails;
|
||||
private EventBridgeService events;
|
||||
private SecretsManagerEventPublisher publisher;
|
||||
private Deque<Runnable> deliveries;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
trails = mock(CloudTrailService.class);
|
||||
events = mock(EventBridgeService.class);
|
||||
AccountResolver accounts = mock(AccountResolver.class);
|
||||
when(accounts.extractAccessKeyId("signed-request")).thenReturn("example-access-key");
|
||||
deliveries = new ArrayDeque<>();
|
||||
publisher = new SecretsManagerEventPublisher(trails, events, accounts, mapper, deliveries::addLast);
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyAllowlistedMetadataReachesCloudTrailAndEventBridge() throws Exception {
|
||||
ObjectNode request = (ObjectNode) mapper.readTree("""
|
||||
{"SecretId":"example","ClientRequestToken":"example-token","VersionStages":["AWSCURRENT"],
|
||||
"SecretString":"sensitive-string","SecretBinary":"sensitive-binary",
|
||||
"Description":"sensitive-description","unknown":{"password":"sensitive-password"}}
|
||||
""");
|
||||
ObjectNode response = mapper.createObjectNode().put("ARN", ARN).put("Name", "example").put("VersionId", "version");
|
||||
ObjectNode record = record();
|
||||
when(trails.emitManagementEvent(any())).thenReturn(Optional.of(record));
|
||||
|
||||
publisher.secretWritten("PutSecretValue", request, response, REGION, "signed-request");
|
||||
|
||||
ArgumentCaptor<CloudTrailService.ManagementEventInput> capture =
|
||||
ArgumentCaptor.forClass(CloudTrailService.ManagementEventInput.class);
|
||||
verify(trails).emitManagementEvent(capture.capture());
|
||||
CloudTrailService.ManagementEventInput input = capture.getValue();
|
||||
assertEquals("secretsmanager.amazonaws.com", input.eventSource());
|
||||
assertEquals("example-access-key", input.accessKeyId());
|
||||
assertEquals("AWSCURRENT", input.requestParameters().path("versionStages").get(0).asText());
|
||||
assertEquals(3, input.requestParameters().size());
|
||||
assertEquals(ARN, input.responseElements().path("arn").asText());
|
||||
assertFalse(input.requestParameters().toString().contains("sensitive-"));
|
||||
verifyNoInteractions(events);
|
||||
assertEquals(1, deliveries.size());
|
||||
deliveries.removeFirst().run();
|
||||
verify(events).publishServiceEvent("aws.secretsmanager", "AWS API Call via CloudTrail",
|
||||
record.toString(), ARN, REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noMatchingLoggingTrailMeansNoEventBridgePublication() {
|
||||
when(trails.emitManagementEvent(any())).thenReturn(Optional.empty());
|
||||
publisher.secretWritten("UpdateSecret", mapper.createObjectNode(),
|
||||
mapper.createObjectNode().put("ARN", ARN), REGION, null);
|
||||
verifyNoInteractions(events);
|
||||
assertTrue(deliveries.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void notificationFailureDoesNotFailTheAlreadyCommittedWrite() {
|
||||
when(trails.emitManagementEvent(any())).thenThrow(new IllegalStateException("example failure"));
|
||||
assertDoesNotThrow(() -> publisher.secretWritten("PutSecretValue", mapper.createObjectNode(),
|
||||
mapper.createObjectNode().put("ARN", ARN), REGION, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void queuedDeliveryUsesSnapshotsInsteadOfMutableRequestObjects() {
|
||||
ObjectNode record = record();
|
||||
String detail = record.toString();
|
||||
ObjectNode response = mapper.createObjectNode().put("ARN", ARN);
|
||||
when(trails.emitManagementEvent(any())).thenReturn(Optional.of(record));
|
||||
publisher.secretWritten("PutSecretValue", mapper.createObjectNode(), response, REGION, null);
|
||||
record.removeAll();
|
||||
response.put("ARN", "changed-after-enqueue");
|
||||
deliveries.removeFirst().run();
|
||||
verify(events).publishServiceEvent("aws.secretsmanager", "AWS API Call via CloudTrail", detail, ARN, REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectedQueueDoesNotRunDeliveryInTheWriteRequestOrFailTheWrite() {
|
||||
when(trails.emitManagementEvent(any())).thenReturn(Optional.of(record()));
|
||||
publisher = new SecretsManagerEventPublisher(trails, events, new AccountResolver(ACCOUNT), mapper,
|
||||
task -> { throw new RejectedExecutionException("example full queue"); });
|
||||
assertDoesNotThrow(() -> publisher.secretWritten("PutSecretValue", mapper.createObjectNode(),
|
||||
mapper.createObjectNode().put("ARN", ARN), REGION, null));
|
||||
verifyNoInteractions(events);
|
||||
}
|
||||
|
||||
@Test
|
||||
void backgroundDeliveryFailureIsContained() {
|
||||
when(trails.emitManagementEvent(any())).thenReturn(Optional.of(record()));
|
||||
doThrow(new IllegalStateException("example delivery failure")).when(events)
|
||||
.publishServiceEvent(anyString(), anyString(), anyString(), anyString(), anyString());
|
||||
publisher.secretWritten("PutSecretValue", mapper.createObjectNode(),
|
||||
mapper.createObjectNode().put("ARN", ARN), REGION, null);
|
||||
assertDoesNotThrow(() -> deliveries.removeFirst().run());
|
||||
}
|
||||
|
||||
private ObjectNode record() {
|
||||
return mapper.createObjectNode().put("eventName", "PutSecretValue")
|
||||
.put("recipientAccountId", ACCOUNT).put("awsRegion", REGION);
|
||||
}
|
||||
}
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
package io.github.hectorvent.floci.services.secretsmanager;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.services.cloudtrail.CloudTrailService;
|
||||
import io.github.hectorvent.floci.services.cloudtrail.model.EventSelector;
|
||||
import io.github.hectorvent.floci.services.sqs.SqsService;
|
||||
import io.github.hectorvent.floci.services.sqs.model.Message;
|
||||
import io.github.hectorvent.floci.services.sqs.model.Queue;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
|
||||
import software.amazon.awssdk.services.eventbridge.model.ApiDestinationHttpMethod;
|
||||
import software.amazon.awssdk.services.eventbridge.model.ConnectionAuthorizationType;
|
||||
import software.amazon.awssdk.services.eventbridge.model.Target;
|
||||
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
|
||||
import software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@QuarkusTest
|
||||
class SecretsManagerEventsIntegrationTest {
|
||||
private static final String ACCOUNT = "661100000001";
|
||||
private static final String REGION = "eu-west-1";
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
@Inject
|
||||
CloudTrailService trails;
|
||||
|
||||
@Inject
|
||||
SqsService sqs;
|
||||
|
||||
private SecretsManagerClient secrets;
|
||||
private EventBridgeClient events;
|
||||
private String name;
|
||||
private String arn;
|
||||
private String queueUrl;
|
||||
|
||||
@BeforeEach
|
||||
void createFixture() {
|
||||
URI endpoint = URI.create("http://localhost:" + RestAssured.port);
|
||||
StaticCredentialsProvider credentials = StaticCredentialsProvider.create(AwsBasicCredentials.create(ACCOUNT, "test"));
|
||||
secrets = SecretsManagerClient.builder().endpointOverride(endpoint).region(Region.of(REGION))
|
||||
.httpClientBuilder(UrlConnectionHttpClient.builder()).credentialsProvider(credentials).build();
|
||||
events = EventBridgeClient.builder().endpointOverride(endpoint).region(Region.of(REGION))
|
||||
.httpClientBuilder(UrlConnectionHttpClient.builder()).credentialsProvider(credentials).build();
|
||||
name = "secret-events-" + UUID.randomUUID();
|
||||
arn = secrets.createSecret(r -> r.name(name).secretString("initial-example-value")).arn();
|
||||
String queueArn = RequestScopes.callAs(ACCOUNT, REGION, () -> {
|
||||
Queue queue = sqs.createQueue(name, Map.of(), REGION);
|
||||
queueUrl = queue.getQueueUrl();
|
||||
return sqs.getQueueAttributes(queueUrl, List.of("QueueArn"), REGION).get("QueueArn");
|
||||
});
|
||||
events.putRule(r -> r.name(name).eventPattern("{\"source\":[\"aws.secretsmanager\"],"
|
||||
+ "\"detail-type\":[\"AWS API Call via CloudTrail\"],"
|
||||
+ "\"detail\":{\"responseElements\":{\"arn\":[\"" + arn + "\"]}}}"));
|
||||
events.putTargets(r -> r.rule(name).targets(Target.builder().id("queue").arn(queueArn).build()));
|
||||
RequestScopes.runAs(ACCOUNT, REGION, () -> trails.createTrail(REGION, name, "example-audit-logs",
|
||||
null, null, false, false, false, false));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void deleteFixture() {
|
||||
try {
|
||||
events.removeTargets(r -> r.rule(name).ids("queue"));
|
||||
events.deleteRule(r -> r.name(name));
|
||||
secrets.deleteSecret(r -> r.secretId(arn).forceDeleteWithoutRecovery(true));
|
||||
RequestScopes.runAs(ACCOUNT, REGION, () -> {
|
||||
trails.deleteTrail(REGION, name);
|
||||
sqs.deleteQueue(queueUrl, REGION);
|
||||
});
|
||||
} finally {
|
||||
events.close();
|
||||
secrets.close();
|
||||
}
|
||||
}
|
||||
|
||||
private List<Message> receive(int waitSeconds) {
|
||||
return RequestScopes.callAs(ACCOUNT, REGION, () -> sqs.receiveMessage(queueUrl, 10, 30, waitSeconds, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sdkWritesReachTheDefaultBusWithoutInjectedEventsAndExcludeSecretValues() throws Exception {
|
||||
RequestScopes.runAs(ACCOUNT, REGION, () -> trails.startLogging(REGION, name));
|
||||
secrets.putSecretValue(r -> r.secretId(arn).secretString("sensitive-put-example"));
|
||||
secrets.updateSecret(r -> r.secretId(arn).secretString("sensitive-update-example"));
|
||||
List<Message> messages = new ArrayList<>();
|
||||
for (int attempt = 0; attempt < 5 && messages.size() < 2; attempt++) {
|
||||
messages.addAll(receive(1));
|
||||
}
|
||||
assertEquals(2, messages.size(), "both SDK writes must reach the rule through service-originated events");
|
||||
for (Message message : messages) {
|
||||
JsonNode event = MAPPER.readTree(message.getBody());
|
||||
assertEquals("aws.secretsmanager", event.path("source").asText());
|
||||
assertEquals("AWS API Call via CloudTrail", event.path("detail-type").asText());
|
||||
assertEquals(ACCOUNT, event.path("account").asText());
|
||||
assertEquals(REGION, event.path("region").asText());
|
||||
assertEquals(arn, event.path("detail").path("responseElements").path("arn").asText());
|
||||
assertFalse(message.getBody().contains("sensitive-"));
|
||||
assertFalse(message.getBody().contains("SecretString"));
|
||||
assertFalse(message.getBody().contains("secretString"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void metadataOnlyUpdatesPublishButReadsUnrelatedSecretsAndFailedWritesDoNot() throws Exception {
|
||||
RequestScopes.runAs(ACCOUNT, REGION, () -> trails.startLogging(REGION, name));
|
||||
String other = secrets.createSecret(r -> r.name(name + "-other").secretString("other-example")).arn();
|
||||
try {
|
||||
secrets.putSecretValue(r -> r.secretId(other).secretString("unrelated-example"));
|
||||
secrets.getSecretValue(r -> r.secretId(arn));
|
||||
secrets.describeSecret(r -> r.secretId(arn));
|
||||
assertThrows(ResourceNotFoundException.class,
|
||||
() -> secrets.putSecretValue(r -> r.secretId(name + "-missing").secretString("failed-example")));
|
||||
assertTrue(receive(0).isEmpty());
|
||||
secrets.updateSecret(r -> r.secretId(arn).description("metadata only"));
|
||||
List<Message> messages = receive(2);
|
||||
assertEquals(1, messages.size());
|
||||
JsonNode detail = MAPPER.readTree(messages.getFirst().getBody()).path("detail");
|
||||
assertEquals("UpdateSecret", detail.path("eventName").asText());
|
||||
assertFalse(detail.path("responseElements").has("versionId"));
|
||||
} finally {
|
||||
secrets.deleteSecret(r -> r.secretId(other).forceDeleteWithoutRecovery(true));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void slowHttpTargetsDoNotDelaySdkWriteResponsesAndKeepRequestScope() throws Exception {
|
||||
CountDownLatch arrived = new CountDownLatch(2);
|
||||
CountDownLatch release = new CountDownLatch(1);
|
||||
List<String> payloads = new CopyOnWriteArrayList<>();
|
||||
ExecutorService httpWorkers = Executors.newVirtualThreadPerTaskExecutor();
|
||||
ExecutorService callers = Executors.newVirtualThreadPerTaskExecutor();
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||
server.setExecutor(httpWorkers);
|
||||
server.createContext("/hook", exchange -> {
|
||||
try {
|
||||
payloads.add(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8));
|
||||
arrived.countDown();
|
||||
boolean released = release.await(10, TimeUnit.SECONDS);
|
||||
exchange.sendResponseHeaders(released ? 200 : 504, -1);
|
||||
} catch (InterruptedException expected) {
|
||||
// Test teardown interrupts any handler still waiting for release.
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
exchange.close();
|
||||
}
|
||||
});
|
||||
server.start();
|
||||
try {
|
||||
String connection = events.createConnection(r -> r.name(name)
|
||||
.authorizationType(ConnectionAuthorizationType.API_KEY)
|
||||
.authParameters(p -> p.apiKeyAuthParameters(k -> k.apiKeyName("example-key").apiKeyValue("example-value"))))
|
||||
.connectionArn();
|
||||
String destination = events.createApiDestination(r -> r.name(name).connectionArn(connection)
|
||||
.httpMethod(ApiDestinationHttpMethod.POST).invocationRateLimitPerSecond(100)
|
||||
.invocationEndpoint("http://127.0.0.1:" + server.getAddress().getPort() + "/hook"))
|
||||
.apiDestinationArn();
|
||||
events.putTargets(r -> r.rule(name).targets(Target.builder().id("blocked-http").arn(destination).build()));
|
||||
RequestScopes.runAs(ACCOUNT, REGION, () -> trails.startLogging(REGION, name));
|
||||
|
||||
Future<?> put = callers.submit(() -> secrets.putSecretValue(r -> r.secretId(arn)
|
||||
.secretString("sensitive-async-put")));
|
||||
Future<?> update = callers.submit(() -> secrets.updateSecret(r -> r.secretId(arn)
|
||||
.secretString("sensitive-async-update")));
|
||||
put.get(2, TimeUnit.SECONDS);
|
||||
update.get(2, TimeUnit.SECONDS);
|
||||
assertTrue(arrived.await(3, TimeUnit.SECONDS), "both target deliveries must run after the SDK writes return");
|
||||
assertEquals(1, release.getCount(), "HTTP targets are still waiting for a response");
|
||||
for (String payload : payloads) {
|
||||
JsonNode event = MAPPER.readTree(payload);
|
||||
assertEquals(ACCOUNT, event.path("account").asText());
|
||||
assertEquals(REGION, event.path("region").asText());
|
||||
assertEquals(arn, event.path("detail").path("responseElements").path("arn").asText());
|
||||
assertFalse(payload.contains("sensitive-"));
|
||||
}
|
||||
} finally {
|
||||
release.countDown();
|
||||
callers.shutdownNow();
|
||||
callers.awaitTermination(5, TimeUnit.SECONDS);
|
||||
server.stop(0);
|
||||
httpWorkers.shutdownNow();
|
||||
events.removeTargets(r -> r.rule(name).ids("blocked-http"));
|
||||
events.deleteApiDestination(r -> r.name(name));
|
||||
events.deleteConnection(r -> r.name(name));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void stoppedTrailsAndReadOnlySelectorsDoNotPublishWrites() {
|
||||
secrets.putSecretValue(r -> r.secretId(arn).secretString("not-logged"));
|
||||
assertTrue(receive(0).isEmpty());
|
||||
RequestScopes.runAs(ACCOUNT, REGION, () -> {
|
||||
trails.putEventSelectors(REGION, name, List.of(new EventSelector("ReadOnly", true, List.of(), List.of())));
|
||||
trails.startLogging(REGION, name);
|
||||
});
|
||||
secrets.updateSecret(r -> r.secretId(arn).description("metadata only"));
|
||||
assertTrue(receive(0).isEmpty());
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
package io.github.hectorvent.floci.services.secretsmanager;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.services.cloudtrail.CloudTrailService;
|
||||
import io.github.hectorvent.floci.services.sqs.SqsService;
|
||||
import io.github.hectorvent.floci.services.sqs.model.Message;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
|
||||
import software.amazon.awssdk.services.eventbridge.model.ApiDestinationHttpMethod;
|
||||
import software.amazon.awssdk.services.eventbridge.model.ConnectionAuthorizationType;
|
||||
import software.amazon.awssdk.services.eventbridge.model.Target;
|
||||
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@QuarkusTest
|
||||
class SecretsManagerEventsResetIntegrationTest {
|
||||
private static final String ACCOUNT = "661100000007";
|
||||
private static final String REGION = "eu-west-1";
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
private static final String PATTERN = "{\"source\":[\"aws.secretsmanager\"],"
|
||||
+ "\"detail-type\":[\"AWS API Call via CloudTrail\"]}";
|
||||
|
||||
@Inject
|
||||
CloudTrailService trails;
|
||||
|
||||
@Inject
|
||||
SqsService sqs;
|
||||
|
||||
@Test
|
||||
void actualResetDrainsBlockedTargetsDropsOldWritesAndDeliversNewSdkWrites() throws Exception {
|
||||
URI endpoint = URI.create("http://localhost:" + RestAssured.port);
|
||||
StaticCredentialsProvider credentials = StaticCredentialsProvider.create(AwsBasicCredentials.create(ACCOUNT, "test"));
|
||||
CountDownLatch arrived = new CountDownLatch(2);
|
||||
CountDownLatch release = new CountDownLatch(1);
|
||||
ExecutorService httpWorkers = Executors.newVirtualThreadPerTaskExecutor();
|
||||
ExecutorService resets = Executors.newSingleThreadExecutor();
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||
server.setExecutor(httpWorkers);
|
||||
server.createContext("/hook", exchange -> {
|
||||
try {
|
||||
exchange.getRequestBody().readAllBytes();
|
||||
arrived.countDown();
|
||||
boolean released = release.await(10, TimeUnit.SECONDS);
|
||||
exchange.sendResponseHeaders(released ? 200 : 504, -1);
|
||||
} catch (InterruptedException expected) {
|
||||
// Teardown releases or interrupts every blocked test target.
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
exchange.close();
|
||||
}
|
||||
});
|
||||
server.start();
|
||||
try (SecretsManagerClient secrets = SecretsManagerClient.builder().endpointOverride(endpoint)
|
||||
.region(Region.of(REGION)).httpClientBuilder(UrlConnectionHttpClient.builder())
|
||||
.credentialsProvider(credentials).build();
|
||||
EventBridgeClient events = EventBridgeClient.builder().endpointOverride(endpoint)
|
||||
.region(Region.of(REGION)).httpClientBuilder(UrlConnectionHttpClient.builder())
|
||||
.credentialsProvider(credentials).build()) {
|
||||
String name = "reset-events-" + UUID.randomUUID();
|
||||
String oldArn = secrets.createSecret(r -> r.name(name).secretString("old-example")).arn();
|
||||
String connection = events.createConnection(r -> r.name(name)
|
||||
.authorizationType(ConnectionAuthorizationType.API_KEY)
|
||||
.authParameters(p -> p.apiKeyAuthParameters(k -> k.apiKeyName("example-key").apiKeyValue("example-value"))))
|
||||
.connectionArn();
|
||||
String destination = events.createApiDestination(r -> r.name(name).connectionArn(connection)
|
||||
.httpMethod(ApiDestinationHttpMethod.POST).invocationRateLimitPerSecond(100)
|
||||
.invocationEndpoint("http://127.0.0.1:" + server.getAddress().getPort() + "/hook"))
|
||||
.apiDestinationArn();
|
||||
rule(events, name, destination);
|
||||
startTrail(name);
|
||||
secrets.putSecretValue(r -> r.secretId(oldArn).secretString("old-first"));
|
||||
secrets.updateSecret(r -> r.secretId(oldArn).secretString("old-second"));
|
||||
assertTrue(arrived.await(3, TimeUnit.SECONDS), "both publisher workers must be occupied");
|
||||
secrets.putSecretValue(r -> r.secretId(oldArn).secretString("queued-before-reset"));
|
||||
|
||||
Future<?> reset = resets.submit(() -> given().post("/_floci/state/reset").then().statusCode(200));
|
||||
assertThrows(TimeoutException.class, () -> reset.get(200, TimeUnit.MILLISECONDS),
|
||||
"reset must drain blocked target deliveries before clearing their state");
|
||||
release.countDown();
|
||||
reset.get(15, TimeUnit.SECONDS);
|
||||
|
||||
String freshArn = secrets.createSecret(r -> r.name(name).secretString("fresh-example")).arn();
|
||||
String queueUrl = RequestScopes.callAs(ACCOUNT, REGION,
|
||||
() -> sqs.createQueue(name, Map.of(), REGION).getQueueUrl());
|
||||
String queueArn = RequestScopes.callAs(ACCOUNT, REGION,
|
||||
() -> sqs.getQueueAttributes(queueUrl, List.of("QueueArn"), REGION).get("QueueArn"));
|
||||
rule(events, name, queueArn);
|
||||
startTrail(name);
|
||||
secrets.putSecretValue(r -> r.secretId(freshArn).secretString("fresh-write"));
|
||||
List<Message> messages = receive(queueUrl, 2);
|
||||
assertEquals(1, messages.size(), "new rules must receive only writes made after reset");
|
||||
JsonNode event = MAPPER.readTree(messages.getFirst().getBody());
|
||||
assertEquals(freshArn, event.path("detail").path("responseElements").path("arn").asText());
|
||||
assertEquals(ACCOUNT, event.path("account").asText());
|
||||
assertEquals(REGION, event.path("region").asText());
|
||||
assertTrue(receive(queueUrl, 1).isEmpty(),
|
||||
"queued events from deleted secrets must not reach the recreated rule");
|
||||
} finally {
|
||||
release.countDown();
|
||||
resets.shutdownNow();
|
||||
assertTrue(resets.awaitTermination(5, TimeUnit.SECONDS));
|
||||
server.stop(0);
|
||||
httpWorkers.shutdownNow();
|
||||
given().post("/_floci/state/reset").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
private void startTrail(String name) {
|
||||
RequestScopes.runAs(ACCOUNT, REGION, () -> {
|
||||
trails.createTrail(REGION, name, "example-reset-audit-logs", null, null, false, false, false, false);
|
||||
trails.startLogging(REGION, name);
|
||||
});
|
||||
}
|
||||
|
||||
private void rule(EventBridgeClient events, String name, String targetArn) {
|
||||
events.putRule(r -> r.name(name).eventPattern(PATTERN));
|
||||
events.putTargets(r -> r.rule(name).targets(Target.builder().id("target").arn(targetArn).build()));
|
||||
}
|
||||
|
||||
private List<Message> receive(String queueUrl, int waitSeconds) {
|
||||
return RequestScopes.callAs(ACCOUNT, REGION, () -> sqs.receiveMessage(queueUrl, 10, 30, waitSeconds, REGION));
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -31,7 +31,8 @@ class SecretsManagerJsonHandlerTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SecretsManagerService(new InMemoryStorage<>(), 30);
|
||||
handler = new SecretsManagerJsonHandler(service, MAPPER, mock(IamEnforcementFilter.class));
|
||||
handler = new SecretsManagerJsonHandler(service, MAPPER, mock(IamEnforcementFilter.class),
|
||||
mock(SecretsManagerEventPublisher.class));
|
||||
}
|
||||
|
||||
private String getRandomPassword(ObjectNode request) {
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ class SecretsManagerRotationLockTest {
|
||||
// is building DescribeSecret's VersionIdsToStages from the same map. Park the reader one
|
||||
// entry into that iteration, add the version, and let the reader continue.
|
||||
SecretsManagerJsonHandler handler = new SecretsManagerJsonHandler(service, new ObjectMapper(),
|
||||
mock(IamEnforcementFilter.class));
|
||||
mock(IamEnforcementFilter.class), mock(SecretsManagerEventPublisher.class));
|
||||
ParkingIterationVersions versions = new ParkingIterationVersions(secret.getVersions());
|
||||
secret.setVersions(versions);
|
||||
assertTrue(secret.getVersions() instanceof ConcurrentMap,
|
||||
|
||||
Reference in new issue
Block a user