mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(marketplace-entitlement): emulate AWS Marketplace Entitlement API (#3340)
This commit is contained in:
1 parent
3090e333d4
commit
87f2c2d1a8
13 files changed
+425
-4
No files matched your search
+61
@@ -0,0 +1,61 @@
|
||||
package io.github.hectorvent.floci.services.marketplace;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
|
||||
@QuarkusTest
|
||||
class MarketplaceEntitlementIntegrationTest {
|
||||
@BeforeAll
|
||||
static void configure() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getEntitlementsReturnsEmptySetForUnknownProduct() {
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("Authorization", auth("us-east-1"))
|
||||
.header("X-Amz-Target", "AWSMPEntitlementService.GetEntitlements")
|
||||
.body("{\"ProductCode\":\"product-local\"}")
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Entitlements", empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getEntitlementsRejectsMutuallyExclusiveCustomerFilters() {
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("Authorization", auth("us-east-1"))
|
||||
.header("X-Amz-Target", "AWSMPEntitlementService.GetEntitlements")
|
||||
.body("{\"ProductCode\":\"product-local\",\"Filter\":{\"CUSTOMER_IDENTIFIER\":[\"customer\"],\"CUSTOMER_AWS_ACCOUNT_ID\":[\"123456789012\"]}}")
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("InvalidParameterException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void entitlementEndpointRejectsUnsupportedRegion() {
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("Authorization", auth("us-west-2"))
|
||||
.header("X-Amz-Target", "AWSMPEntitlementService.GetEntitlements")
|
||||
.body("{\"ProductCode\":\"product-local\"}")
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("InvalidParameterException"));
|
||||
}
|
||||
|
||||
private static String auth(String region) {
|
||||
return "AWS4-HMAC-SHA256 Credential=000000000000/20260908/" + region + "/aws-marketplace/aws4_request";
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package io.github.hectorvent.floci.services.marketplace;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class MarketplaceEntitlementServiceTest {
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private AccountAwareStorageBackend<JsonNode> storage;
|
||||
private MarketplaceEntitlementService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
storage = AccountAwareStorageBackend.inMemory("000000000000");
|
||||
service = new MarketplaceEntitlementService(mapper, storage);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getEntitlementsReadsSharedReadOnlyStateAndAppliesFilters() throws Exception {
|
||||
storage.put("product-local/ent-1", mapper.readTree("""
|
||||
{"ProductCode":"product-local","Dimension":"users","CustomerAWSAccountId":"123456789012",
|
||||
"LicenseArn":"arn:aws:license-manager:us-east-1:123456789012:license:l-local",
|
||||
"Value":{"IntegerValue":10}}
|
||||
"""));
|
||||
storage.put("product-local/ent-2", mapper.readTree("""
|
||||
{"ProductCode":"product-local","Dimension":"storage","CustomerAWSAccountId":"999999999999",
|
||||
"Value":{"IntegerValue":5}}
|
||||
"""));
|
||||
|
||||
JsonNode response = service.getEntitlements(mapper.readTree("""
|
||||
{"ProductCode":"product-local","Filter":{"CUSTOMER_AWS_ACCOUNT_ID":["123456789012"]}}
|
||||
"""), "us-east-1");
|
||||
assertEquals(1, response.path("Entitlements").size());
|
||||
assertEquals("users", response.path("Entitlements").get(0).path("Dimension").asText());
|
||||
assertEquals("123456789012",
|
||||
response.path("Entitlements").get(0).path("CustomerAWSAccountId").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void maxResultsMustBeIntegral() throws Exception {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.getEntitlements(mapper.readTree(
|
||||
"{\"ProductCode\":\"product-local\",\"MaxResults\":1.5}"), "us-east-1"));
|
||||
assertEquals("InvalidParameterException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void maxResultsRejectsIntegralOverflow() throws Exception {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.getEntitlements(mapper.readTree(
|
||||
"{\"ProductCode\":\"product-local\",\"MaxResults\":4294967297}"), "us-east-1"));
|
||||
assertEquals("InvalidParameterException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void productCodeAndRegionFollowAwsConstraints() throws Exception {
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.getEntitlements(mapper.readTree("{\"ProductCode\":\"\"}"), "us-east-1"));
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.getEntitlements(mapper.readTree("{\"ProductCode\":\"product-local\"}"), "us-west-2"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user