test: drop duplicate and debug test classes (#9406)

Removes six test classes whose checks are covered elsewhere, moving across the
few checks only they made: S3DumpTest and UriBuilderTest asserted nothing,
FilterTest repeated S3VirtualHostTest, ApiGatewayGetTagsIntegrationTest and
LambdaCodeSigningConfigIntegrationTest repeated stronger siblings,
ApiGatewayUntagResourceIntegrationTest's encoded-ARN UntagResource check moves
into testTagResource, and Ec2Phase2IntegrationTest folds into
Ec2IntegrationTest with its launch-option checks and cleanup.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-11-24 20:29:52 -04:00
1 parent 06046bf707
commit a84ec2bb2b
9 files changed
+362 -676

No files matched your search

@@ -1,43 +0,0 @@
package io.floci.aws.services.apigateway;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
@QuarkusTest
class ApiGatewayGetTagsIntegrationTest {
@Test
void testGetTags() {
String apiId = given()
.contentType("application/json")
.body("{\"name\":\"get-tags-api\"}")
.when()
.post("/restapis")
.then()
.statusCode(201)
.extract()
.path("id");
String resourceArn = "arn:aws:apigateway:us-east-1::/restapis/" + apiId;
given()
.pathParam("resourceArn", resourceArn)
.contentType("application/json")
.body("{\"tags\":{\"owner\":\"network\"}}")
.when()
.put("/tags/{resourceArn}")
.then()
.statusCode(204);
given()
.pathParam("resourceArn", resourceArn)
.when()
.get("/tags/{resourceArn}")
.then()
.statusCode(200)
.body("tags.owner", equalTo("network"));
}
}
@@ -43,6 +43,24 @@ class ApiGatewayTagResourceIntegrationTest {
.then()
.statusCode(200)
.body("tags.environment", equalTo("test"));
given()
.pathParam("resourceArn", resourceArn)
.queryParam("tagKeys", "environment")
.when()
.delete("/tags/{resourceArn}")
.then()
.statusCode(204);
given()
.pathParam("apiId", apiId)
.when()
.get("/restapis/{apiId}")
.then()
.statusCode(200)
.body("tags.environment", nullValue());
given().pathParam("apiId", apiId).when().delete("/restapis/{apiId}").then().statusCode(202);
}
@Test
@@ -1,50 +0,0 @@
package io.floci.aws.services.apigateway;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.nullValue;
@QuarkusTest
public class ApiGatewayUntagResourceIntegrationTest {
@Test
public void testUntagResource() {
String apiId = given()
.contentType("application/json")
.body("{\"name\":\"untaggable-api\"}")
.when()
.post("/restapis")
.then()
.statusCode(201)
.extract().path("id");
String resourceArn = "arn:aws:apigateway:us-east-1::/restapis/" + apiId;
given()
.pathParam("resourceArn", resourceArn)
.contentType("application/json")
.body("{\"tags\":{\"team\":\"platform\"}}")
.when()
.put("/tags/{resourceArn}")
.then()
.statusCode(204);
given()
.pathParam("resourceArn", resourceArn)
.queryParam("tagKeys", "team")
.when()
.delete("/tags/{resourceArn}")
.then()
.statusCode(204);
given()
.pathParam("apiId", apiId)
.when()
.get("/restapis/{apiId}")
.then()
.statusCode(200)
.body("tags.team", nullValue());
}
}
@@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
@@ -29,6 +30,7 @@ import java.util.zip.GZIPOutputStream;
import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyOrNullString;
@@ -61,6 +63,11 @@ class Ec2IntegrationTest {
/** A second account, which reaches the default account's IPAM pools by id. */
private static final String WORKLOAD_AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=000000000002/20260205/us-east-1/ec2/aws4_request";
private static final String IAM_AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/iam/aws4_request";
private static final String PROFILE_BY_ARN = "my-app-role";
private static final String PROFILE_BY_NAME = "my-app-profile";
private static final String LAUNCH_KEY_NAME = "launch-imported-key";
private static String instanceId;
private static String vpcId;
@@ -78,6 +85,10 @@ class Ec2IntegrationTest {
private static String rootVolumeId;
private static String networkInterfaceId;
private static String launchTemplateId;
private static String instanceWithUserData;
private static String instanceWithProfile;
private static String instanceWithProfileName;
private static final List<String> launchedInstances = new ArrayList<>();
private static String launchTemplateUserData;
private static String launchTemplateVersionUserData;
private static String vpcEndpointId;
@@ -3889,7 +3900,8 @@ class Ec2IntegrationTest {
.then()
.statusCode(200)
.body("StopInstancesResponse.instancesSet.item.instanceId", equalTo(instanceId))
.body("StopInstancesResponse.instancesSet.item.currentState.name", equalTo("stopping"));
.body("StopInstancesResponse.instancesSet.item.currentState.name", equalTo("stopping"))
.body("StopInstancesResponse.instancesSet.item.previousState.name", equalTo("running"));
}
@Test
@@ -3904,7 +3916,9 @@ class Ec2IntegrationTest {
.then()
.statusCode(200)
.body("StartInstancesResponse.instancesSet.item.instanceId", equalTo(instanceId))
.body("StartInstancesResponse.instancesSet.item.currentState.name", equalTo("pending"));
.body("StartInstancesResponse.instancesSet.item.currentState.name", equalTo("pending"))
.body("StartInstancesResponse.instancesSet.item.previousState.name", anyOf(
equalTo("stopped"), equalTo("stopping"), equalTo("running")));
}
@Test
@@ -4650,7 +4664,22 @@ class Ec2IntegrationTest {
.then()
.statusCode(200)
.body("TerminateInstancesResponse.instancesSet.item.instanceId", equalTo(instanceId))
.body("TerminateInstancesResponse.instancesSet.item.currentState.name", equalTo("shutting-down"));
.body("TerminateInstancesResponse.instancesSet.item.currentState.name", equalTo("shutting-down"))
.body("TerminateInstancesResponse.instancesSet.item.previousState.name", notNullValue());
}
@Test
@Order(101)
void startTerminatedInstanceFails() {
given()
.formParam("Action", "StartInstances")
.formParam("InstanceId.1", instanceId)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(400)
.body("Response.Errors.Error.Code", equalTo("IncorrectInstanceState"));
}
@Test
@@ -4840,10 +4869,322 @@ class Ec2IntegrationTest {
.statusCode(200);
}
// =========================================================================
// Launch options: user data, instance profiles, key pairs, counts, tags
// =========================================================================
@Test
@Order(110)
void runInstancesWithUserData() {
String script = "#!/bin/bash\necho hello > /tmp/test.txt";
String encoded = Base64.getEncoder().encodeToString(script.getBytes(StandardCharsets.UTF_8));
instanceWithUserData = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("UserData", encoded)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item.imageId", equalTo("ami-amazonlinux2023"))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
launchedInstances.add(instanceWithUserData);
}
@Test
@Order(111)
void describeInstanceLaunchedWithUserData() {
given()
.formParam("Action", "DescribeInstances")
.formParam("InstanceId.1", instanceWithUserData)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceId",
equalTo(instanceWithUserData))
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceState.name",
equalTo("running"));
}
@Test
@Order(112)
void runInstancesWithIamInstanceProfile() {
String profileArn = "arn:aws:iam::000000000000:instance-profile/" + PROFILE_BY_ARN;
given().header("Authorization", IAM_AUTH_HEADER)
.formParam("Action", "CreateInstanceProfile").formParam("InstanceProfileName", PROFILE_BY_ARN)
.post("/").then().statusCode(200);
instanceWithProfile = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-ubuntu2204")
.formParam("InstanceType", "t3.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("IamInstanceProfile.Arn", profileArn)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item.instanceType", equalTo("t3.micro"))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
launchedInstances.add(instanceWithProfile);
}
@Test
@Order(113)
void describeInstanceWithProfile() {
given()
.formParam("Action", "DescribeInstances")
.formParam("InstanceId.1", instanceWithProfile)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceId",
equalTo(instanceWithProfile))
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceState.name",
equalTo("running"));
}
@Test
@Order(114)
void runInstancesWithIamInstanceProfileName() {
given().header("Authorization", IAM_AUTH_HEADER)
.formParam("Action", "CreateInstanceProfile").formParam("InstanceProfileName", PROFILE_BY_NAME)
.post("/").then().statusCode(200);
instanceWithProfileName = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-ubuntu2204")
.formParam("InstanceType", "t3.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("IamInstanceProfile.Name", PROFILE_BY_NAME)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item.iamInstanceProfile.arn",
equalTo("arn:aws:iam::000000000000:instance-profile/" + PROFILE_BY_NAME))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
launchedInstances.add(instanceWithProfileName);
}
@Test
@Order(115)
void describeInstanceWithProfileName() {
given()
.formParam("Action", "DescribeInstances")
.formParam("InstanceId.1", instanceWithProfileName)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceId",
equalTo(instanceWithProfileName))
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.iamInstanceProfile.arn",
equalTo("arn:aws:iam::000000000000:instance-profile/" + PROFILE_BY_NAME));
}
@Test
@Order(116)
void importKeyPairForSsh() {
// AWS wire format: PublicKeyMaterial must be base64-encoded. The key has to be whole, as
// ImportKeyPair refuses a truncated blob.
String publicKey = Ec2KeyMaterial.generateRsa().openSshPublicKey() + " test@test";
String encodedKey = Base64.getEncoder().encodeToString(publicKey.getBytes(StandardCharsets.UTF_8));
given()
.formParam("Action", "ImportKeyPair")
.formParam("KeyName", LAUNCH_KEY_NAME)
.formParam("PublicKeyMaterial", encodedKey)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("ImportKeyPairResponse.keyName", equalTo(LAUNCH_KEY_NAME))
.body("ImportKeyPairResponse.keyPairId", startsWith("key-"));
}
@Test
@Order(117)
void runInstancesWithImportedKey() {
String launched = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("KeyName", LAUNCH_KEY_NAME)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item.keyName", equalTo(LAUNCH_KEY_NAME))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
launchedInstances.add(launched);
}
@Test
@Order(118)
void runMultipleInstances() {
List<String> launched = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "2")
.formParam("MaxCount", "2")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.size()", equalTo(2))
.body("RunInstancesResponse.instancesSet.item[0].instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item[1].instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item[0].amiLaunchIndex", equalTo("0"))
.body("RunInstancesResponse.instancesSet.item[1].amiLaunchIndex", equalTo("1"))
.extract().xmlPath().getList("RunInstancesResponse.instancesSet.item.instanceId", String.class);
launchedInstances.addAll(launched);
}
@Test
@Order(119)
void runInstancesWithTagSpecification() {
String tagged = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("TagSpecification.1.ResourceType", "instance")
.formParam("TagSpecification.1.Tag.1.Key", "Env")
.formParam("TagSpecification.1.Tag.1.Value", "test")
.formParam("TagSpecification.1.Tag.2.Key", "Name")
.formParam("TagSpecification.1.Tag.2.Value", "tag-specification-instance")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item.tagSet.item.find { it.key == 'Env' }.value",
equalTo("test"))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
launchedInstances.add(tagged);
given()
.formParam("Action", "DescribeInstances")
.formParam("InstanceId.1", tagged)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.tagSet.item.size()",
equalTo(2));
}
@Test
@Order(120)
void runInstancesDefaultPlacement() {
String placed = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "m5.large")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceType", equalTo("m5.large"))
.body("RunInstancesResponse.instancesSet.item.placement.availabilityZone",
startsWith("us-east-1"))
.body("RunInstancesResponse.instancesSet.item.privateIpAddress", not(emptyOrNullString()))
.body("RunInstancesResponse.instancesSet.item.vpcId", not(emptyOrNullString()))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
launchedInstances.add(placed);
}
@Test
@Order(121)
void cleanupLaunchOptionResources() {
RequestSpecification terminate = given()
.formParam("Action", "TerminateInstances")
.header("Authorization", AUTH_HEADER);
for (int i = 0; i < launchedInstances.size(); i++) {
terminate.formParam("InstanceId." + (i + 1), launchedInstances.get(i));
}
terminate.when().post("/").then().statusCode(200);
launchedInstances.clear();
given()
.formParam("Action", "DeleteKeyPair")
.formParam("KeyName", LAUNCH_KEY_NAME)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200);
for (String profile : List.of(PROFILE_BY_ARN, PROFILE_BY_NAME)) {
given().header("Authorization", IAM_AUTH_HEADER)
.formParam("Action", "DeleteInstanceProfile").formParam("InstanceProfileName", profile)
.post("/").then().statusCode(200);
}
}
// =========================================================================
// Error cases
// =========================================================================
@Test
@Order(200)
void terminateNonExistentInstance() {
given()
.formParam("Action", "TerminateInstances")
.formParam("InstanceId.1", "i-0000000000000dead")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(400)
.body("Response.Errors.Error.Code", equalTo("InvalidInstanceID.NotFound"));
}
@Test
@Order(200)
void stopNonExistentInstance() {
given()
.formParam("Action", "StopInstances")
.formParam("InstanceId.1", "i-0000000000000dead")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(400)
.body("Response.Errors.Error.Code", equalTo("InvalidInstanceID.NotFound"));
}
@Test
@Order(200)
void describeNonExistentInstance() {
@@ -1,438 +0,0 @@
package io.floci.aws.services.ec2;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.util.Base64;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
/**
* Integration tests for EC2 Phase 2 features:
* - UserData parsing from base64 wire format
* - IamInstanceProfile.Arn stored on instance
* - SSH key import and key name association
* - State transitions (stop/start/terminate/reboot)
* - DescribeInstances with state filters
* - Error on StartInstances for terminated instance
* - Multiple instance launch (MinCount/MaxCount)
*
* All tests run in mock mode (floci.services.ec2.mock=true in test application.yml)
* so no real Docker is required.
*/
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class Ec2Phase2IntegrationTest {
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/ec2/aws4_request";
private static String instanceWithUserData;
private static String instanceWithProfile;
private static String instanceWithProfileName;
private static String instanceForTerminate;
private static String importedKeyName = "phase2-imported-key";
// ─── UserData ──────────────────────────────────────────────────────────────
@Test
@Order(1)
void runInstancesWithUserData() {
String script = "#!/bin/bash\necho hello > /tmp/test.txt";
String encoded = Base64.getEncoder().encodeToString(script.getBytes());
instanceWithUserData = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("UserData", encoded)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item.imageId", equalTo("ami-amazonlinux2023"))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
}
@Test
@Order(2)
void describeInstanceLaunchedWithUserData() {
given()
.formParam("Action", "DescribeInstances")
.formParam("InstanceId.1", instanceWithUserData)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceId",
equalTo(instanceWithUserData))
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceState.name",
equalTo("running"));
}
// ─── IamInstanceProfile ────────────────────────────────────────────────────
@Test
@Order(10)
void runInstancesWithIamInstanceProfile() {
String profileArn = "arn:aws:iam::000000000000:instance-profile/my-app-role";
given().header("Authorization", AUTH_HEADER.replace("/ec2/", "/iam/"))
.formParam("Action", "CreateInstanceProfile").formParam("InstanceProfileName", "my-app-role")
.post("/").then().statusCode(200);
instanceWithProfile = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-ubuntu2204")
.formParam("InstanceType", "t3.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("IamInstanceProfile.Arn", profileArn)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item.instanceType", equalTo("t3.micro"))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
}
@Test
@Order(11)
void describeInstanceWithProfile() {
given()
.formParam("Action", "DescribeInstances")
.formParam("InstanceId.1", instanceWithProfile)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceId",
equalTo(instanceWithProfile))
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceState.name",
equalTo("running"));
}
@Test
@Order(12)
void runInstancesWithIamInstanceProfileName() {
String profileName = "my-app-profile";
given().header("Authorization", AUTH_HEADER.replace("/ec2/", "/iam/")).formParam("Action", "CreateInstanceProfile")
.formParam("InstanceProfileName", profileName).post("/").then().statusCode(200);
instanceWithProfileName = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-ubuntu2204")
.formParam("InstanceType", "t3.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("IamInstanceProfile.Name", profileName)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item.iamInstanceProfile.arn",
equalTo("arn:aws:iam::000000000000:instance-profile/" + profileName))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
}
@Test
@Order(13)
void describeInstanceWithProfileName() {
given()
.formParam("Action", "DescribeInstances")
.formParam("InstanceId.1", instanceWithProfileName)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceId",
equalTo(instanceWithProfileName))
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.iamInstanceProfile.arn",
equalTo("arn:aws:iam::000000000000:instance-profile/my-app-profile"));
}
// ─── SSH key import ────────────────────────────────────────────────────────
@Test
@Order(20)
void importKeyPairForSsh() {
// AWS wire format: PublicKeyMaterial must be base64-encoded. The key has to be whole, as
// ImportKeyPair refuses a truncated blob.
String publicKey = Ec2KeyMaterial.generateRsa().openSshPublicKey() + " test@test";
String encodedKey = Base64.getEncoder().encodeToString(publicKey.getBytes());
given()
.formParam("Action", "ImportKeyPair")
.formParam("KeyName", importedKeyName)
.formParam("PublicKeyMaterial", encodedKey)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("ImportKeyPairResponse.keyName", equalTo(importedKeyName))
.body("ImportKeyPairResponse.keyPairId", startsWith("key-"));
}
@Test
@Order(21)
void runInstancesWithImportedKey() {
given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("KeyName", importedKeyName)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item.keyName", equalTo(importedKeyName));
}
// ─── Multiple instances ────────────────────────────────────────────────────
@Test
@Order(30)
void runMultipleInstances() {
given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "2")
.formParam("MaxCount", "2")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.size()", equalTo(2))
.body("RunInstancesResponse.instancesSet.item[0].instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item[1].instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item[0].amiLaunchIndex", equalTo("0"))
.body("RunInstancesResponse.instancesSet.item[1].amiLaunchIndex", equalTo("1"));
}
// ─── State filters ─────────────────────────────────────────────────────────
@Test
@Order(40)
void describeRunningInstancesWithFilter() {
given()
.formParam("Action", "DescribeInstances")
.formParam("Filter.1.Name", "instance-state-name")
.formParam("Filter.1.Value.1", "running")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("DescribeInstancesResponse.reservationSet.item.size()", greaterThanOrEqualTo(1));
}
// ─── Lifecycle: stop/start/terminate ──────────────────────────────────────
@Test
@Order(50)
void runInstanceForTermination() {
instanceForTerminate = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
}
@Test
@Order(51)
void stopInstance() {
given()
.formParam("Action", "StopInstances")
.formParam("InstanceId.1", instanceForTerminate)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("StopInstancesResponse.instancesSet.item.instanceId", equalTo(instanceForTerminate))
.body("StopInstancesResponse.instancesSet.item.currentState.name", equalTo("stopping"))
.body("StopInstancesResponse.instancesSet.item.previousState.name", equalTo("running"));
}
@Test
@Order(52)
void startInstance() {
given()
.formParam("Action", "StartInstances")
.formParam("InstanceId.1", instanceForTerminate)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("StartInstancesResponse.instancesSet.item.instanceId", equalTo(instanceForTerminate))
.body("StartInstancesResponse.instancesSet.item.currentState.name", equalTo("pending"))
.body("StartInstancesResponse.instancesSet.item.previousState.name", anyOf(
equalTo("stopped"), equalTo("stopping"), equalTo("running")));
}
@Test
@Order(53)
void terminateInstance() {
given()
.formParam("Action", "TerminateInstances")
.formParam("InstanceId.1", instanceForTerminate)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("TerminateInstancesResponse.instancesSet.item.instanceId", equalTo(instanceForTerminate))
.body("TerminateInstancesResponse.instancesSet.item.currentState.name", equalTo("shutting-down"))
.body("TerminateInstancesResponse.instancesSet.item.previousState.name", notNullValue());
}
@Test
@Order(54)
void startTerminatedInstanceFails() {
given()
.formParam("Action", "StartInstances")
.formParam("InstanceId.1", instanceForTerminate)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(400)
.body("Response.Errors.Error.Code", equalTo("IncorrectInstanceState"));
}
// ─── TagSpecification on RunInstances ─────────────────────────────────────
@Test
@Order(60)
void runInstancesWithTagSpecification() {
String instanceId = given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "t2.micro")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.formParam("TagSpecification.1.ResourceType", "instance")
.formParam("TagSpecification.1.Tag.1.Key", "Env")
.formParam("TagSpecification.1.Tag.1.Value", "test")
.formParam("TagSpecification.1.Tag.2.Key", "Name")
.formParam("TagSpecification.1.Tag.2.Value", "phase2-test-instance")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceId", startsWith("i-"))
.body("RunInstancesResponse.instancesSet.item.tagSet.item.find { it.key == 'Env' }.value",
equalTo("test"))
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
// Verify tags appear in DescribeInstances
given()
.formParam("Action", "DescribeInstances")
.formParam("InstanceId.1", instanceId)
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.tagSet.item.size()",
equalTo(2));
}
// ─── Instance type and placement ──────────────────────────────────────────
@Test
@Order(70)
void runInstancesDefaultPlacement() {
given()
.formParam("Action", "RunInstances")
.formParam("ImageId", "ami-amazonlinux2023")
.formParam("InstanceType", "m5.large")
.formParam("MinCount", "1")
.formParam("MaxCount", "1")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(200)
.body("RunInstancesResponse.instancesSet.item.instanceType", equalTo("m5.large"))
.body("RunInstancesResponse.instancesSet.item.placement.availabilityZone",
startsWith("us-east-1"))
.body("RunInstancesResponse.instancesSet.item.privateIpAddress", not(emptyOrNullString()))
.body("RunInstancesResponse.instancesSet.item.vpcId", not(emptyOrNullString()));
}
// ─── Error: invalid instance ID ──────────────────────────────────────────
@Test
@Order(80)
void terminateNonExistentInstance() {
given()
.formParam("Action", "TerminateInstances")
.formParam("InstanceId.1", "i-nonexistent1234567890")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(400)
.body("Response.Errors.Error.Code", equalTo("InvalidInstanceID.NotFound"));
}
@Test
@Order(81)
void stopNonExistentInstance() {
given()
.formParam("Action", "StopInstances")
.formParam("InstanceId.1", "i-nonexistent1234567890")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(400)
.body("Response.Errors.Error.Code", equalTo("InvalidInstanceID.NotFound"));
}
@Test
@Order(82)
void describeNonExistentInstance() {
given()
.formParam("Action", "DescribeInstances")
.formParam("InstanceId.1", "i-nonexistent1234567890")
.header("Authorization", AUTH_HEADER)
.when()
.post("/")
.then()
.statusCode(400)
.body("Response.Errors.Error.Code", equalTo("InvalidInstanceID.NotFound"));
}
}
@@ -1,72 +0,0 @@
package io.floci.aws.services.lambda;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class LambdaCodeSigningConfigIntegrationTest {
private static final String BASE_PATH = "/2015-03-31";
private static final String CODE_SIGNING_PATH = "/2020-06-30";
private static final String FUNCTION_NAME = "code-signing-test-function";
@Test
@Order(1)
void createFunction() {
given()
.contentType("application/json")
.body(String.format("""
{
"FunctionName": "%s",
"Runtime": "nodejs20.x",
"Role": "arn:aws:iam::000000000000:role/lambda-role",
"Handler": "index.handler",
"Description": "Code signing config test function"
}
""", FUNCTION_NAME))
.when()
.post(BASE_PATH + "/functions")
.then()
.statusCode(201)
.body("FunctionName", equalTo(FUNCTION_NAME));
}
@Test
@Order(2)
void getFunctionCodeSigningConfig() {
given()
.when()
.get(CODE_SIGNING_PATH + "/functions/" + FUNCTION_NAME + "/code-signing-config")
.then()
.statusCode(200)
.body("FunctionName", equalTo(FUNCTION_NAME))
.body("CodeSigningConfigArn", notNullValue());
}
@Test
@Order(3)
void getFunctionCodeSigningConfigNotFound() {
given()
.when()
.get(CODE_SIGNING_PATH + "/functions/nonexistent-function/code-signing-config")
.then()
.statusCode(404);
}
@Test
@Order(4)
void cleanup() {
given()
.when()
.delete(BASE_PATH + "/functions/" + FUNCTION_NAME)
.then()
.statusCode(204);
}
}
@@ -1,33 +0,0 @@
package io.floci.aws.services.s3;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
@QuarkusTest
class FilterTest {
@Test
void testFilterWithQuery() {
given()
.header("Host", "my-bucket.localhost:4566")
.when()
.put("/")
.then()
.statusCode(200);
String xml = "<Delete><Object><Key>test</Key></Object></Delete>";
given()
.header("Host", "my-bucket.localhost:4566")
.queryParam("delete", "")
.contentType("application/xml")
.body(xml)
.log().all()
.when()
.post("/")
.then()
.log().all()
.statusCode(200);
}
}
@@ -1,19 +0,0 @@
package io.floci.aws.services.s3;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
@QuarkusTest
class S3DumpTest {
@Test
void dump() {
given()
.header("Host", "mybucket.s3.amazonaws.com")
.when()
.post("/?delete")
.then()
.log().all();
}
}
@@ -1,18 +0,0 @@
package io.floci.aws.services.s3;
import jakarta.ws.rs.core.UriBuilder;
import org.junit.jupiter.api.Test;
import java.net.URI;
import static org.junit.jupiter.api.Assertions.assertEquals;
class UriBuilderTest {
@Test
void testUriBuilder() {
URI uri = URI.create("http://host/?delete");
URI newUri = UriBuilder.fromUri(uri).replacePath("/b/").build();
System.out.println("NEW URI: " + newUri.toString());
System.out.println("NEW URI QUERY: " + newUri.getQuery());
}
}