mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(apigateway): complete API Gateway API key responses (#3817)
Return timestamps, stage keys, tags, and customer ID across create, get, list, and update operations to prevent Terraform provider crashes and state drift. Generate opaque IDs by default while preserving legacy generateDistinctId=false behavior. Keep API key values hidden unless explicitly requested. Add REST, SDK, and CloudFormation regression coverage.
This commit is contained in:
1 parent
30b491a546
commit
ad20699a6b
9 files changed
+244
-71
No files matched your search
+91
@@ -0,0 +1,91 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.apigateway.ApiGatewayClient;
|
||||
import software.amazon.awssdk.services.apigateway.model.ApiKey;
|
||||
import software.amazon.awssdk.services.apigateway.model.CreateApiKeyResponse;
|
||||
import software.amazon.awssdk.services.apigateway.model.GetApiKeyResponse;
|
||||
import software.amazon.awssdk.services.apigateway.model.GetApiKeysResponse;
|
||||
import software.amazon.awssdk.services.apigateway.model.PatchOperation;
|
||||
import software.amazon.awssdk.services.apigateway.model.UpdateApiKeyResponse;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DisplayName("API Gateway API keys")
|
||||
class ApiGatewayApiKeyCompatibilityTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("API key responses expose the complete AWS SDK shape")
|
||||
void apiKeyResponsesExposeCompleteShape() {
|
||||
ApiGatewayClient apiGateway = TestFixtures.apiGatewayClient();
|
||||
String value = "11112222333344445555666677778888";
|
||||
CreateApiKeyResponse created = apiGateway.createApiKey(request -> request
|
||||
.name(TestFixtures.uniqueName("apigw-key"))
|
||||
.enabled(true)
|
||||
.customerId("marketplace-customer-1")
|
||||
.value(value));
|
||||
|
||||
try {
|
||||
assertThat(created.id()).isNotBlank().isNotEqualTo(value);
|
||||
assertThat(created.value()).isEqualTo(value);
|
||||
assertThat(created.customerId()).isEqualTo("marketplace-customer-1");
|
||||
assertCompleteShape(created.createdDate(), created.lastUpdatedDate(),
|
||||
created.hasStageKeys(), created.stageKeys(), created.hasTags(), created.tags());
|
||||
|
||||
GetApiKeyResponse read = apiGateway.getApiKey(request -> request.apiKey(created.id()));
|
||||
assertThat(read.value()).isNull();
|
||||
assertThat(read.customerId()).isEqualTo("marketplace-customer-1");
|
||||
assertCompleteShape(read.createdDate(), read.lastUpdatedDate(),
|
||||
read.hasStageKeys(), read.stageKeys(), read.hasTags(), read.tags());
|
||||
|
||||
GetApiKeyResponse readWithValue = apiGateway.getApiKey(request -> request
|
||||
.apiKey(created.id())
|
||||
.includeValue(true));
|
||||
assertThat(readWithValue.value()).isEqualTo(value);
|
||||
|
||||
GetApiKeysResponse listed = apiGateway.getApiKeys();
|
||||
ApiKey listedKey = listed.items().stream()
|
||||
.filter(key -> created.id().equals(key.id()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
assertThat(listedKey.value()).isNull();
|
||||
assertThat(listedKey.customerId()).isEqualTo("marketplace-customer-1");
|
||||
assertCompleteShape(listedKey.createdDate(), listedKey.lastUpdatedDate(),
|
||||
listedKey.hasStageKeys(), listedKey.stageKeys(), listedKey.hasTags(), listedKey.tags());
|
||||
|
||||
UpdateApiKeyResponse updated = apiGateway.updateApiKey(request -> request
|
||||
.apiKey(created.id())
|
||||
.patchOperations(PatchOperation.builder()
|
||||
.op("replace")
|
||||
.path("/customerId")
|
||||
.value("marketplace-customer-2")
|
||||
.build()));
|
||||
assertThat(updated.value()).isNull();
|
||||
assertThat(updated.customerId()).isEqualTo("marketplace-customer-2");
|
||||
assertCompleteShape(updated.createdDate(), updated.lastUpdatedDate(),
|
||||
updated.hasStageKeys(), updated.stageKeys(), updated.hasTags(), updated.tags());
|
||||
} finally {
|
||||
apiGateway.deleteApiKey(request -> request.apiKey(created.id()));
|
||||
apiGateway.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertCompleteShape(Instant createdDate,
|
||||
Instant lastUpdatedDate,
|
||||
boolean hasStageKeys,
|
||||
List<String> stageKeys,
|
||||
boolean hasTags,
|
||||
Map<String, String> tags) {
|
||||
assertThat(createdDate).isNotNull();
|
||||
assertThat(lastUpdatedDate).isNotNull();
|
||||
assertThat(hasStageKeys).isTrue();
|
||||
assertThat(stageKeys).isEmpty();
|
||||
assertThat(hasTags).isTrue();
|
||||
assertThat(tags).isEmpty();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user