mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ec2): DescribeKeyPairs returns InvalidKeyPair.NotFound for missing names/ids (#1932)
DescribeKeyPairs returned an empty list (HTTP 200 / CLI exit 0) when a requested KeyName or KeyPairId did not exist, instead of the documented InvalidKeyPair.NotFound fault. Idempotent callers that treat exit 0 as "present" then skip creating the key pair. Fail with InvalidKeyPair.NotFound (400) when any explicitly requested name or id does not resolve, while an unfiltered describe on an empty account still returns an empty list. Fixes #1911
This commit is contained in:
1 parent
a4356f25fb
commit
7d961068e1
3 files changed
+78
-1
No files matched your search
@@ -930,6 +930,20 @@ class Ec2IntegrationTest {
|
||||
.body("DescribeKeyPairsResponse.keySet.item.keyName", equalTo("test-key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(41)
|
||||
void describeKeyPairsRejectsMissingName() {
|
||||
given()
|
||||
.formParam("Action", "DescribeKeyPairs")
|
||||
.formParam("KeyName.1", "does-not-exist")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidKeyPair.NotFound"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(39)
|
||||
void importKeyPair() {
|
||||
|
||||
@@ -297,6 +297,50 @@ class Ec2ServiceTest {
|
||||
assertEquals("InvalidKeyPair.Duplicate", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeKeyPairsThrowsNotFoundForMissingName() {
|
||||
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
mock(Ec2PortForwardManager.class),
|
||||
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
|
||||
new InMemoryStorageFactory());
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.describeKeyPairs("us-east-1", List.of("does-not-exist"), List.of()));
|
||||
assertEquals("InvalidKeyPair.NotFound", error.getErrorCode());
|
||||
assertEquals(400, error.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeKeyPairsThrowsNotFoundForMissingId() {
|
||||
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
mock(Ec2PortForwardManager.class),
|
||||
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
|
||||
new InMemoryStorageFactory());
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.describeKeyPairs("us-east-1", List.of(), List.of("key-missing")));
|
||||
assertEquals("InvalidKeyPair.NotFound", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeKeyPairsReturnsRequestedKeyAndAllowsEmptyUnfilteredList() {
|
||||
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
mock(Ec2PortForwardManager.class),
|
||||
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
|
||||
new InMemoryStorageFactory());
|
||||
|
||||
// Unfiltered describe on an empty account is not an error.
|
||||
assertTrue(service.describeKeyPairs("us-east-1", List.of(), List.of()).isEmpty());
|
||||
|
||||
service.createKeyPair("us-east-1", "present-key");
|
||||
assertEquals(1, service.describeKeyPairs("us-east-1", List.of("present-key"), List.of()).size());
|
||||
|
||||
// A missing name is not masked by a present one in the same request.
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.describeKeyPairs("us-east-1", List.of("present-key", "absent-key"), List.of()));
|
||||
assertEquals("InvalidKeyPair.NotFound", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerImageReusingSnapshotDoesNotOverwriteSnapshotMetadata() {
|
||||
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
|
||||
Reference in new issue
Block a user