mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
chore(iam): share regional resource policy ARN checks (#7745)
This commit is contained in:
1 parent
6e3bdaf9ef
commit
ed45a35274
9 files changed
+101
-18
No files matched your search
+9
@@ -11,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class EventBridgeResourcePolicyProviderTest {
|
||||
@@ -50,4 +51,12 @@ class EventBridgeResourcePolicyProviderTest {
|
||||
assertTrue(provider.getResourcePolicies("events", "arn:aws:events:::event-bus/orders").isEmpty());
|
||||
assertTrue(provider.getResourcePolicies("sqs", "arn:aws:sqs:us-east-1:" + OWNER + ":orders").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aForeignCredentialScopeStillReadsThePartitionResourceOwner() {
|
||||
String arn = "arn:aws-us-gov:events:us-gov-west-1:" + OWNER + ":event-bus/orders";
|
||||
when(eventBridgeService.findBusPolicy(arn)).thenReturn(Optional.of(POLICY));
|
||||
|
||||
assertEquals(List.of(new ResourcePolicy(POLICY, OWNER)), provider.getResourcePolicies("states", arn));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.floci.aws.services.iam;
|
||||
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
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.assertTrue;
|
||||
|
||||
class ResourcePolicyProviderTest {
|
||||
|
||||
@Test
|
||||
void malformedRegionalOwnersAreRejected() {
|
||||
for (String arn : List.of(
|
||||
"arn:aws:sqs:us-east-1:123:orders",
|
||||
"arn:aws:sqs:us-east-1:11112222333x:orders",
|
||||
"arn:aws:sqs:us-east-1:111122223333:orders",
|
||||
"arn:aws:sqs::111122223333:orders",
|
||||
"arn:aws:sqs: :111122223333:orders")) {
|
||||
assertTrue(ResourcePolicyProvider.regionalArn(arn, "sqs").isEmpty(), arn);
|
||||
}
|
||||
assertTrue(ResourcePolicyProvider.regionalArn(null, "sqs").isEmpty());
|
||||
assertTrue(ResourcePolicyProvider.regionalArn("not-an-arn", "sqs").isEmpty());
|
||||
assertTrue(ResourcePolicyProvider.regionalArn("arn:aws:sns:us-east-1:111122223333:orders", "sqs")
|
||||
.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void regionalOwnerIsPreservedAcrossPartitions() {
|
||||
for (String value : List.of(
|
||||
"arn:aws:sqs:us-east-1:111122223333:orders",
|
||||
"arn:aws-us-gov:sqs:us-gov-west-1:111122223333:orders",
|
||||
"arn:aws-cn:sqs:cn-north-1:111122223333:orders")) {
|
||||
AwsArnUtils.Arn arn = ResourcePolicyProvider.regionalArn(value, "sqs").orElseThrow();
|
||||
assertEquals(AwsArnUtils.parse(value), arn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class SnsResourcePolicyProviderTest {
|
||||
@@ -54,4 +55,12 @@ class SnsResourcePolicyProviderTest {
|
||||
"arn:aws:sns:us-east-1:" + OWNER + ":app/GCM/my-app").isEmpty());
|
||||
assertTrue(provider.getResourcePolicies("sqs", "arn:aws:sqs:us-east-1:" + OWNER + ":queue").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aForeignCredentialScopeStillReadsThePartitionResourceOwner() {
|
||||
String arn = "arn:aws-us-gov:sns:us-gov-west-1:" + OWNER + ":orders";
|
||||
when(snsService.findTopicPolicy(arn)).thenReturn(Optional.of(POLICY));
|
||||
|
||||
assertEquals(List.of(new ResourcePolicy(POLICY, OWNER)), provider.getResourcePolicies("states", arn));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class SqsResourcePolicyProviderTest {
|
||||
@@ -47,4 +48,12 @@ class SqsResourcePolicyProviderTest {
|
||||
assertTrue(provider.getResourcePolicies("sqs", "arn:aws:sqs:us-east-1:" + OWNER + ":*").isEmpty());
|
||||
assertTrue(provider.getResourcePolicies("sns", "arn:aws:sns:us-east-1:" + OWNER + ":topic").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aForeignCredentialScopeStillReadsThePartitionResourceOwner() {
|
||||
String arn = "arn:aws-us-gov:sqs:us-gov-west-1:" + OWNER + ":orders";
|
||||
when(sqsService.findQueuePolicy(arn)).thenReturn(Optional.of(POLICY));
|
||||
|
||||
assertEquals(List.of(new ResourcePolicy(POLICY, OWNER)), provider.getResourcePolicies("states", arn));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user