mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(emr): scope Studio list markers to their account, Region and filters (#8740)
ListStudios used one constant namespace for its markers, and ListStudioSessionMappings its Studio and identity type joined with String.valueOf. A marker from another account or Region therefore resumed this one's listing at its cursor, and an absent filter could not be told apart from the text "null". Both now scope their markers as ListNotebookExecutions does (#8705): a JSON list of the operation, the account, the Region and each filter, so any other marker is refused with InvalidRequestException "Invalid Marker.". The JSON list moves from EmrNotebookExecutionService to EmrService.listingNamespace, which all three listings use.
This commit is contained in:
1 parent
76413ce74a
commit
6618ae3de6
5 files changed
+92
-21
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.emr;
|
||||
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
@@ -7,15 +8,19 @@ import io.floci.aws.services.ec2.model.SecurityGroup;
|
||||
import io.floci.aws.services.ec2.model.Subnet;
|
||||
import io.floci.aws.services.ec2.model.Vpc;
|
||||
import io.floci.aws.services.emr.model.EmrStudio;
|
||||
import io.floci.aws.services.emr.model.EmrStudioSessionMapping;
|
||||
import io.floci.aws.services.identitystore.IdentityStoreService;
|
||||
import io.floci.aws.services.ssoadmin.SsoAdminService;
|
||||
import io.floci.aws.testing.MutableClock;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
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.anyList;
|
||||
@@ -23,18 +28,26 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** A Studio's place in its listing, which no deleted Studio's can take, through {@link EmrStudioService}. */
|
||||
/**
|
||||
* A Studio's place in its listing, which no deleted Studio's can take, and the listings' markers, which resume only
|
||||
* their own account's and Region's, through {@link EmrStudioService}.
|
||||
*/
|
||||
class EmrStudioServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final String OTHER_REGION = "eu-west-1";
|
||||
private static final String OTHER_ACCOUNT = "111111111111";
|
||||
|
||||
private final MutableClock clock = new MutableClock();
|
||||
// One store under every service here, as the services of one Floci share theirs.
|
||||
private final AccountAwareStorageBackend<EmrStudio> store = AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
private Ec2Service ec2;
|
||||
private EmrStudioService studios;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Ec2Service ec2 = mock(Ec2Service.class);
|
||||
ec2 = mock(Ec2Service.class);
|
||||
Vpc vpc = new Vpc();
|
||||
vpc.setVpcId("vpc-1");
|
||||
Subnet subnet = new Subnet();
|
||||
@@ -46,11 +59,58 @@ class EmrStudioServiceTest {
|
||||
when(ec2.describeVpcs(eq(REGION), anyList(), any())).thenReturn(List.of(vpc));
|
||||
when(ec2.describeSubnets(eq(REGION), anyList(), any())).thenReturn(List.of(subnet));
|
||||
when(ec2.describeSecurityGroups(eq(REGION), anyList(), anyList(), any())).thenReturn(List.of(group));
|
||||
studios = new EmrStudioService(AccountAwareStorageBackend.inMemory(ACCOUNT),
|
||||
new RegionResolver(REGION, ACCOUNT), ec2, mock(SsoAdminService.class),
|
||||
studios = service(REGION, ACCOUNT);
|
||||
}
|
||||
|
||||
// The service as a request in region of account reaches it.
|
||||
private EmrStudioService service(String region, String account) {
|
||||
return new EmrStudioService(store, new RegionResolver(region, account), ec2, mock(SsoAdminService.class),
|
||||
mock(IdentityStoreService.class), clock, "http://localhost:4566");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStudiosListMarkerResumesOnlyTheListingOfItsAccountAndRegion() {
|
||||
for (int made = 0; made < 51; made++) {
|
||||
studios.createStudio(studio("studio-" + made));
|
||||
}
|
||||
String marker = studios.listStudios(null).nextToken();
|
||||
|
||||
assertNotNull(marker);
|
||||
assertEquals(1, studios.listStudios(marker).items().size());
|
||||
assertRefused(() -> service(OTHER_REGION, ACCOUNT).listStudios(marker));
|
||||
assertRefused(() -> service(REGION, OTHER_ACCOUNT).listStudios(marker));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSessionMappingsListMarkerResumesOnlyTheListingOfItsAccountRegionAndFilters() {
|
||||
EmrStudio studio = new EmrStudio();
|
||||
studio.setStudioId("es-MAPPINGS");
|
||||
studio.setRegion(REGION);
|
||||
studio.setAuthMode("SSO");
|
||||
studio.setSequence(1);
|
||||
for (int made = 0; made < 51; made++) {
|
||||
EmrStudioSessionMapping mapping = new EmrStudioSessionMapping();
|
||||
mapping.setIdentityId("user-" + made);
|
||||
mapping.setIdentityType("USER");
|
||||
mapping.setSequence(made + 1);
|
||||
studio.getSessionMappings().add(mapping);
|
||||
}
|
||||
store.put(studio.getStudioId(), studio);
|
||||
String marker = studios.listSessionMappings(null, null, null).nextToken();
|
||||
|
||||
assertNotNull(marker);
|
||||
assertEquals(1, studios.listSessionMappings(null, null, marker).items().size());
|
||||
assertRefused(() -> service(OTHER_REGION, ACCOUNT).listSessionMappings(null, null, marker));
|
||||
assertRefused(() -> service(REGION, OTHER_ACCOUNT).listSessionMappings(null, null, marker));
|
||||
assertRefused(() -> studios.listSessionMappings(null, "USER", marker));
|
||||
}
|
||||
|
||||
private static void assertRefused(Executable listing) {
|
||||
AwsException refused = assertThrows(AwsException.class, listing);
|
||||
assertEquals("InvalidRequestException", refused.getErrorCode());
|
||||
assertEquals("Invalid Marker.", refused.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStudioMadeAfterTheNewestIsDeletedListsAfterEveryEarlierOne() {
|
||||
String first = studios.createStudio(studio("first")).getStudioId();
|
||||
|
||||
Reference in new issue
Block a user