fix(scheduler): check EventBridge Scheduler requests from the generated request resources (#8406)

EventBridge Scheduler was built by hand in ResourceArnBuilder. It now moves
out of HAND_BUILT into NAMESPACES, so every operation's resources come from
iam-request-resources.json, and the hand builder and the enforcement filter's
routing to it are gone.

A schedule a request names with no group is in the default group, as
botocore documents GroupName: "If you omit this, the default schedule group
is used" (CreateSchedule, DeleteSchedule), and "EventBridge Scheduler
assumes that the schedule is associated with the default group"
(GetSchedule, UpdateSchedule). The rule that reads ECS's "If you do not
specify a cluster, the default cluster is assumed" now reads this phrasing
too, and SchedulerService answers the default group's ARN, reading only. A
resource already chosen by whether its member names the default (an
EventBridge rule on the default bus or on another) takes no default of its
own, so EventBridge's entries stay as they are.

Tagging is checked on the group Scheduler's modeled /tags/{ResourceArn}
carries, the only tagging route AWS gives it. The shared tags controller
now serves a namespace the generated table reads whole only on the routes
its model gives: the bare /tags, or an ARN whose slash is not encoded, is
refused for Scheduler, EMR Serverless, GuardDuty and Security Hub with the
controller's existing "Invalid resource ARN", and tags nothing, rather than
being checked on * where a Deny on the resource would not apply.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-14 23:59:33 -04:00
1 parent 1b8e4fa503
commit 4a70910c53
24 files changed
+511 -176

No files matched your search

@@ -8,9 +8,12 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -34,29 +37,45 @@ class AbstractTagsControllerTest {
}
@Test
void listTagsDelegatesToDispatcher() {
void listTagsDelegatesToDispatcherOnARouteOfTheArnsService() {
HttpHeaders headers = mock(HttpHeaders.class);
UriInfo uriInfo = mock(UriInfo.class);
String arn = "arn:aws:apigateway:us-east-1::/restapis/123";
Response expected = Response.ok().build();
when(dispatcher.resolveHandler(arn, uriInfo)).thenReturn(handler);
when(dispatcher.listTagsForArn(headers, arn)).thenReturn(expected);
Response actual = controller.listTags(headers, arn);
Response actual = controller.listTags(headers, uriInfo, arn);
assertEquals(expected, actual);
verify(dispatcher).resolveHandler(arn, uriInfo);
verify(dispatcher).listTagsForArn(headers, arn);
}
@Test
void aRequestOnNoRouteOfTheArnsServiceIsRefusedBeforeItIsDispatched() {
HttpHeaders headers = mock(HttpHeaders.class);
UriInfo uriInfo = mock(UriInfo.class);
String arn = "arn:aws:scheduler:us-east-1:000000000000:schedule-group/reports";
AwsException refused = new AwsException("BadRequestException", "Invalid resource ARN: " + arn, 400);
when(dispatcher.resolveHandler(arn, uriInfo)).thenThrow(refused);
assertSame(refused, assertThrows(AwsException.class, () -> controller.listTags(headers, uriInfo, arn)));
verify(dispatcher, never()).listTagsForArn(any(), any());
}
@Test
void tagResourcePostDispatchesWithHandlerSuccessStatus() {
HttpHeaders headers = mock(HttpHeaders.class);
String arn = "arn:aws:kafka:us-east-1:000000000000:cluster/test/id";
String body = "{\"tags\":{\"env\":\"test\"}}";
when(dispatcher.resolveHandler(arn)).thenReturn(handler);
UriInfo uriInfo = mock(UriInfo.class);
when(dispatcher.resolveHandler(arn, uriInfo)).thenReturn(handler);
when(handler.tagResourceSuccessStatus()).thenReturn(204);
Response expected = Response.noContent().build();
when(dispatcher.tagResourcePost(eq(headers), eq(arn), eq(body), any(Response.class))).thenReturn(expected);
Response actual = controller.tagResourcePost(headers, arn, body);
Response actual = controller.tagResourcePost(headers, uriInfo, arn, body);
assertEquals(expected, actual);
verify(dispatcher).tagResourcePost(eq(headers), eq(arn), eq(body), any(Response.class));
@@ -67,12 +86,13 @@ class AbstractTagsControllerTest {
HttpHeaders headers = mock(HttpHeaders.class);
String arn = "arn:aws:apigateway:us-east-1::/restapis/123";
String body = "{\"tags\":{\"env\":\"test\"}}";
when(dispatcher.resolveHandler(arn)).thenReturn(handler);
UriInfo uriInfo = mock(UriInfo.class);
when(dispatcher.resolveHandler(arn, uriInfo)).thenReturn(handler);
when(handler.tagResourceSuccessStatus()).thenReturn(200);
Response expected = Response.ok().build();
when(dispatcher.tagResourcePut(eq(headers), eq(arn), eq(body), any(Response.class))).thenReturn(expected);
Response actual = controller.tagResourcePut(headers, arn, body);
Response actual = controller.tagResourcePut(headers, uriInfo, arn, body);
assertEquals(expected, actual);
verify(dispatcher).tagResourcePut(eq(headers), eq(arn), eq(body), any(Response.class));
@@ -83,7 +103,7 @@ class AbstractTagsControllerTest {
HttpHeaders headers = mock(HttpHeaders.class);
UriInfo uriInfo = mock(UriInfo.class);
String arn = "arn:aws:apigateway:us-east-1::/restapis/123";
when(dispatcher.resolveHandler(arn)).thenReturn(handler);
when(dispatcher.resolveHandler(arn, uriInfo)).thenReturn(handler);
when(handler.untagResourceSuccessStatus()).thenReturn(204);
Response expected = Response.noContent().build();
when(dispatcher.untagResourceForArn(eq(headers), eq(uriInfo), eq(arn), any(Response.class), eq(handler)))
@@ -451,8 +451,9 @@ class IamEnforcementFilterTest {
}
@Test
void schedulerResourcesAreBuiltInTheRequestsPartition() {
// A Region no partition publishes takes the deployment's partition, which Scheduler mints its ARNs in.
void schedulerResourcesAreReadFromTheTableInTheRequestsPartition() {
// A Region no partition publishes takes the deployment's partition, which Scheduler mints its ARNs in, on the
// operation the request is dispatched as, which the table of request resources reads.
ContainerRequestContext containerRequest = mock(ContainerRequestContext.class);
String auth = "AWS4-HMAC-SHA256 Credential=AKIAUSER/20260924/xx-local-1/scheduler/aws4_request, "
+ "SignedHeaders=host, Signature=abc";
@@ -467,12 +468,13 @@ class IamEnforcementFilterTest {
.thenReturn(Optional.of(descriptor("scheduler", ServiceProtocol.JSON,
Set.of("scheduler"), SchedulerController.class)));
when(actionRegistry.resolveRoute("scheduler", containerRequest)).thenReturn("scheduler:GetSchedule");
when(arnBuilder.buildResources(any(), any(), any(), any(), any())).thenReturn(List.of("*"));
when(arnBuilder.buildResources(any(), any(), any(), any(), any(), any())).thenReturn(List.of("*"));
when(iamService.resolveCallerContext(eq("AKIAUSER"), any())).thenReturn(CallerContext.of(List.of()));
newFilter(resourceInfo(SchedulerController.class)).filter(containerRequest);
verify(arnBuilder).buildResources("scheduler", containerRequest, "xx-local-1", "000000000000", "aws-cn");
verify(arnBuilder).buildResources("scheduler", "scheduler:GetSchedule", containerRequest, "xx-local-1",
"000000000000", "aws-cn");
}
@Test
@@ -0,0 +1,65 @@
package io.floci.aws.core.common;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.UriInfo;
import org.junit.jupiter.api.Test;
import java.net.URI;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class TagDispatcherTest {
private static final String GROUP = "arn:aws:scheduler:us-east-1:000000000000:schedule-group/reports";
private static final String PIPE = "arn:aws:pipes:us-east-1:000000000000:pipe/orders";
private final TagHandler scheduler = handler("scheduler");
private final TagHandler pipes = handler("pipes");
private final TagDispatcher dispatcher = new TagDispatcher(List.of(scheduler, pipes),
new RegionResolver("us-east-1", "000000000000"), new ObjectMapper());
/**
* Scheduler, which the generated table reads whole, tags on its modeled /tags/{ResourceArn} alone, the ARN sent
* as one encoded segment: the bare /tags, or an ARN whose slash is not encoded, is no route of its model and is
* refused as an ARN that path does not serve.
*/
@Test
void aServiceTheTableReadsIsServedOnlyOnTheRoutesItsModelGives() {
String encoded = "/tags/arn%3Aaws%3Ascheduler%3Aus-east-1%3A000000000000%3Aschedule-group%2Freports";
assertSame(scheduler, dispatcher.resolveHandler(GROUP, sent(encoded)));
for (String refused : List.of("/tags", "/tags/" + GROUP)) {
AwsException error = assertThrows(AwsException.class,
() -> dispatcher.resolveHandler(GROUP, sent(refused)));
assertEquals(400, error.getHttpStatus());
assertEquals("Invalid resource ARN: " + GROUP, error.getMessage());
}
}
/** Pipes is still built by hand, its tagged ARN read wherever the controller reads it, so every route serves it. */
@Test
void aServiceBuiltByHandIsServedOnEveryRoute() {
assertSame(pipes, dispatcher.resolveHandler(PIPE, sent("/tags")));
assertSame(pipes, dispatcher.resolveHandler(PIPE, sent("/tags/" + PIPE)));
}
private static TagHandler handler(String serviceKey) {
TagHandler handler = mock(TagHandler.class);
when(handler.serviceKey()).thenReturn(serviceKey);
return handler;
}
/** The URI of a request sent to the path, as {@link UriInfo} gives it. */
private static UriInfo sent(String path) {
UriInfo uriInfo = mock(UriInfo.class);
when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:4566" + path));
when(uriInfo.getBaseUri()).thenReturn(URI.create("http://localhost:4566/"));
when(uriInfo.getQueryParameters()).thenReturn(new MultivaluedHashMap<>());
return uriInfo;
}
}
@@ -6,6 +6,8 @@ import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
@@ -93,9 +95,9 @@ class CloudFormationListIntrinsicsIntegrationTest {
.when().post("/")
.then().statusCode(200).body("Tags", equalTo(expected));
given()
.queryParam("resourceArn", "arn:aws:scheduler:us-east-1:000000000000:schedule-group/" + name)
.when().get("/tags")
given().urlEncodingEnabled(false)
.when().get("/tags/" + URLEncoder.encode(
"arn:aws:scheduler:us-east-1:000000000000:schedule-group/" + name, StandardCharsets.UTF_8))
.then().statusCode(200).body("Tags", equalTo(expected));
}
} finally {
@@ -6,6 +6,8 @@ import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import static io.restassured.RestAssured.given;
@@ -260,36 +262,36 @@ class GuardDutyControllerIntegrationTest {
String detectorId = createDetector(authorization, "{\"enable\":true,\"tags\":{\"env\":\"test\"}}");
String arn = "arn:aws:guardduty:" + EAST + ":000000000208:detector/" + detectorId;
given()
given().urlEncodingEnabled(false)
.contentType("application/json")
.header("Authorization", authorization)
.body("{\"tags\":{\"team\":\"security\"}}")
.when()
.post("/tags/" + arn)
.post(tagsPath(arn))
.then()
.statusCode(204);
given()
given().urlEncodingEnabled(false)
.header("Authorization", authorization)
.when()
.get("/tags/" + arn)
.get(tagsPath(arn))
.then()
.statusCode(200)
.body("tags.env", equalTo("test"))
.body("tags.team", equalTo("security"));
given()
given().urlEncodingEnabled(false)
.header("Authorization", authorization)
.queryParam("tagKeys", "env")
.when()
.delete("/tags/" + arn)
.delete(tagsPath(arn))
.then()
.statusCode(204);
given()
given().urlEncodingEnabled(false)
.header("Authorization", authorization)
.when()
.get("/tags/" + arn)
.get(tagsPath(arn))
.then()
.statusCode(200)
.body("tags.team", equalTo("security"));
@@ -311,4 +313,9 @@ class GuardDutyControllerIntegrationTest {
.body("detectorId", notNullValue())
.extract().path("detectorId");
}
/** The modeled {@code /tags/{ResourceArn}}, the ARN encoded as one path segment as an SDK sends it. */
private static String tagsPath(String arn) {
return "/tags/" + URLEncoder.encode(arn, StandardCharsets.UTF_8);
}
}
@@ -7,6 +7,8 @@ import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
@@ -127,16 +129,16 @@ class GuardDutyMalwareProtectionPlanIntegrationTest {
""".formatted(ROLE));
String arn = "arn:aws:guardduty:eu-north-1:000000000205:malware-protection-plan/" + planId;
given().contentType("application/json").header("Authorization", auth)
given().urlEncodingEnabled(false).contentType("application/json").header("Authorization", auth)
.body("{\"tags\":{\"b\":\"2\"}}")
.when().post("/tags/" + arn)
.when().post(tagsPath(arn))
.then().statusCode(204);
given().header("Authorization", auth)
.when().delete("/tags/" + arn + "?tagKeys=a")
given().urlEncodingEnabled(false).header("Authorization", auth)
.when().delete(tagsPath(arn) + "?tagKeys=a")
.then().statusCode(204);
given().header("Authorization", auth)
.when().get("/tags/" + arn)
given().urlEncodingEnabled(false).header("Authorization", auth)
.when().get(tagsPath(arn))
.then().statusCode(200)
.body("tags.b", equalTo("2"))
.body("tags.a", nullValue());
@@ -225,4 +227,9 @@ class GuardDutyMalwareProtectionPlanIntegrationTest {
.body("malwareProtectionPlanId", not(startsWith("arn:")))
.extract().path("malwareProtectionPlanId");
}
/** The modeled {@code /tags/{ResourceArn}}, the ARN encoded as one path segment as an SDK sends it. */
private static String tagsPath(String arn) {
return "/tags/" + URLEncoder.encode(arn, StandardCharsets.UTF_8);
}
}
@@ -184,6 +184,25 @@ class IamActionRegistryTest {
assertEquals(action, registry.resolveRoute("es", mockCtx(method, path, new MultivaluedHashMap<>(), null, "")));
}
@Test
void aRequestIsOnAPathOfAServicesModelOnlyAsTheModelGivesIt() {
MultivaluedMap<String, String> none = new MultivaluedHashMap<>();
String encoded = "/tags/arn%3Aaws%3Ascheduler%3Aus-east-1%3A000000000000%3Aschedule-group%2Freports";
// Scheduler's /tags/{ResourceArn} takes the ARN as one segment, encoded as an SDK sends it, whatever method
// a request sends there.
assertTrue(IamActionRegistry.modelRoutes("scheduler", mockCtx("POST", encoded, none, null, "").getUriInfo()));
assertTrue(IamActionRegistry.modelRoutes("scheduler", mockCtx("PUT", encoded, none, null, "").getUriInfo()));
assertFalse(IamActionRegistry.modelRoutes("scheduler",
mockCtx("POST", "/tags/arn:aws:scheduler:us-east-1:000000000000:schedule-group/reports", none, null, "")
.getUriInfo()));
assertFalse(IamActionRegistry.modelRoutes("scheduler", mockCtx("POST", "/tags", none, null, "").getUriInfo()));
// Control Tower's generated routes give the bare path the shared tags controller also serves it on.
assertTrue(IamActionRegistry.modelRoutes("controltower",
mockCtx("POST", "/tags", none, null, "").getUriInfo()));
// A scope whose routes are not vendored is not one the model can answer for.
assertTrue(IamActionRegistry.modelRoutes("sqs", mockCtx("POST", "/tags", none, null, "").getUriInfo()));
}
@Test
void theLabelsOfTheVendoredRouteARequestMatchesAreItsPathsValuesDecoded() {
MultivaluedMap<String, String> none = new MultivaluedHashMap<>();
@@ -144,28 +144,39 @@ class IamRestRouteEnforcementIntegrationTest {
}
@Test
void schedulerTaggingIsCheckedOnTheBareTagsRouteToo() {
// The shared tagging routes also take the ARN in the body of POST /tags.
void schedulerTaggingIsCheckedOnTheGroupItsModeledRouteNamesAndServedOnNoOtherRoute() {
// Scheduler tags the group whose ARN its modeled /tags/{ResourceArn} carries, which the generated request
// resources read, so a Deny on that group holds against an Allow on every resource. The shared controller's
// bare POST /tags is no route of Scheduler's model, as AWS gives it none: let through, it is refused as an
// ARN that path does not serve, and tags nothing.
String user = user("route-scheduler-tags");
String group = scheduleGroup("route-group-" + suffix());
String tagsPath = "/tags/" + encoded(group);
String tags = "{\"Tags\":[{\"Key\":\"team\",\"Value\":\"a\"}]}";
policy(user, allow("scheduler:ListTagsForResource", "*"));
refused(as(user, "scheduler").body(tagBody(group)).post("/tags").then(), "scheduler:TagResource");
refused(as(user, "scheduler").urlEncodingEnabled(false).body(tags).post(tagsPath).then(),
"scheduler:TagResource");
policy(user, allow("scheduler:TagResource", group));
// Allowed on that group, the request reaches Scheduler, which has no such group.
as(user, "scheduler").body(tagBody(group)).post("/tags").then().statusCode(not(403));
as(user, "scheduler").urlEncodingEnabled(false).body(tags).post(tagsPath).then().statusCode(not(403));
policy(user, allow("scheduler:TagResource", "*") + "," + deny("scheduler:TagResource", group));
refused(as(user, "scheduler").urlEncodingEnabled(false).body(tags).post(tagsPath).then(),
"scheduler:TagResource");
as(user, "scheduler").body(tagBody(group)).post("/tags").then().statusCode(400)
.body(containsString("Invalid resource ARN"));
}
@Test
void postTagsIsCheckedAgainstTheArnItsBodyNames() {
// POST /tags tags the ARN its body names: one named in the query does not move the check.
String user = user("route-tags-body");
String allowed = scheduleGroup("route-allowed-" + suffix());
String other = scheduleGroup("route-other-" + suffix());
String allowed = "arn:aws:pipes:us-east-1:" + ACCOUNT + ":pipe/route-allowed-" + suffix();
String other = "arn:aws:pipes:us-east-1:" + ACCOUNT + ":pipe/route-other-" + suffix();
policy(user, allow("scheduler:TagResource", allowed));
refused(as(user, "scheduler").queryParam("resourceArn", allowed).body(tagBody(other)).post("/tags").then(),
"scheduler:TagResource");
policy(user, allow("pipes:TagResource", allowed));
refused(as(user, "pipes").queryParam("resourceArn", allowed).body(tagBody(other)).post("/tags").then(),
"pipes:TagResource");
}
@Test
@@ -2414,65 +2414,101 @@ class ResourceArnBuilderTest {
builder.buildResources("apigateway", ctx, "us-gov-west-1", ACCOUNT, "aws-us-gov"));
}
/**
* Scheduler as IAM asks it: the {@code default} schedule group, in the partition given, the one a request naming
* no group acts on.
*/
private static StoredResourceArns schedulerIn(String partition) {
return new StoredResourceArns() {
@Override
public String namespace() {
return "scheduler";
}
@Override
public Optional<String> find(String type, List<String> names, String region) {
return Optional.empty();
}
@Override
public Optional<String> findDefault(String type, String region) {
return "schedule-group".equals(type)
? Optional.of("arn:" + partition + ":scheduler:" + region + ":" + ACCOUNT
+ ":schedule-group/default")
: Optional.empty();
}
};
}
private List<String> schedulerResources(ResourceArnBuilder builder, String method, String sent, String operation) {
when(ctx.getMethod()).thenReturn(method);
request(sent);
return builder.buildResources("scheduler", "scheduler:" + operation, ctx, "us-east-1", ACCOUNT, "aws");
}
/**
* A schedule is in the group its request names, the body's {@code GroupName} on a create or an update and the
* {@code groupName} query parameter otherwise, and in the {@code default} group when it names none, as botocore
* documents ("If you omit this, the default schedule group is used"); a group is the one its path names; a tag
* route's resource the ARN in its path; and the list operations act on no resource type.
*/
@Test
void schedulerRoutesResolveTheScheduleInItsGroupTheGroupOrTheTaggedArn() {
when(uriInfo.getPath()).thenReturn("/schedules/nightly");
assertEquals("arn:aws:scheduler:us-east-1:000000000000:schedule/default/nightly",
builder.build("scheduler", ctx, "us-east-1", "000000000000"));
void aScheduleIsInTheGroupItsRequestNamesOrTheDefaultOneAndAGroupIsTheOneItsPathNames() {
ResourceArnBuilder backed = reading(schedulerIn("aws"));
String schedule = "arn:aws:scheduler:us-east-1:000000000000:schedule/";
assertEquals(List.of(schedule + "default/nightly"),
schedulerResources(backed, "GET", "/schedules/nightly", "GetSchedule"));
assertEquals(List.of(schedule + "default/nightly"),
schedulerResources(backed, "DELETE", "/schedules/nightly", "DeleteSchedule"));
queryParams.putSingle("groupName", "reports");
assertEquals("arn:aws:scheduler:us-east-1:000000000000:schedule/reports/nightly",
builder.build("scheduler", ctx, "us-east-1", "000000000000"));
// A create or update names its group in the body, which Scheduler reads, not in the query, which
// it ignores for them: a groupName there does not move the check to another group.
when(ctx.getMethod()).thenReturn("POST");
setJsonBody("{\"GroupName\":\"billing\",\"ScheduleExpression\":\"rate(1 hour)\"}");
assertEquals("arn:aws:scheduler:us-east-1:000000000000:schedule/billing/nightly",
builder.build("scheduler", ctx, "us-east-1", "000000000000"));
queryParams.putSingle("groupName", "reports");
setJsonBody("{\"GroupName\":\"billing\",\"ScheduleExpression\":\"rate(1 hour)\"}");
assertEquals("arn:aws:scheduler:us-east-1:000000000000:schedule/billing/nightly",
builder.build("scheduler", ctx, "us-east-1", "000000000000"));
assertEquals(List.of(schedule + "reports/nightly"),
schedulerResources(backed, "GET", "/schedules/nightly?groupName=reports", "GetSchedule"));
// A create or update names its group in the body, which Scheduler reads, not in the query, which it
// ignores for them: a groupName there does not move the check to another group. A target's ARN is no
// schedule's.
setJsonBody("{\"GroupName\":\"billing\",\"ScheduleExpression\":\"rate(1 hour)\",\"Target\":{\"Arn\":"
+ "\"arn:aws:lambda:us-east-1:000000000000:function:f\","
+ "\"RoleArn\":\"arn:aws:iam::000000000000:role/r\"}}");
assertEquals(List.of(schedule + "billing/nightly"),
schedulerResources(backed, "POST", "/schedules/nightly?groupName=reports", "CreateSchedule"));
queryParams.clear();
when(ctx.getMethod()).thenReturn("PUT");
setJsonBody("{\"ScheduleExpression\":\"rate(1 hour)\"}");
assertEquals("arn:aws:scheduler:us-east-1:000000000000:schedule/default/nightly",
builder.build("scheduler", ctx, "us-east-1", "000000000000"));
when(ctx.getMethod()).thenReturn("GET");
queryParams.clear();
when(uriInfo.getPath()).thenReturn("/schedule-groups/reports");
assertEquals("arn:aws:scheduler:us-east-1:000000000000:schedule-group/reports",
builder.build("scheduler", ctx, "us-east-1", "000000000000"));
assertEquals(List.of(schedule + "default/nightly"),
schedulerResources(backed, "PUT", "/schedules/nightly", "UpdateSchedule"));
String group = "arn:aws:scheduler:us-east-1:000000000000:schedule-group/reports";
when(uriInfo.getPath()).thenReturn("/tags/" + group);
assertEquals(group, builder.build("scheduler", ctx, "us-east-1", "000000000000"));
// The same tagging is served at /tags, the ARN in the resourceArn query parameter or body field.
when(uriInfo.getPath()).thenReturn("/tags");
queryParams.putSingle("resourceArn", group);
assertEquals(group, builder.build("scheduler", ctx, "us-east-1", "000000000000"));
assertEquals(List.of(group), schedulerResources(backed, "GET", "/schedule-groups/reports", "GetScheduleGroup"));
assertEquals(List.of(group),
schedulerResources(backed, "POST", "/schedule-groups/reports", "CreateScheduleGroup"));
assertEquals(List.of(group),
schedulerResources(backed, "DELETE", "/schedule-groups/reports", "DeleteScheduleGroup"));
// An SDK sends the ARN in the path encoded, as one segment of the modeled /tags/{ResourceArn}.
String encoded = "/tags/arn%3Aaws%3Ascheduler%3Aus-east-1%3A000000000000%3Aschedule-group%2Freports";
assertEquals(List.of(group), schedulerResources(backed, "GET", encoded, "ListTagsForResource"));
assertEquals(List.of(group), schedulerResources(backed, "POST", encoded, "TagResource"));
queryParams.putSingle("TagKeys", "team");
assertEquals(List.of(group), schedulerResources(backed, "DELETE", encoded + "?TagKeys=team", "UntagResource"));
queryParams.clear();
when(ctx.getMethod()).thenReturn("POST");
setJsonBody("{\"resourceArn\":\"" + group + "\",\"tags\":[]}");
assertEquals(group, builder.build("scheduler", ctx, "us-east-1", "000000000000"));
// POST /tags tags the body's ARN, so a resourceArn in the query does not move the check.
queryParams.putSingle("resourceArn", "arn:aws:scheduler:us-east-1:000000000000:schedule-group/other");
setJsonBody("{\"resourceArn\":\"" + group + "\",\"tags\":[]}");
assertEquals(group, builder.build("scheduler", ctx, "us-east-1", "000000000000"));
queryParams.clear();
when(uriInfo.getPath()).thenReturn("/schedules");
assertEquals("*", builder.build("scheduler", ctx, "us-east-1", "000000000000"));
assertEquals(List.of("*"), schedulerResources(backed, "GET", "/schedules", "ListSchedules"));
assertEquals(List.of("*"), schedulerResources(backed, "GET", "/schedule-groups", "ListScheduleGroups"));
}
@Test
void schedulerAndPipesArnsAreMintedInTheRequestsPartition() {
// A Region no partition publishes takes the deployment's partition, as Scheduler and Pipes mint
// their ARNs, rather than aws.
when(uriInfo.getPath()).thenReturn("/schedules/nightly");
ResourceArnBuilder backed = reading(schedulerIn("aws-cn"));
when(ctx.getMethod()).thenReturn("GET");
request("/schedules/nightly");
assertEquals(List.of("arn:aws-cn:scheduler:xx-local-1:000000000000:schedule/default/nightly"),
builder.buildResources("scheduler", ctx, "xx-local-1", "000000000000", "aws-cn"));
when(uriInfo.getPath()).thenReturn("/schedule-groups/reports");
backed.buildResources("scheduler", "scheduler:GetSchedule", ctx, "xx-local-1", "000000000000",
"aws-cn"));
request("/schedule-groups/reports");
assertEquals(List.of("arn:aws-cn:scheduler:xx-local-1:000000000000:schedule-group/reports"),
builder.buildResources("scheduler", ctx, "xx-local-1", "000000000000", "aws-cn"));
when(uriInfo.getPath()).thenReturn("/v1/pipes/orders");
backed.buildResources("scheduler", "scheduler:GetScheduleGroup", ctx, "xx-local-1", "000000000000",
"aws-cn"));
request("/v1/pipes/orders");
assertEquals(List.of("arn:aws-cn:pipes:xx-local-1:000000000000:pipe/orders"),
builder.buildResources("pipes", ctx, "xx-local-1", "000000000000", "aws-cn"));
}
@@ -8,6 +8,8 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import static io.restassured.RestAssured.given;
@@ -221,13 +223,21 @@ class SchedulerIntegrationTest {
private static final String TAGGED_GROUP_ARN =
"arn:aws:scheduler:us-east-1:000000000000:schedule-group/tagged-group";
/**
* The modeled {@code /tags/{ResourceArn}} for an ARN, encoded as one path segment as an SDK sends it. Send it with
* {@code urlEncodingEnabled(false)}, or it is encoded twice.
*/
private static String tagsPath(String arn) {
return "/tags/" + URLEncoder.encode(arn, StandardCharsets.UTF_8);
}
@Test
@Order(13)
void listTagsReturnsTagsFromCreate() {
// tagged-group was created at @Order(2) with env=test and team=platform.
given()
given().urlEncodingEnabled(false)
.when()
.get("/tags/" + TAGGED_GROUP_ARN)
.get(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(200)
.body("Tags.find { it.Key == 'env' }.Value", equalTo("test"))
@@ -243,7 +253,7 @@ class SchedulerIntegrationTest {
// a system whose clock granularity collides with the test class's startup speed.
Thread.sleep(2);
given()
given().urlEncodingEnabled(false)
.contentType("application/json")
.body("""
{
@@ -254,13 +264,13 @@ class SchedulerIntegrationTest {
}
""")
.when()
.post("/tags/" + TAGGED_GROUP_ARN)
.post(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(204);
given()
given().urlEncodingEnabled(false)
.when()
.get("/tags/" + TAGGED_GROUP_ARN)
.get(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(200)
.body("Tags.find { it.Key == 'owner' }.Value", equalTo("Alice"))
@@ -291,17 +301,17 @@ class SchedulerIntegrationTest {
@Test
@Order(15)
void untagResourceRemovesKeys() {
given()
given().urlEncodingEnabled(false)
.queryParam("TagKeys", "owner")
.queryParam("TagKeys", "env")
.when()
.delete("/tags/" + TAGGED_GROUP_ARN)
.delete(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(204);
given()
given().urlEncodingEnabled(false)
.when()
.get("/tags/" + TAGGED_GROUP_ARN)
.get(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(200)
.body("Tags.find { it.Key == 'owner' }", nullValue())
@@ -309,17 +319,53 @@ class SchedulerIntegrationTest {
.body("Tags.find { it.Key == 'team' }.Value", equalTo("platform"));
}
@Test
@Order(16)
void taggingOnARouteSchedulerDoesNotHaveIsRefusedAndTagsNothing() {
// AWS serves Scheduler's tagging on /tags/{ResourceArn} alone: the bare /tags the shared controller serves
// other services on, and a path whose ARN's slash is not encoded, are no route of Scheduler's.
given()
.contentType("application/json")
.body("{\"resourceArn\":\"" + TAGGED_GROUP_ARN + "\",\"tags\":[{\"key\":\"refused\",\"value\":\"x\"}]}")
.when()
.post("/tags")
.then()
.statusCode(400)
.body(containsString("Invalid resource ARN"));
given()
.contentType("application/json")
.body("{\"Tags\":[{\"Key\":\"refused\",\"Value\":\"x\"}]}")
.when()
.post("/tags/" + TAGGED_GROUP_ARN)
.then()
.statusCode(400)
.body(containsString("Invalid resource ARN"));
given()
.queryParam("resourceArn", TAGGED_GROUP_ARN)
.when()
.get("/tags")
.then()
.statusCode(400);
given().urlEncodingEnabled(false)
.when()
.get(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(200)
.body("Tags.find { it.Key == 'refused' }", nullValue());
}
@Test
@Order(16)
void tagResourceOnMissingGroupReturns404() {
String arn = "arn:aws:scheduler:us-east-1:000000000000:schedule-group/no-such-group";
given()
given().urlEncodingEnabled(false)
.contentType("application/json")
.body("""
{"Tags": [{"Key": "k", "Value": "v"}]}
""")
.when()
.post("/tags/" + arn)
.post(tagsPath(arn))
.then()
.statusCode(404);
}
@@ -329,10 +375,10 @@ class SchedulerIntegrationTest {
void tagResourceWithEmptyBodyReturns400() {
// Null/blank request body must surface as the structured AWS validation error
// ("Value null at 'Tags' ...") rather than leaking a Jackson parser message.
given()
given().urlEncodingEnabled(false)
.contentType("application/json")
.when()
.post("/tags/" + TAGGED_GROUP_ARN)
.post(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(400);
}
@@ -342,11 +388,11 @@ class SchedulerIntegrationTest {
void tagResourceWithNonObjectBodyReturns400() {
// A syntactically valid JSON array at the root must be rejected as a wire-shape
// error, not silently treated as "missing 'Tags'".
given()
given().urlEncodingEnabled(false)
.contentType("application/json")
.body("[1,2,3]")
.when()
.post("/tags/" + TAGGED_GROUP_ARN)
.post(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(400);
}
@@ -356,13 +402,13 @@ class SchedulerIntegrationTest {
void tagResourceOnScheduleArnReturns400() {
// AWS only allows tagging schedule groups, not individual schedules.
String arn = "arn:aws:scheduler:us-east-1:000000000000:schedule/default/some-schedule";
given()
given().urlEncodingEnabled(false)
.contentType("application/json")
.body("""
{"Tags": [{"Key": "k", "Value": "v"}]}
""")
.when()
.post("/tags/" + arn)
.post(tagsPath(arn))
.then()
.statusCode(400);
}
@@ -372,11 +418,11 @@ class SchedulerIntegrationTest {
void tagResourceWithoutTagsReturns400() {
// AWS spec: Tags is required on TagResource. Empty body must surface as
// ValidationException rather than silently succeed.
given()
given().urlEncodingEnabled(false)
.contentType("application/json")
.body("{}")
.when()
.post("/tags/" + TAGGED_GROUP_ARN)
.post(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(400);
}
@@ -385,9 +431,9 @@ class SchedulerIntegrationTest {
@Order(19)
void untagResourceWithoutTagKeysReturns400() {
// AWS spec: TagKeys is required on UntagResource.
given()
given().urlEncodingEnabled(false)
.when()
.delete("/tags/" + TAGGED_GROUP_ARN)
.delete(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(400);
}
@@ -1028,13 +1074,13 @@ class SchedulerIntegrationTest {
void tagResourceEntryMissingKeyOrValueReturns400() {
// AWS Tag shape requires both Key and Value; entries with either missing
// must surface as ValidationException, not be silently dropped.
given()
given().urlEncodingEnabled(false)
.contentType("application/json")
.body("""
{"Tags": [{"Key": "k"}]}
""")
.when()
.post("/tags/" + TAGGED_GROUP_ARN)
.post(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(400);
}
@@ -1044,13 +1090,13 @@ class SchedulerIntegrationTest {
void tagResourceTagsWrongTypeReturns400() {
// Tags must be a list. An object or string in its place is a wire-format
// error, not a missing value, so the message should differ from "Value null".
given()
given().urlEncodingEnabled(false)
.contentType("application/json")
.body("""
{"Tags": "not-a-list"}
""")
.when()
.post("/tags/" + TAGGED_GROUP_ARN)
.post(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(400);
}
@@ -1060,13 +1106,13 @@ class SchedulerIntegrationTest {
void tagResourceWithPutMethodReturns405() {
// AWS Scheduler only defines POST for TagResource. PUT is not in the spec
// and must be rejected so floci does not expose a non-AWS mutation route.
given()
given().urlEncodingEnabled(false)
.contentType("application/json")
.body("""
{"Tags": [{"Key": "k", "Value": "v"}]}
""")
.when()
.put("/tags/" + TAGGED_GROUP_ARN)
.put(tagsPath(TAGGED_GROUP_ARN))
.then()
.statusCode(405);
}