feat(marketplace-reporting): emulate AWS Marketplace Reporting API (#3343)

This commit is contained in:
Franklin G. Mendoza authored and GitHub committed 2026-09-11 09:15:23 -04:00
1 parent ee23e26bc3
commit 3c080e1ea6
11 files changed
+259 -1

No files matched your search

@@ -0,0 +1,44 @@
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.equalTo;
import static org.hamcrest.Matchers.notNullValue;
@QuarkusTest
class MarketplaceReportingIntegrationTest {
@BeforeAll static void configure() { RestAssuredJsonUtils.configureAwsContentTypes(); }
@Test
void getBuyerDashboardReturnsEmbeddingUrl() {
String dashboard = "arn:aws:aws-marketplace::000000000000:AWSMarketplace/ReportingData/Agreement_V1/Dashboard/AgreementSummary_V1";
given().contentType("application/json").header("Authorization", auth())
.body("{\"dashboardIdentifier\":\"" + dashboard + "\",\"embeddingDomains\":[\"https://example.com\"]}")
.post("/getBuyerDashboard").then().statusCode(200)
.body("dashboardIdentifier", equalTo(dashboard)).body("embedUrl", notNullValue())
.body("embeddingDomains[0]", equalTo("https://example.com"));
}
@Test
void rejectsTrailingJson() {
given().contentType("application/json").header("Authorization", auth())
.body("{} {}")
.post("/getBuyerDashboard").then().statusCode(400)
.body("__type", containsString("BadRequestException"));
}
@Test
void rejectsUnsupportedDashboardArn() {
given().contentType("application/json").header("Authorization", auth())
.body("{\"dashboardIdentifier\":\"bad\",\"embeddingDomains\":[\"https://example.com\"]}")
.post("/getBuyerDashboard").then().statusCode(400)
.body("__type", containsString("BadRequestException"));
}
private static String auth() { return "AWS4-HMAC-SHA256 Credential=000000000000/20260908/us-east-1/aws-marketplace/aws4_request"; }
}
@@ -0,0 +1,33 @@
package io.github.hectorvent.floci.services.marketplace;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class MarketplaceReportingServiceTest {
private final ObjectMapper mapper = new ObjectMapper();
private final MarketplaceReportingService service = new MarketplaceReportingService(mapper);
@Test
void getBuyerDashboardBuildsAccountScopedEmbedUrl() throws Exception {
var response = service.getBuyerDashboard(mapper.readTree("""
{"dashboardIdentifier":"arn:aws:aws-marketplace::123456789012:AWSMarketplace/ReportingData/Agreement_V1/Dashboard/AgreementSummary_V1",
"embeddingDomains":["https://example.com"]}
"""), "123456789012");
assertTrue(response.path("embedUrl").asText().contains("accounts/123456789012/dashboards/AgreementSummary_V1"));
assertEquals("https://example.com", response.path("embeddingDomains").get(0).asText());
}
@Test
void invalidDomainsAreRejected() throws Exception {
AwsException error = assertThrows(AwsException.class, () -> service.getBuyerDashboard(mapper.readTree("""
{"dashboardIdentifier":"arn:aws:aws-marketplace::123456789012:AWSMarketplace/ReportingData/Agreement_V1/Dashboard/AgreementSummary_V1",
"embeddingDomains":["javascript:alert(1)"]}
"""), "123456789012"));
assertEquals("BadRequestException", error.getErrorCode());
}
}