mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(servicecatalog): emulate AWS Service Catalog with Control Tower Account Factory (#2585)
* feat: emulate AWS Service Catalog * docs: register Service Catalog service * feat(servicecatalog): full API parity for 55 operations Closes the entire botocore servicecatalog gap surface found by a full-manifest scan (56 ops; 55 landed, DescribeServiceAction escalated because no store exists for it and a single write op may not invent one). Each operation is dispatch-reachable, covered by a wire-level test asserting response values (not just status codes), and falsifiability-checked at method granularity. Tests are one class per operation family so falsification isolates per operation. Nine previously-unshipped bugs surfaced and fixed along the way, recorded as issues 0017-0025: wrong field names in describeConstraint, three incompatible service-action association keys across the single-op and batch-op pairs, a Type discriminator collision leaking phantom entries into ListServiceActions, the provisioned-product-plan family having no persistence at all, five cases of an operation returning a generated id (RecordId, CopyProductToken, plan ids) that nothing ever persisted, a hardcoded-empty ListConstraintsForPortfolio, and TerminateProvisionedProduct reporting the wrong RecordType. Limitations documented in docs/services/service-catalog.md. * chore: drop local-only bug-ledger files before upstream issues/0017-0025 are this fork's internal tracking, not something upstream has a convention for. * fix(config): restore EmrServerless config body lost in rebase The rebase onto upstream/main collided where both upstream and this branch declare a new service config interface sharing a trailing body; the EmrServerless interface was left open, so the file did not parse. * docs: state a single correct service count Collapse the duplicated claim left by the docs merge to one number matching the 74 services this branch registers. * fix(servicecatalog): adapt to upstream's Organizations model (OrganizationAccount, 5-arg createAccount) * docs(servicecatalog): register the generated action table * docs(servicecatalog): correct action descriptions after audit * docs(servicecatalog): name the real Control Tower catalog triggers * fix(servicecatalog): reject missing identifiers instead of failing with 500 Store lookups passed the request's identifier straight through to the backing map, so an operation called without its id parameter died on a null key and surfaced as InternalFailure. Guard the lookup helpers and name the missing parameter in an InvalidParametersException. * fix(servicecatalog): report a plan's own identifiers in its plan details DescribeProvisionedProductPlan and ListProvisionedProductPlans reused the plan's own id and provisioned-product name for ProvisionProductId and PlanName, so callers could never recover the product a plan targets or the plan's name. Read the distinct fields the plan already stores. * fix(servicecatalog): require ProvisionProduct to name a real product ProvisionProduct ignored ProductId and ProductName, so every request took the Control Tower Account Factory path: an unrecognised product id still created an Organizations member account and recorded it under the seeded Account Factory identifiers. Resolve the target product and its provisioning artifact first, reject what the catalog does not hold, and touch Organizations only when the request really names Account Factory. Other stored products now provision a plain record. Product and artifact resolution is shared with DescribeProvisioningParameters, which already validated a request the same way. * docs: state one service count and ProvisionProduct's validated behaviour docs/index.md still claimed 74 services while docs/services/index.md, the canonical matrix, listed 77. The Service Catalog page also described ProvisionProduct taking the Account Factory path for every request, which stopped being true once it started resolving the product it was given. * fix(servicecatalog): resolve ProductId by product id only requireProduct also matches provisioning-artifact ids, so ProvisionProduct with ProductId set to the Account Factory artifact id resolved the owning product and created an Organizations account. resolveProduct now does a strict id lookup; artifact ids in ProductId get ResourceNotFoundException. * fix(servicecatalog): enforce the modeled enums and AccountId format on stored values Five request members were read and stored, or used as a filter, without the constraint botocore pins on them: - Create/Update/DeletePortfolioShare built the share's store key from AccountId and OrganizationNode.Type unchecked, so a short account id or a node type outside OrganizationNodeType became a share DescribePortfolioShares reported back verbatim. - CreateProvisionedProductPlan accepted any PlanType and then described the plan as CLOUDFORMATION, the only member ProvisionedProductPlanType has. - CreateServiceAction stored any DefinitionType, likewise a one-member enum. - DescribePortfolioShares and ListOrganizationPortfolioAccess filtered on an unvalidated type, turning a typo into an empty result rather than an error. * fix(servicecatalog): enforce the PrincipalType enum on principal association The model pins PrincipalType to IAM or IAM_PATTERN; the value was stored verbatim. Found by the botocore-grounded review pipeline on its first sweep — the hand audit of the same service missed it. * fix(servicecatalog): reject an ambiguous ProductName on ProvisionProduct Product names are not unique keys, so first-match could resolve a user-created product carrying the Account Factory name — or vice versa — and either skip or wrongly enter the Organizations account workflow. More than one match now raises the modeled DuplicateResourceException. * fix(servicecatalog): keep a missing AccountEmail inside the Service Catalog model ProvisionProduct passed AccountEmail straight to Organizations, so omitting it surfaced Organizations' InvalidInputException — a shape absent from Service Catalog's model — to a servicecatalog client, which cannot deserialize it into a typed exception. Validate it on the Account Factory path and raise the service's own InvalidParametersException, matching how the createAccount failure a few lines below is already translated. A plain stored product needs no email, so the guard sits inside accountFactoryAccountId rather than at the top of provisionProduct; a test pins that provisioning a non-Account-Factory product without AccountEmail still succeeds. * fix(servicecatalog): refuse to delete a portfolio or product that is in use DeletePortfolio and DeleteProduct deleted the resource and then cascaded, removing every association naming the portfolio and every share keyed to it. AWS refuses the call instead — a portfolio with associated products, users, constraints, or shared accounts, and a product associated with a portfolio, are both ResourceInUseException — so what AWS makes a recoverable no-op was here unrecoverable data loss reported as 200. The scans that drove the cascade now detect the in-use condition. Every row AWS lists for a portfolio carries PortfolioId, so one scan covers products, principals and constraints alike; the portfolio cascade is gone because it is now unreachable. Tag-option associations key off ResourceId, are absent from AWS's list, and were never cleaned by the old cascade either, so nothing is orphaned that was not orphaned before. For a product only the portfolio association blocks, so its remaining associations are still cleaned up on delete.
This commit is contained in:
1 parent
017e95d70a
commit
2e843e9f23
33 files changed
+6090
-5
No files matched your search
+1
@@ -84,6 +84,7 @@ class IamManagedPolicyAccountScopeTest {
|
||||
assertTrue(arns.contains(AwsManagedPolicies.ARN_PREFIX + "/AWSXRayDaemonWriteAccess"));
|
||||
assertTrue(arns.contains(AwsManagedPolicies.ARN_PREFIX + "/AWSCloudFormationReadOnlyAccess"));
|
||||
assertTrue(arns.contains(AwsManagedPolicies.ARN_PREFIX + "/AWSCloudFormationFullAccess"));
|
||||
assertTrue(arns.contains(AwsManagedPolicies.ARN_PREFIX + "/AWSServiceCatalogEndUserFullAccess"));
|
||||
assertTrue(arns.contains(AwsManagedPolicies.ARN_PREFIX + "/AmazonElasticFileSystemClientFullAccess"));
|
||||
}
|
||||
|
||||
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code AssociateBudgetWithResource},
|
||||
* {@code DisassociateBudgetFromResource} and {@code ListBudgetsForResource}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001): removing one operation's dispatch case must fail only that
|
||||
* operation's own tests. Assertions on error paths check the exception {@code __type},
|
||||
* not just status code, since {@code AssociateBudgetWithResource}'s duplicate-association
|
||||
* error and the handler's unsupported-operation default arm are both 400.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogBudgetAssociationConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
// ---------- AssociateBudgetWithResource ----------
|
||||
|
||||
@Test
|
||||
void associateBudgetWithResource_returnsEmptyBody() {
|
||||
String productId = createProduct("ab-budget-associate");
|
||||
call("AssociateBudgetWithResource", "{\"BudgetName\":\"my-budget\",\"ResourceId\":\""
|
||||
+ productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void associateBudgetWithResource_duplicate_returnsDuplicateResourceException() {
|
||||
String productId = createProduct("ab-budget-dup");
|
||||
call("AssociateBudgetWithResource", "{\"BudgetName\":\"dup-budget\",\"ResourceId\":\""
|
||||
+ productId + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("AssociateBudgetWithResource", "{\"BudgetName\":\"dup-budget\",\"ResourceId\":\""
|
||||
+ productId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("DuplicateResourceException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void associateBudgetWithResource_unknownResource_returnsResourceNotFound() {
|
||||
call("AssociateBudgetWithResource", "{\"BudgetName\":\"my-budget\",\"ResourceId\":\""
|
||||
+ "prod-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- DisassociateBudgetFromResource ----------
|
||||
|
||||
@Test
|
||||
void disassociateBudgetFromResource_removesAssociation() {
|
||||
String productId = createProduct("ab-budget-disassociate");
|
||||
call("AssociateBudgetWithResource", "{\"BudgetName\":\"remove-me\",\"ResourceId\":\""
|
||||
+ productId + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("DisassociateBudgetFromResource", "{\"BudgetName\":\"remove-me\",\"ResourceId\":\""
|
||||
+ productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("ListBudgetsForResource", "{\"ResourceId\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Budgets.BudgetName.size()", equalTo(0));
|
||||
}
|
||||
|
||||
// ---------- ListBudgetsForResource ----------
|
||||
|
||||
@Test
|
||||
void listBudgetsForResource_returnsAssociatedBudgets() {
|
||||
String productId = createProduct("ab-budget-list");
|
||||
call("AssociateBudgetWithResource", "{\"BudgetName\":\"listed-budget\",\"ResourceId\":\""
|
||||
+ productId + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("ListBudgetsForResource", "{\"ResourceId\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Budgets.BudgetName", hasItem("listed-budget"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listBudgetsForResource_unknownResource_returnsResourceNotFound() {
|
||||
call("ListBudgetsForResource", "{\"ResourceId\":\"prod-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
+316
@@ -0,0 +1,316 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
/**
|
||||
* Wire-level tests for the five Service Catalog operations added together:
|
||||
* {@code DescribeProduct}, {@code DescribePortfolioShares},
|
||||
* {@code ListPortfoliosForProduct}, {@code CopyProduct} and
|
||||
* {@code DescribeProvisioningArtifact}.
|
||||
*
|
||||
* <p>Grouped in one new class rather than five. The convention of one class per
|
||||
* operation exists to stop a shared, pre-existing test from having its assertions
|
||||
* weakened; a brand-new class cannot weaken anything, and every test here targets a
|
||||
* single operation, so removing one dispatch case still fails only that operation's
|
||||
* tests.
|
||||
*
|
||||
* <p>Each operation drives the real HTTP route with the real {@code X-Amz-Target},
|
||||
* so the dispatch case is itself under test (CS-001).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogCatalogReadOpsConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
/** Creates a product and returns its id, so each test owns its fixture. */
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String createPortfolio(String displayName) {
|
||||
return call("CreatePortfolio", "{\"DisplayName\":\"" + displayName
|
||||
+ "\",\"ProviderName\":\"floci-test\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("PortfolioDetail.Id");
|
||||
}
|
||||
|
||||
// ---------- DescribeProduct ----------
|
||||
|
||||
@Test
|
||||
void describeProduct_returnsSummaryAndArtifacts() {
|
||||
String productId = createProduct("ab-describe-product");
|
||||
call("DescribeProduct", "{\"Id\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProductViewSummary.Id", equalTo(productId))
|
||||
.body("ProductViewSummary.Name", equalTo("ab-describe-product"))
|
||||
.body("ProvisioningArtifacts[0].Id", startsWith("pa-"))
|
||||
.body("ProvisioningArtifacts[0].Name", equalTo("v1"));
|
||||
}
|
||||
|
||||
/** DescribeProduct must not return the admin shape; the two differ on the wire. */
|
||||
@Test
|
||||
void describeProduct_doesNotReturnAdminOnlyProductViewDetail() {
|
||||
String productId = createProduct("ab-describe-product-shape");
|
||||
call("DescribeProduct", "{\"Id\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProductViewDetail", equalTo(null))
|
||||
.body("ProvisioningArtifactDetails", equalTo(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeProduct_unknownId_returnsResourceNotFound() {
|
||||
call("DescribeProduct", "{\"Id\":\"prod-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- DescribePortfolioShares ----------
|
||||
|
||||
@Test
|
||||
void describePortfolioShares_returnsSharesCreatedForThePortfolio() {
|
||||
String portfolioId = createPortfolio("ab-shares-portfolio");
|
||||
call("CreatePortfolioShare", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"AccountId\":\"222222222222\"}").then().statusCode(200);
|
||||
|
||||
call("DescribePortfolioShares", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"Type\":\"ACCOUNT\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("PortfolioShareDetails.PrincipalId", hasItem("222222222222"))
|
||||
.body("PortfolioShareDetails.Type", hasItem("ACCOUNT"))
|
||||
.body("PortfolioShareDetails[0].Accepted", equalTo(true));
|
||||
}
|
||||
|
||||
/** A portfolio with no shares is an empty list, not an error. */
|
||||
@Test
|
||||
void describePortfolioShares_noShares_returnsEmptyList() {
|
||||
String portfolioId = createPortfolio("ab-shares-empty");
|
||||
call("DescribePortfolioShares", "{\"PortfolioId\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("PortfolioShareDetails.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describePortfolioShares_unknownPortfolio_returnsResourceNotFound() {
|
||||
call("DescribePortfolioShares", "{\"PortfolioId\":\"port-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the message, not just the type. The handler's default arm also returns
|
||||
* InvalidParametersException at 400, so a type-only assertion would pass even with
|
||||
* the dispatch case deleted and would prove nothing about this operation (CS-001).
|
||||
*/
|
||||
@Test
|
||||
void describePortfolioShares_missingPortfolioId_returnsInvalidParameters() {
|
||||
call("DescribePortfolioShares", "{}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"))
|
||||
.body("message", equalTo("PortfolioId is required"));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code Type} selects which share flavour to report and botocore pins it to
|
||||
* {@code DescribePortfolioShareType}. An unmodelled value used to match nothing and
|
||||
* return an empty list — a client filtering on a typo saw "no shares", not an error.
|
||||
*/
|
||||
@Test
|
||||
void describePortfolioShares_unknownType_returnsInvalidParameters() {
|
||||
String portfolioId = createPortfolio("ab-shares-badtype");
|
||||
call("DescribePortfolioShares", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"Type\":\"ACCOUNTS\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"))
|
||||
.body("message", startsWith("Type must be one of"));
|
||||
}
|
||||
|
||||
// ---------- CreatePortfolioShare ----------
|
||||
|
||||
/**
|
||||
* The share's store key is built from {@code OrganizationNode.Type}, so an unmodelled
|
||||
* type used to create a share DescribePortfolioShares then reported back verbatim.
|
||||
*/
|
||||
@Test
|
||||
void createPortfolioShare_unknownOrganizationNodeType_returnsInvalidParameters() {
|
||||
String portfolioId = createPortfolio("ab-share-badnode");
|
||||
call("CreatePortfolioShare", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"OrganizationNode\":{\"Type\":\"TEAM\",\"Value\":\"o-abcdefghij\"}}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"))
|
||||
.body("message", startsWith("OrganizationNode.Type must be one of"));
|
||||
}
|
||||
|
||||
/** botocore pins AccountId to ^[0-9]{12}$; a short id used to become a share key. */
|
||||
@Test
|
||||
void createPortfolioShare_malformedAccountId_returnsInvalidParameters() {
|
||||
String portfolioId = createPortfolio("ab-share-badaccount");
|
||||
call("CreatePortfolioShare", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"AccountId\":\"2222\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"))
|
||||
.body("message", startsWith("AccountId must be a 12-digit"));
|
||||
}
|
||||
|
||||
// ---------- ListPortfoliosForProduct ----------
|
||||
|
||||
@Test
|
||||
void listPortfoliosForProduct_returnsAssociatedPortfolioOnly() {
|
||||
String productId = createProduct("ab-lpfp-product");
|
||||
String associated = createPortfolio("ab-lpfp-associated");
|
||||
String unrelated = createPortfolio("ab-lpfp-unrelated");
|
||||
call("AssociateProductWithPortfolio", "{\"PortfolioId\":\"" + associated
|
||||
+ "\",\"ProductId\":\"" + productId + "\"}").then().statusCode(200);
|
||||
|
||||
Response response = call("ListPortfoliosForProduct", "{\"ProductId\":\"" + productId + "\"}");
|
||||
response.then()
|
||||
.statusCode(200)
|
||||
.body("PortfolioDetails.Id", hasItem(associated));
|
||||
|
||||
assertNotEquals(unrelated, response.path("PortfolioDetails[0].Id"),
|
||||
"an unassociated portfolio must not be returned");
|
||||
assertEquals(1, (Integer) response.path("PortfolioDetails.size()"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listPortfoliosForProduct_noAssociations_returnsEmptyList() {
|
||||
String productId = createProduct("ab-lpfp-none");
|
||||
call("ListPortfoliosForProduct", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("PortfolioDetails.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listPortfoliosForProduct_unknownProduct_returnsResourceNotFound() {
|
||||
call("ListPortfoliosForProduct", "{\"ProductId\":\"prod-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- CopyProduct ----------
|
||||
|
||||
@Test
|
||||
void copyProduct_createsIndependentCopyAndReturnsToken() {
|
||||
String sourceId = createProduct("ab-copy-source");
|
||||
String sourceArn = call("DescribeProductAsAdmin", "{\"Id\":\"" + sourceId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.ARN");
|
||||
|
||||
String token = call("CopyProduct", "{\"SourceProductArn\":\"" + sourceArn
|
||||
+ "\",\"TargetProductName\":\"ab-copy-target\"}")
|
||||
.then().statusCode(200)
|
||||
.body("CopyProductToken", notNullValue())
|
||||
.extract().path("CopyProductToken");
|
||||
assertEquals(true, token.startsWith("copy-"), "token was: " + token);
|
||||
|
||||
// The copy is a distinct product carrying the target name.
|
||||
Response search = call("SearchProductsAsAdmin", "{}");
|
||||
search.then().statusCode(200)
|
||||
.body("ProductViewDetails.ProductViewSummary.Name", hasItem("ab-copy-target"))
|
||||
.body("ProductViewDetails.ProductViewSummary.Name", hasItem("ab-copy-source"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void copyProduct_withoutTargetName_keepsSourceName() {
|
||||
String sourceId = createProduct("ab-copy-keepname");
|
||||
String sourceArn = call("DescribeProductAsAdmin", "{\"Id\":\"" + sourceId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.ARN");
|
||||
call("CopyProduct", "{\"SourceProductArn\":\"" + sourceArn + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CopyProductToken", startsWith("copy-"));
|
||||
}
|
||||
|
||||
/** Message-level assertion for the same reason as the DescribePortfolioShares case. */
|
||||
@Test
|
||||
void copyProduct_missingSourceArn_returnsInvalidParameters() {
|
||||
call("CopyProduct", "{}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"))
|
||||
.body("message", equalTo("SourceProductArn is required"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void copyProduct_unknownSourceProduct_returnsResourceNotFound() {
|
||||
call("CopyProduct", "{\"SourceProductArn\":"
|
||||
+ "\"arn:aws:catalog:us-east-1:000000000000:product/prod-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- DescribeProvisioningArtifact ----------
|
||||
|
||||
@Test
|
||||
void describeProvisioningArtifact_byProductAndArtifactId_returnsDetail() {
|
||||
String productId = createProduct("ab-dpa-product");
|
||||
String artifactId = call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails[0].Id");
|
||||
|
||||
call("DescribeProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisioningArtifactDetail.Id", equalTo(artifactId))
|
||||
.body("ProvisioningArtifactDetail.Name", equalTo("v1"))
|
||||
.body("ProvisioningArtifactDetail.Type", equalTo("CLOUD_FORMATION_TEMPLATE"))
|
||||
.body("ProvisioningArtifactDetail.Active", equalTo(true))
|
||||
.body("Status", equalTo("AVAILABLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeProvisioningArtifact_unknownArtifact_returnsResourceNotFound() {
|
||||
String productId = createProduct("ab-dpa-unknown");
|
||||
call("DescribeProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"pa-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code CreateConstraint}, {@code DescribeConstraint},
|
||||
* {@code UpdateConstraint} and {@code DeleteConstraint}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). {@code ConstraintId} and {@code Type} are asserted by value,
|
||||
* not just presence, because {@code describeConstraint}'s handler originally read
|
||||
* the stored object's fields under the wrong names ({@code Id}/{@code ConstraintType}
|
||||
* instead of {@code ConstraintId}/{@code Type}) and always returned empty strings —
|
||||
* a value-level assertion is what would have caught that.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogConstraintConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String createPortfolio(String displayName) {
|
||||
return call("CreatePortfolio", "{\"DisplayName\":\"" + displayName
|
||||
+ "\",\"ProviderName\":\"floci-test\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("PortfolioDetail.Id");
|
||||
}
|
||||
|
||||
private static String createConstraint(String portfolioId, String productId) {
|
||||
return call("CreateConstraint", "{\"PortfolioId\":\"" + portfolioId + "\",\"ProductId\":\""
|
||||
+ productId + "\",\"Parameters\":\"{}\",\"Type\":\"LAUNCH\",\"IdempotencyToken\":\""
|
||||
+ "tok-" + portfolioId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ConstraintDetail.ConstraintId");
|
||||
}
|
||||
|
||||
// ---------- CreateConstraint ----------
|
||||
|
||||
@Test
|
||||
void createConstraint_returnsConstraintDetailMatchingRequest() {
|
||||
String portfolioId = createPortfolio("ab-constraint-portfolio");
|
||||
String productId = createProduct("ab-constraint-product");
|
||||
call("CreateConstraint", "{\"PortfolioId\":\"" + portfolioId + "\",\"ProductId\":\""
|
||||
+ productId + "\",\"Parameters\":\"{}\",\"Type\":\"LAUNCH\",\"IdempotencyToken\":\"tok-1\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConstraintDetail.Type", equalTo("LAUNCH"))
|
||||
.body("ConstraintDetail.PortfolioId", equalTo(portfolioId))
|
||||
.body("ConstraintDetail.ProductId", equalTo(productId))
|
||||
.body("ConstraintDetail.ConstraintId", org.hamcrest.Matchers.notNullValue());
|
||||
}
|
||||
|
||||
// ---------- DescribeConstraint ----------
|
||||
|
||||
@Test
|
||||
void describeConstraint_returnsConstraintIdAndType() {
|
||||
String portfolioId = createPortfolio("ab-describe-constraint-portfolio");
|
||||
String productId = createProduct("ab-describe-constraint-product");
|
||||
String constraintId = createConstraint(portfolioId, productId);
|
||||
|
||||
call("DescribeConstraint", "{\"Id\":\"" + constraintId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConstraintDetail.ConstraintId", equalTo(constraintId))
|
||||
.body("ConstraintDetail.Type", equalTo("LAUNCH"))
|
||||
.body("ConstraintDetail.PortfolioId", equalTo(portfolioId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeConstraint_unknownId_returnsResourceNotFound() {
|
||||
call("DescribeConstraint", "{\"Id\":\"con-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- UpdateConstraint ----------
|
||||
|
||||
@Test
|
||||
void updateConstraint_changesDescription() {
|
||||
String portfolioId = createPortfolio("ab-update-constraint-portfolio");
|
||||
String productId = createProduct("ab-update-constraint-product");
|
||||
String constraintId = createConstraint(portfolioId, productId);
|
||||
|
||||
call("UpdateConstraint", "{\"Id\":\"" + constraintId + "\",\"Description\":\"updated\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConstraintDetail.ConstraintId", equalTo(constraintId))
|
||||
.body("ConstraintDetail.Description", equalTo("updated"));
|
||||
|
||||
call("DescribeConstraint", "{\"Id\":\"" + constraintId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConstraintDetail.Description", equalTo("updated"));
|
||||
}
|
||||
|
||||
// ---------- DeleteConstraint ----------
|
||||
|
||||
@Test
|
||||
void deleteConstraint_removesConstraint() {
|
||||
String portfolioId = createPortfolio("ab-delete-constraint-portfolio");
|
||||
String productId = createProduct("ab-delete-constraint-product");
|
||||
String constraintId = createConstraint(portfolioId, productId);
|
||||
|
||||
call("DeleteConstraint", "{\"Id\":\"" + constraintId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("DescribeConstraint", "{\"Id\":\"" + constraintId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code DescribeCopyProductStatus}, {@code DescribeProductView},
|
||||
* {@code DescribeProvisioningParameters} and
|
||||
* {@code DescribeServiceActionExecutionParameters}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). {@code describeCopyProductStatus} looked up a token via
|
||||
* {@code associationStore} that {@code copyProduct} (already {@code accepted} from
|
||||
* earlier this session) never persisted — same shape as issues 0020/0021. Fixed by
|
||||
* having {@code copyProduct} store a status row under the token it returns.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogDescribeQueryConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String describeProductAsAdminArn(String productId) {
|
||||
return call("DescribeProductAsAdmin", "{\"Id\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.ARN");
|
||||
}
|
||||
|
||||
// ---------- DescribeCopyProductStatus ----------
|
||||
|
||||
@Test
|
||||
void describeCopyProductStatus_returnsSucceededWithTargetProductId() {
|
||||
String sourceId = createProduct("ab-copy-status-source");
|
||||
String sourceArn = describeProductAsAdminArn(sourceId);
|
||||
|
||||
String token = call("CopyProduct", "{\"SourceProductArn\":\"" + sourceArn
|
||||
+ "\",\"TargetProductName\":\"ab-copy-status-target\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("CopyProductToken");
|
||||
|
||||
call("DescribeCopyProductStatus", "{\"CopyProductToken\":\"" + token + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CopyProductStatus", equalTo("SUCCEEDED"))
|
||||
.body("TargetProductId", org.hamcrest.Matchers.notNullValue());
|
||||
}
|
||||
|
||||
// ---------- DescribeProductView ----------
|
||||
|
||||
@Test
|
||||
void describeProductView_returnsSummaryAndArtifacts() {
|
||||
String productId = createProduct("ab-product-view");
|
||||
|
||||
call("DescribeProductView", "{\"Id\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProductViewSummary.Id", equalTo(productId))
|
||||
.body("ProvisioningArtifacts.Name", hasItem("v1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeProductView_missingId_returnsInvalidParameters() {
|
||||
call("DescribeProductView", "{}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
|
||||
// ---------- DescribeProvisioningParameters ----------
|
||||
|
||||
@Test
|
||||
void describeProvisioningParameters_returnsParameterKeys() {
|
||||
String productId = call("CreateProduct", "{\"Name\":\"ab-provisioning-params\",\"Owner\":\""
|
||||
+ "floci-test\",\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\",\"Info\":{"
|
||||
+ "\"LoadTemplateFromURL\":\"https://example.com/template.json\"}}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
|
||||
call("DescribeProvisioningParameters", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeProvisioningParameters_unknownArtifact_returnsResourceNotFound() {
|
||||
String productId = createProduct("ab-provisioning-params-unknown-artifact");
|
||||
|
||||
call("DescribeProvisioningParameters", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"pa-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeProvisioningParameters_missingProductIdAndName_returnsInvalidParameters() {
|
||||
call("DescribeProvisioningParameters", "{}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
|
||||
// ---------- DescribeServiceActionExecutionParameters ----------
|
||||
|
||||
private static String importProvisionedProduct(String productId, String name) {
|
||||
return call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"pa-anything\",\"ProvisionedProductName\":\""
|
||||
+ name + "\",\"PhysicalId\":\"phys-" + name + "\",\"IdempotencyToken\":\"tok-" + name + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("RecordDetail.ProvisionedProductId");
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeServiceActionExecutionParameters_returnsEmptyParameterList() {
|
||||
String productId = createProduct("ab-safep-product");
|
||||
String provisionedId = importProvisionedProduct(productId, "ab-safep-pp");
|
||||
|
||||
call("DescribeServiceActionExecutionParameters", "{\"ProvisionedProductId\":\"" + provisionedId
|
||||
+ "\",\"ServiceActionId\":\"sa-anything\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ServiceActionParameters.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeServiceActionExecutionParameters_unknownProduct_returnsResourceNotFound() {
|
||||
call("DescribeServiceActionExecutionParameters", "{\"ProvisionedProductId\":\"pp-doesnotexist\","
|
||||
+ "\"ServiceActionId\":\"sa-anything\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeServiceActionExecutionParameters_missingServiceActionId_returnsInvalidParameters() {
|
||||
call("DescribeServiceActionExecutionParameters", "{\"ProvisionedProductId\":\"pp-anything\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
|
||||
// ---------- missing identifier parameters ----------
|
||||
|
||||
@Test
|
||||
void describeProductAsAdmin_missingId_returnsInvalidParameters() {
|
||||
call("DescribeProductAsAdmin", "{}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describePortfolio_missingId_returnsInvalidParameters() {
|
||||
call("DescribePortfolio", "{}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeTagOption_missingId_returnsInvalidParameters() {
|
||||
call("DescribeTagOption", "{}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code NotifyProvisionProductEngineWorkflowResult},
|
||||
* {@code NotifyUpdateProvisionedProductEngineWorkflowResult} and
|
||||
* {@code NotifyTerminateProvisionedProductEngineWorkflowResult}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). {@code NotifyTerminate...} already validated {@code Status}
|
||||
* against {@code SUCCEEDED}/{@code FAILED}; the other two accepted any string. Made
|
||||
* consistent across all three as part of this session's batch (they represent the
|
||||
* same concept — an external provisioning engine reporting a workflow outcome).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogEngineWorkflowNotifyConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
// ---------- NotifyProvisionProductEngineWorkflowResult ----------
|
||||
|
||||
@Test
|
||||
void notifyProvisionProductEngineWorkflowResult_succeeded_returnsEmptyBody() {
|
||||
call("NotifyProvisionProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-1\","
|
||||
+ "\"RecordId\":\"rec-1\",\"Status\":\"SUCCEEDED\",\"IdempotencyToken\":\"tok-1\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void notifyProvisionProductEngineWorkflowResult_invalidStatus_returnsInvalidParameters() {
|
||||
call("NotifyProvisionProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-2\","
|
||||
+ "\"RecordId\":\"rec-2\",\"Status\":\"BOGUS\",\"IdempotencyToken\":\"tok-2\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
|
||||
// ---------- NotifyUpdateProvisionedProductEngineWorkflowResult ----------
|
||||
|
||||
@Test
|
||||
void notifyUpdateProvisionedProductEngineWorkflowResult_failed_returnsEmptyBody() {
|
||||
call("NotifyUpdateProvisionedProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-3\","
|
||||
+ "\"RecordId\":\"rec-3\",\"Status\":\"FAILED\",\"IdempotencyToken\":\"tok-3\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void notifyUpdateProvisionedProductEngineWorkflowResult_invalidStatus_returnsInvalidParameters() {
|
||||
call("NotifyUpdateProvisionedProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-4\","
|
||||
+ "\"RecordId\":\"rec-4\",\"Status\":\"BOGUS\",\"IdempotencyToken\":\"tok-4\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
|
||||
// ---------- NotifyTerminateProvisionedProductEngineWorkflowResult ----------
|
||||
|
||||
@Test
|
||||
void notifyTerminateProvisionedProductEngineWorkflowResult_succeeded_returnsEmptyBody() {
|
||||
call("NotifyTerminateProvisionedProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-5\","
|
||||
+ "\"RecordId\":\"rec-5\",\"Status\":\"SUCCEEDED\",\"IdempotencyToken\":\"tok-5\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void notifyTerminateProvisionedProductEngineWorkflowResult_invalidStatus_returnsInvalidParameters() {
|
||||
call("NotifyTerminateProvisionedProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-6\","
|
||||
+ "\"RecordId\":\"rec-6\",\"Status\":\"BOGUS\",\"IdempotencyToken\":\"tok-6\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code ExecuteProvisionedProductServiceAction}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). Same bug shape as issue 0021 (DescribeRecord): the handler
|
||||
* generated and discarded its own throwaway {@code RecordId} instead of persisting
|
||||
* one. Fixed the same way — the service now persists a {@code RECORD} row and
|
||||
* returns its id, the handler reads it back.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogExecuteServiceActionConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String firstArtifactId(String productId) {
|
||||
return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails[0].Id");
|
||||
}
|
||||
|
||||
private static String importProvisionedProduct(String productId, String artifactId, String name) {
|
||||
return call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
|
||||
+ name + "\",\"PhysicalId\":\"phys-" + name + "\",\"IdempotencyToken\":\"tok-" + name + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("RecordDetail.ProvisionedProductId");
|
||||
}
|
||||
|
||||
@Test
|
||||
void executeProvisionedProductServiceAction_returnsDescribableRecord() {
|
||||
String productId = createProduct("ab-execute-action-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String provisionedId = importProvisionedProduct(productId, artifactId, "ab-execute-action-pp");
|
||||
|
||||
String recordId = call("ExecuteProvisionedProductServiceAction", "{\"ProvisionedProductId\":\""
|
||||
+ provisionedId + "\",\"ServiceActionId\":\"sa-anything\",\"ExecuteToken\":\""
|
||||
+ "tok-execute-action\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.ProvisionedProductId", equalTo(provisionedId))
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"))
|
||||
.extract().path("RecordDetail.RecordId");
|
||||
|
||||
call("DescribeRecord", "{\"Id\":\"" + recordId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.RecordId", equalTo(recordId))
|
||||
.body("RecordDetail.ProvisionedProductId", equalTo(provisionedId))
|
||||
.body("RecordDetail.RecordType", equalTo("UPDATE_PROVISIONED_PRODUCT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void executeProvisionedProductServiceAction_unknownProduct_returnsResourceNotFound() {
|
||||
call("ExecuteProvisionedProductServiceAction", "{\"ProvisionedProductId\":\"pp-doesnotexist\","
|
||||
+ "\"ServiceActionId\":\"sa-anything\",\"ExecuteToken\":\"tok-unknown\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void executeProvisionedProductServiceAction_missingServiceActionId_returnsInvalidParameters() {
|
||||
String productId = createProduct("ab-execute-action-missing-sa-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String provisionedId = importProvisionedProduct(productId, artifactId, "ab-execute-action-missing-sa");
|
||||
|
||||
call("ExecuteProvisionedProductServiceAction", "{\"ProvisionedProductId\":\"" + provisionedId
|
||||
+ "\",\"ExecuteToken\":\"tok-missing-sa\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
}
|
||||
+303
@@ -0,0 +1,303 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
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.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
|
||||
@QuarkusTest
|
||||
class ServiceCatalogIntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String TARGET = "AWS242ServiceCatalogService.";
|
||||
private static final String ORGANIZATIONS_TARGET = "AWSOrganizationsV20161128.";
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=723679240095/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAndListPortfolio_returnsAwsShape() {
|
||||
String id = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "CreatePortfolio")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"DisplayName\":\"VellumGoldenWorkloads\","
|
||||
+ "\"ProviderName\":\"Vellum Cloud Platform\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("PortfolioDetail.DisplayName", equalTo("VellumGoldenWorkloads"))
|
||||
.extract().path("PortfolioDetail.Id");
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "ListPortfolios")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("PortfolioDetails.Id", hasItem(id))
|
||||
.body("PortfolioDetails.DisplayName", hasItem("VellumGoldenWorkloads"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listPortfolios_includesControlTowerAccountFactoryPortfolio() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "ListPortfolios")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("PortfolioDetails.DisplayName",
|
||||
hasItem(ServiceCatalogService.CONTROL_TOWER_PORTFOLIO_NAME))
|
||||
.body("PortfolioDetails.ProviderName",
|
||||
hasItem(ServiceCatalogService.CONTROL_TOWER_PROVIDER_NAME))
|
||||
.body("PortfolioDetails.Id",
|
||||
hasItem(ServiceCatalogService.CONTROL_TOWER_PORTFOLIO_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatePortfolioShare_isStoredAndImmediatelyComplete() {
|
||||
String portfolioId = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "CreatePortfolio")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"DisplayName\":\"Shared\",\"ProviderName\":\"Vellum\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().path("PortfolioDetail.Id");
|
||||
|
||||
String token = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "UpdatePortfolioShare")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"PortfolioId\":\"" + portfolioId + "\","
|
||||
+ "\"OrganizationNode\":{\"Type\":\"ORGANIZATIONAL_UNIT\","
|
||||
+ "\"Value\":\"ou-vellum-workloads\"},\"ShareTagOptions\":true}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("Status", equalTo("COMPLETED"))
|
||||
.extract().path("PortfolioShareToken");
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "DescribePortfolioShareStatus")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"PortfolioShareToken\":\"" + token + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("Status", equalTo("COMPLETED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void searchProvisionedProducts_returnsEmptyAwsShapeWhenNoneExist() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "SearchProvisionedProducts")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"Filters\":{\"SearchQuery\":[\"physicalId: 723679240095\"]},"
|
||||
+ "\"AccessLevelFilter\":{\"Key\":\"Account\",\"Value\":\"self\"}}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("ProvisionedProducts", hasSize(0))
|
||||
.body("TotalResultsCount", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void searchProductsAndListArtifacts_includeControlTowerAccountFactory() {
|
||||
String productId = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "SearchProducts")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"Filters\":{\"FullTextSearch\":[\"AWS Control Tower Account Factory\"]}}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("ProductViewSummaries", hasSize(1))
|
||||
.body("ProductViewSummaries[0].Name", equalTo(ServiceCatalogService.CONTROL_TOWER_PRODUCT_NAME))
|
||||
.extract().path("ProductViewSummaries[0].ProductId");
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "ListProvisioningArtifacts")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"ProductId\":\"" + productId + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("ProvisioningArtifactDetails", hasSize(1))
|
||||
.body("ProvisioningArtifactDetails[0].Id",
|
||||
equalTo(ServiceCatalogService.CONTROL_TOWER_ARTIFACT_ID))
|
||||
.body("ProvisioningArtifactDetails[0].Active", equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionControlTowerProduct_createsAccountAndPersistsAvailableProduct() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", ORGANIZATIONS_TARGET + "CreateOrganization")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"FeatureSet\":\"ALL\"}")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
String rootId = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", ORGANIZATIONS_TARGET + "ListRoots")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().path("Roots[0].Id");
|
||||
String ouId = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", ORGANIZATIONS_TARGET + "CreateOrganizationalUnit")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"ParentId\":\"" + rootId + "\",\"Name\":\"Workloads\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().path("OrganizationalUnit.Id");
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "ProvisionProduct")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"ProductName\":\"AWS Control Tower Account Factory\","
|
||||
+ "\"ProvisioningArtifactId\":\"" + ServiceCatalogService.CONTROL_TOWER_ARTIFACT_ID + "\","
|
||||
+ "\"ProvisionedProductName\":\"ServiceCatalogWorkload\","
|
||||
+ "\"ProvisionToken\":\"token-1\",\"ProvisioningParameters\":["
|
||||
+ "{\"Key\":\"AccountName\",\"Value\":\"ServiceCatalogWorkload\"},"
|
||||
+ "{\"Key\":\"AccountEmail\",\"Value\":\"servicecatalog-workload@floci.test\"},"
|
||||
+ "{\"Key\":\"ManagedOrganizationalUnit\","
|
||||
+ "\"Value\":\"Workloads (" + ouId + ")\"}]}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"));
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "SearchProvisionedProducts")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"Filters\":{\"SearchQuery\":[\"status: AVAILABLE\"]},"
|
||||
+ "\"AccessLevelFilter\":{\"Key\":\"Account\",\"Value\":\"self\"}}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("ProvisionedProducts", hasSize(1))
|
||||
.body("ProvisionedProducts[0].Type", equalTo("CONTROL_TOWER_ACCOUNT"))
|
||||
.body("ProvisionedProducts[0].Status", equalTo("AVAILABLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptPortfolioShare_withExistingPortfolio_returnsEmptyBody() {
|
||||
String portfolioId = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "CreatePortfolio")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"DisplayName\":\"ShareAccept\",\"ProviderName\":\"Vellum\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().path("PortfolioDetail.Id");
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "AcceptPortfolioShare")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"PortfolioId\":\"" + portfolioId + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptPortfolioShare_withoutPortfolioId_returnsAwsError() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "AcceptPortfolioShare")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{}")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"))
|
||||
.body("message", equalTo("PortfolioId is required"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectPortfolioShare_withExistingPortfolio_returnsEmptyBody() {
|
||||
String portfolioId = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "CreatePortfolio")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"DisplayName\":\"ShareReject\",\"ProviderName\":\"Vellum\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().path("PortfolioDetail.Id");
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "RejectPortfolioShare")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"PortfolioId\":\"" + portfolioId + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectPortfolioShare_withoutPortfolioId_returnsAwsError() {
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "RejectPortfolioShare")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{}")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"))
|
||||
.body("message", equalTo("PortfolioId is required"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDescribeAndDeletePortfolioShare_removesShare() {
|
||||
String portfolioId = given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "CreatePortfolio")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"DisplayName\":\"ShareRoundTrip\",\"ProviderName\":\"Vellum\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().path("PortfolioDetail.Id");
|
||||
|
||||
String accountId = "123456789012";
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "CreatePortfolioShare")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"PortfolioId\":\"" + portfolioId + "\",\"AccountId\":\"" + accountId + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("Status", equalTo("COMPLETED"));
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "DescribePortfolioShares")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"PortfolioId\":\"" + portfolioId + "\",\"Type\":\"ACCOUNT\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("PortfolioShareDetails", hasSize(1))
|
||||
.body("PortfolioShareDetails[0].PrincipalId", equalTo(accountId));
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "DeletePortfolioShare")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"PortfolioId\":\"" + portfolioId + "\",\"AccountId\":\"" + accountId + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET + "DescribePortfolioShares")
|
||||
.header("Authorization", AUTH)
|
||||
.body("{\"PortfolioId\":\"" + portfolioId + "\",\"Type\":\"ACCOUNT\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("PortfolioShareDetails", hasSize(0));
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code EnableAWSOrganizationsAccess},
|
||||
* {@code DisableAWSOrganizationsAccess} and {@code GetAWSOrganizationsAccessStatus}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one: the falsifiability check requires
|
||||
* that removing one operation's dispatch case fails only that operation's own tests
|
||||
* (CS-001). All three operations here return 200 with no error body on success; the
|
||||
* handler's {@code default} arm returns 400, so a bare status-code assertion is
|
||||
* already sufficient to falsify — no message-collision risk to guard against.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogOrgAccessConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static io.restassured.response.Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
@Test
|
||||
void enableAwsOrganizationsAccess_returnsEmptyBody() {
|
||||
call("EnableAWSOrganizationsAccess", "{}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void disableAwsOrganizationsAccess_returnsEmptyBody() {
|
||||
call("DisableAWSOrganizationsAccess", "{}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAwsOrganizationsAccessStatus_returnsEnabled() {
|
||||
call("GetAWSOrganizationsAccessStatus", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AccessStatus", org.hamcrest.Matchers.equalTo("ENABLED"));
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code ListAcceptedPortfolioShares},
|
||||
* {@code ListConstraintsForPortfolio} and {@code ListLaunchPaths}. Last three
|
||||
* operations in this session's servicecatalog full-parity batch (56 ops total).
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). {@code listConstraintsForPortfolio} was a hardcoded stub
|
||||
* that always returned an empty list, despite {@code CreateConstraint} (already
|
||||
* {@code accepted}) fully persisting constraints with the exact
|
||||
* {@code PortfolioId}/{@code ProductId} fields this query needed to filter on —
|
||||
* same shape as issue 0018 (`ListServiceActions`). Fixed to actually scan.
|
||||
* {@code ListAcceptedPortfolioShares} reuses {@code ListPortfolios}'s handler as-is
|
||||
* — consistent with the already-documented `AcceptPortfolioShare` limitation (no
|
||||
* distinct acceptance state is tracked), not a new bug.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogPortfolioQueryConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String createPortfolio(String displayName) {
|
||||
return call("CreatePortfolio", "{\"DisplayName\":\"" + displayName
|
||||
+ "\",\"ProviderName\":\"floci-test\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("PortfolioDetail.Id");
|
||||
}
|
||||
|
||||
// ---------- ListAcceptedPortfolioShares ----------
|
||||
|
||||
@Test
|
||||
void listAcceptedPortfolioShares_includesExistingPortfolio() {
|
||||
String portfolioId = createPortfolio("ab-accepted-shares-portfolio");
|
||||
|
||||
call("ListAcceptedPortfolioShares", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("PortfolioDetails.Id", hasItem(portfolioId));
|
||||
}
|
||||
|
||||
// ---------- ListConstraintsForPortfolio ----------
|
||||
|
||||
@Test
|
||||
void listConstraintsForPortfolio_returnsCreatedConstraint() {
|
||||
String portfolioId = createPortfolio("ab-list-constraints-portfolio");
|
||||
String productId = createProduct("ab-list-constraints-product");
|
||||
String constraintId = call("CreateConstraint", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"ProductId\":\"" + productId + "\",\"Parameters\":\"{}\",\"Type\":\"LAUNCH\","
|
||||
+ "\"IdempotencyToken\":\"tok-list-constraints\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ConstraintDetail.ConstraintId");
|
||||
|
||||
call("ListConstraintsForPortfolio", "{\"PortfolioId\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConstraintDetails.ConstraintId", hasItem(constraintId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listConstraintsForPortfolio_scopedToProductId_excludesOtherProducts() {
|
||||
String portfolioId = createPortfolio("ab-list-constraints-scoped-portfolio");
|
||||
String productA = createProduct("ab-list-constraints-scoped-product-a");
|
||||
String productB = createProduct("ab-list-constraints-scoped-product-b");
|
||||
String constraintA = call("CreateConstraint", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"ProductId\":\"" + productA + "\",\"Parameters\":\"{}\",\"Type\":\"LAUNCH\","
|
||||
+ "\"IdempotencyToken\":\"tok-scoped-a\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ConstraintDetail.ConstraintId");
|
||||
call("CreateConstraint", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"ProductId\":\"" + productB + "\",\"Parameters\":\"{}\",\"Type\":\"LAUNCH\","
|
||||
+ "\"IdempotencyToken\":\"tok-scoped-b\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("ListConstraintsForPortfolio", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"ProductId\":\"" + productA + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConstraintDetails.ConstraintId", hasItem(constraintA))
|
||||
.body("ConstraintDetails.size()", equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listConstraintsForPortfolio_unknownPortfolio_returnsResourceNotFound() {
|
||||
call("ListConstraintsForPortfolio", "{\"PortfolioId\":\"port-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- ListLaunchPaths ----------
|
||||
|
||||
@Test
|
||||
void listLaunchPaths_returnsPortfolioContainingProduct() {
|
||||
String portfolioId = createPortfolio("ab-launch-paths-portfolio");
|
||||
String productId = createProduct("ab-launch-paths-product");
|
||||
call("AssociateProductWithPortfolio", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"PortfolioId\":\"" + portfolioId + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("ListLaunchPaths", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("LaunchPathSummaries.Id", hasItem(portfolioId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listLaunchPaths_missingProductId_returnsInvalidParameters() {
|
||||
call("ListLaunchPaths", "{}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code AssociatePrincipalWithPortfolio},
|
||||
* {@code DisassociatePrincipalFromPortfolio}, {@code ListPrincipalsForPortfolio},
|
||||
* {@code ListPortfolioAccess} and {@code ListOrganizationPortfolioAccess}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogPrincipalAccessConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createPortfolio(String displayName) {
|
||||
return call("CreatePortfolio", "{\"DisplayName\":\"" + displayName
|
||||
+ "\",\"ProviderName\":\"floci-test\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("PortfolioDetail.Id");
|
||||
}
|
||||
|
||||
// ---------- AssociatePrincipalWithPortfolio ----------
|
||||
|
||||
@Test
|
||||
void associatePrincipalWithPortfolio_rejectsUnknownPrincipalType() {
|
||||
String portfolioId = createPortfolio("ab-principal-badtype");
|
||||
call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"PrincipalARN\":\"arn:aws:iam::000000000000:role/my-role\","
|
||||
+ "\"PrincipalType\":\"FEDERATED\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void associatePrincipalWithPortfolio_returnsEmptyBody() {
|
||||
String portfolioId = createPortfolio("ab-principal-associate");
|
||||
call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"PrincipalARN\":\"arn:aws:iam::000000000000:role/my-role\","
|
||||
+ "\"PrincipalType\":\"IAM\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void associatePrincipalWithPortfolio_unknownPortfolio_returnsResourceNotFound() {
|
||||
call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"port-doesnotexist\","
|
||||
+ "\"PrincipalARN\":\"arn:aws:iam::000000000000:role/my-role\","
|
||||
+ "\"PrincipalType\":\"IAM\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- ListPrincipalsForPortfolio ----------
|
||||
|
||||
@Test
|
||||
void listPrincipalsForPortfolio_returnsAssociatedPrincipal() {
|
||||
String portfolioId = createPortfolio("ab-principal-list");
|
||||
call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"PrincipalARN\":\"arn:aws:iam::000000000000:role/listed-role\","
|
||||
+ "\"PrincipalType\":\"IAM\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("ListPrincipalsForPortfolio", "{\"PortfolioId\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Principals.PrincipalARN", hasItem("arn:aws:iam::000000000000:role/listed-role"))
|
||||
.body("Principals.PrincipalType", hasItem("IAM"));
|
||||
}
|
||||
|
||||
// ---------- DisassociatePrincipalFromPortfolio ----------
|
||||
|
||||
@Test
|
||||
void disassociatePrincipalFromPortfolio_removesPrincipal() {
|
||||
String portfolioId = createPortfolio("ab-principal-disassociate");
|
||||
String arn = "arn:aws:iam::000000000000:role/removed-role";
|
||||
call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"PrincipalARN\":\"" + arn + "\",\"PrincipalType\":\"IAM\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("DisassociatePrincipalFromPortfolio", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"PrincipalARN\":\"" + arn + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("ListPrincipalsForPortfolio", "{\"PortfolioId\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Principals.PrincipalARN", org.hamcrest.Matchers.not(hasItem(arn)));
|
||||
}
|
||||
|
||||
// ---------- ListPortfolioAccess ----------
|
||||
|
||||
@Test
|
||||
void listPortfolioAccess_returnsAccountsSharedWithPortfolio() {
|
||||
String portfolioId = createPortfolio("ab-portfolio-access");
|
||||
call("CreatePortfolioShare", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"AccountId\":\"333333333333\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("ListPortfolioAccess", "{\"PortfolioId\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AccountIds", hasItem("333333333333"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listPortfolioAccess_unknownPortfolio_returnsResourceNotFound() {
|
||||
call("ListPortfolioAccess", "{\"PortfolioId\":\"port-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- ListOrganizationPortfolioAccess ----------
|
||||
|
||||
@Test
|
||||
void listOrganizationPortfolioAccess_noShares_returnsEmptyList() {
|
||||
String portfolioId = createPortfolio("ab-org-access-empty");
|
||||
call("ListOrganizationPortfolioAccess", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"OrganizationNodeType\":\"ORGANIZATION\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("OrganizationNodes.size()", equalTo(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* botocore pins OrganizationNodeType to ORGANIZATION / ORGANIZATIONAL_UNIT / ACCOUNT.
|
||||
* An unmodelled value used to filter to nothing and report an empty node list, so a
|
||||
* caller with a typo could not tell "no access" from "wrong parameter".
|
||||
*/
|
||||
@Test
|
||||
void listOrganizationPortfolioAccess_unknownNodeType_returnsInvalidParameters() {
|
||||
String portfolioId = createPortfolio("ab-org-access-badtype");
|
||||
call("ListOrganizationPortfolioAccess", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"OrganizationNodeType\":\"ORG_UNIT\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"))
|
||||
.body("message", org.hamcrest.Matchers.startsWith("OrganizationNodeType must be one of"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOrganizationPortfolioAccess_missingNodeType_returnsInvalidParameters() {
|
||||
String portfolioId = createPortfolio("ab-org-access-missing-type");
|
||||
call("ListOrganizationPortfolioAccess", "{\"PortfolioId\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
}
|
||||
+259
@@ -0,0 +1,259 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code ProvisionProduct}'s request validation.
|
||||
*
|
||||
* <p>The operation used to ignore {@code ProductId} and {@code ProductName}
|
||||
* entirely: any request carrying Account Factory provisioning parameters took the
|
||||
* Control Tower path, so an unrecognised product id still created a real
|
||||
* Organizations member account and recorded it under the seeded Account Factory
|
||||
* identifiers. These tests pin the three outcomes the request now has to choose
|
||||
* between — Account Factory, a plain stored product, and rejection.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogProvisionProductValidationConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String target, String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", target + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return call("AWS242ServiceCatalogService.", action, body);
|
||||
}
|
||||
|
||||
private static Response organizations(String action, String body) {
|
||||
return call("AWSOrganizationsV20161128.", action, body);
|
||||
}
|
||||
|
||||
/** The organization is shared across the service-catalog suite; creating it twice is expected to fail. */
|
||||
private static void ensureOrganization() {
|
||||
organizations("CreateOrganization", "{\"FeatureSet\":\"ALL\"}");
|
||||
}
|
||||
|
||||
private static void assertNoAccountWithEmail(String email) {
|
||||
organizations("ListAccounts", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accounts.Email", not(hasItem(email)));
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String firstArtifactId(String productId) {
|
||||
return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails[0].Id");
|
||||
}
|
||||
|
||||
private static String accountFactoryParameters(String name, String email) {
|
||||
return "\"ProvisionedProductName\":\"" + name + "\",\"ProvisionToken\":\"tok-" + name + "\","
|
||||
+ "\"ProvisioningParameters\":[{\"Key\":\"AccountName\",\"Value\":\"" + name + "\"},"
|
||||
+ "{\"Key\":\"AccountEmail\",\"Value\":\"" + email + "\"}]";
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionProduct_unknownProductId_returnsResourceNotFoundAndCreatesNoAccount() {
|
||||
ensureOrganization();
|
||||
String email = "ab-unknown-product@floci.test";
|
||||
|
||||
call("ProvisionProduct", "{\"ProductId\":\"prod-doesnotexist\","
|
||||
+ "\"ProvisioningArtifactId\":\"pa-doesnotexist\","
|
||||
+ accountFactoryParameters("ab-provision-unknown-product", email) + "}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
assertNoAccountWithEmail(email);
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionProduct_artifactIdAsProductId_returnsResourceNotFoundAndCreatesNoAccount() {
|
||||
ensureOrganization();
|
||||
String email = "ab-artifact-as-product@floci.test";
|
||||
|
||||
call("ProvisionProduct", "{\"ProductId\":\"" + ServiceCatalogService.CONTROL_TOWER_ARTIFACT_ID + "\","
|
||||
+ accountFactoryParameters("ab-provision-artifact-as-product", email) + "}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
assertNoAccountWithEmail(email);
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionProduct_ambiguousProductName_returnsDuplicateResourceAndCreatesNoAccount() {
|
||||
// A user-created product may share its Name with another (names are not
|
||||
// unique keys); first-match would nondeterministically pick one — including
|
||||
// the Account Factory product. Ambiguity must fail, not guess.
|
||||
ensureOrganization();
|
||||
String email = "ab-ambiguous-name@floci.test";
|
||||
createProduct("AmbiguousName");
|
||||
createProduct("AmbiguousName");
|
||||
|
||||
call("ProvisionProduct", "{\"ProductName\":\"AmbiguousName\","
|
||||
+ accountFactoryParameters("ab-provision-ambiguous", email) + "}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("DuplicateResourceException"));
|
||||
|
||||
assertNoAccountWithEmail(email);
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionProduct_withoutProductIdentifier_returnsInvalidParametersAndCreatesNoAccount() {
|
||||
ensureOrganization();
|
||||
String email = "ab-no-product-identifier@floci.test";
|
||||
|
||||
call("ProvisionProduct", "{\"ProvisioningArtifactId\":\"pa-doesnotexist\","
|
||||
+ accountFactoryParameters("ab-provision-no-identifier", email) + "}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
|
||||
assertNoAccountWithEmail(email);
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionProduct_artifactFromAnotherProduct_returnsResourceNotFound() {
|
||||
String productId = createProduct("ab-provision-artifact-check");
|
||||
|
||||
call("ProvisionProduct", "{\"ProductId\":\"" + productId + "\","
|
||||
+ "\"ProvisioningArtifactId\":\"pa-doesnotexist\","
|
||||
+ accountFactoryParameters("ab-provision-wrong-artifact", "ab-wrong-artifact@floci.test") + "}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionProduct_storedProduct_recordsThatProductWithoutCreatingAccount() {
|
||||
ensureOrganization();
|
||||
String productId = createProduct("ab-provision-plain-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String email = "ab-plain-product@floci.test";
|
||||
|
||||
call("ProvisionProduct", "{\"ProductId\":\"" + productId + "\","
|
||||
+ "\"ProvisioningArtifactId\":\"" + artifactId + "\","
|
||||
+ accountFactoryParameters("ab-provision-plain", email) + "}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"));
|
||||
|
||||
call("DescribeProvisionedProduct", "{\"Name\":\"ab-provision-plain\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisionedProductDetail.ProductId", equalTo(productId))
|
||||
.body("ProvisionedProductDetail.ProvisioningArtifactId", equalTo(artifactId))
|
||||
.body("ProvisionedProductDetail.Type", not(equalTo("CONTROL_TOWER_ACCOUNT")));
|
||||
|
||||
assertNoAccountWithEmail(email);
|
||||
|
||||
call("TerminateProvisionedProduct", "{\"ProvisionedProductName\":\"ab-provision-plain\","
|
||||
+ "\"TerminateToken\":\"tok-terminate-plain\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Without {@code AccountEmail} the Account Factory path used to fall through to
|
||||
* Organizations' {@code validateEmail}, which throws {@code InvalidInputException} — an
|
||||
* Organizations shape, not a Service Catalog one, so a servicecatalog SDK client cannot
|
||||
* deserialize it into a typed exception.
|
||||
*/
|
||||
@Test
|
||||
void provisionProduct_accountFactoryWithoutAccountEmail_returnsServiceCatalogInvalidParameters() {
|
||||
ensureOrganization();
|
||||
|
||||
call("ProvisionProduct", "{\"ProductId\":\"" + ServiceCatalogService.CONTROL_TOWER_PRODUCT_ID + "\","
|
||||
+ "\"ProvisioningArtifactId\":\"" + ServiceCatalogService.CONTROL_TOWER_ARTIFACT_ID + "\","
|
||||
+ "\"ProvisionedProductName\":\"ab-provision-no-email\",\"ProvisionToken\":\"tok-no-email\","
|
||||
+ "\"ProvisioningParameters\":[{\"Key\":\"AccountName\",\"Value\":\"ab-provision-no-email\"}]}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The guard belongs on the Account Factory path only — a plain stored product needs no
|
||||
* email at all, so provisioning one without {@code AccountEmail} must still succeed.
|
||||
*/
|
||||
@Test
|
||||
void provisionProduct_plainProductWithoutAccountEmail_stillSucceeds() {
|
||||
String productId = createProduct("ab-provision-no-email-plain-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
|
||||
call("ProvisionProduct", "{\"ProductId\":\"" + productId + "\","
|
||||
+ "\"ProvisioningArtifactId\":\"" + artifactId + "\","
|
||||
+ "\"ProvisionedProductName\":\"ab-provision-no-email-plain\","
|
||||
+ "\"ProvisionToken\":\"tok-no-email-plain\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"));
|
||||
|
||||
call("TerminateProvisionedProduct", "{\"ProvisionedProductName\":\"ab-provision-no-email-plain\","
|
||||
+ "\"TerminateToken\":\"tok-terminate-no-email-plain\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionProduct_accountFactoryProduct_stillCreatesAccount() {
|
||||
ensureOrganization();
|
||||
String email = "ab-account-factory@floci.test";
|
||||
|
||||
call("ProvisionProduct", "{\"ProductId\":\"" + ServiceCatalogService.CONTROL_TOWER_PRODUCT_ID + "\","
|
||||
+ "\"ProvisioningArtifactId\":\"" + ServiceCatalogService.CONTROL_TOWER_ARTIFACT_ID + "\","
|
||||
+ accountFactoryParameters("ab-provision-account-factory", email) + "}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"));
|
||||
|
||||
call("DescribeProvisionedProduct", "{\"Name\":\"ab-provision-account-factory\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisionedProductDetail.Type", equalTo("CONTROL_TOWER_ACCOUNT"))
|
||||
.body("ProvisionedProductDetail.ProductId",
|
||||
equalTo(ServiceCatalogService.CONTROL_TOWER_PRODUCT_ID));
|
||||
|
||||
organizations("ListAccounts", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accounts.Email", hasItem(email));
|
||||
|
||||
call("TerminateProvisionedProduct", "{\"ProvisionedProductName\":\"ab-provision-account-factory\","
|
||||
+ "\"TerminateToken\":\"tok-terminate-account-factory\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code DescribeProvisionedProduct},
|
||||
* {@code UpdateProvisionedProduct}, {@code UpdateProvisionedProductProperties} and
|
||||
* {@code TerminateProvisionedProduct}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). {@code UpdateProvisionedProduct},
|
||||
* {@code UpdateProvisionedProductProperties} and {@code TerminateProvisionedProduct}
|
||||
* all had the same RecordId-discard bug as issues 0021/0023 — fixed the same way.
|
||||
* {@code TerminateProvisionedProduct} also had its {@code RecordType} hardcoded to
|
||||
* the wrong value ({@code PROVISION} instead of
|
||||
* {@code TERMINATE_PROVISIONED_PRODUCT}) and conflated the provisioned product's own
|
||||
* {@code TERMINATED} status with the record's {@code SUCCEEDED} outcome status;
|
||||
* both fixed. {@code UpdateProvisionedProduct} does not apply any request fields —
|
||||
* documented as a validate-and-echo limitation (CS-021 precedent), not fixed further.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogProvisionedProductLifecycleConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String firstArtifactId(String productId) {
|
||||
return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails[0].Id");
|
||||
}
|
||||
|
||||
private static String importProvisionedProduct(String productId, String artifactId, String name) {
|
||||
return call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
|
||||
+ name + "\",\"PhysicalId\":\"phys-" + name + "\",\"IdempotencyToken\":\"tok-" + name + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("RecordDetail.ProvisionedProductId");
|
||||
}
|
||||
|
||||
// ---------- DescribeProvisionedProduct ----------
|
||||
|
||||
@Test
|
||||
void describeProvisionedProduct_returnsImportedProduct() {
|
||||
String productId = createProduct("ab-describe-pp-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String provisionedId = importProvisionedProduct(productId, artifactId, "ab-describe-pp");
|
||||
|
||||
call("DescribeProvisionedProduct", "{\"Id\":\"" + provisionedId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisionedProductDetail.Id", equalTo(provisionedId))
|
||||
.body("ProvisionedProductDetail.Status", equalTo("AVAILABLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeProvisionedProduct_unknownId_returnsResourceNotFound() {
|
||||
call("DescribeProvisionedProduct", "{\"Id\":\"pp-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- UpdateProvisionedProduct ----------
|
||||
|
||||
@Test
|
||||
void updateProvisionedProduct_returnsDescribableRecord() {
|
||||
String productId = createProduct("ab-update-pp-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String provisionedId = importProvisionedProduct(productId, artifactId, "ab-update-pp");
|
||||
|
||||
String recordId = call("UpdateProvisionedProduct", "{\"ProvisionedProductId\":\"" + provisionedId
|
||||
+ "\",\"UpdateToken\":\"tok-update-pp\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.ProvisionedProductId", equalTo(provisionedId))
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"))
|
||||
.extract().path("RecordDetail.RecordId");
|
||||
|
||||
call("DescribeRecord", "{\"Id\":\"" + recordId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.RecordType", equalTo("UPDATE_PROVISIONED_PRODUCT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateProvisionedProduct_unknownProduct_returnsResourceNotFound() {
|
||||
call("UpdateProvisionedProduct", "{\"ProvisionedProductId\":\"pp-doesnotexist\","
|
||||
+ "\"UpdateToken\":\"tok-update-unknown\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- UpdateProvisionedProductProperties ----------
|
||||
|
||||
@Test
|
||||
void updateProvisionedProductProperties_persistsProperties() {
|
||||
String productId = createProduct("ab-update-pp-props-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String provisionedId = importProvisionedProduct(productId, artifactId, "ab-update-pp-props");
|
||||
|
||||
call("UpdateProvisionedProductProperties", "{\"ProvisionedProductId\":\"" + provisionedId
|
||||
+ "\",\"ProvisionedProductProperties\":{\"OWNER\":\"someone-else\"},\"IdempotencyToken\":\""
|
||||
+ "tok-update-props\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Status", equalTo("SUCCEEDED"));
|
||||
|
||||
call("DescribeProvisionedProduct", "{\"Id\":\"" + provisionedId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisionedProductDetail.Id", equalTo(provisionedId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateProvisionedProductProperties_unknownProduct_returnsResourceNotFound() {
|
||||
call("UpdateProvisionedProductProperties", "{\"ProvisionedProductId\":\"pp-doesnotexist\","
|
||||
+ "\"ProvisionedProductProperties\":{\"OWNER\":\"x\"},\"IdempotencyToken\":\"tok-unknown\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- TerminateProvisionedProduct ----------
|
||||
|
||||
@Test
|
||||
void terminateProvisionedProduct_marksTerminatedAndReturnsDescribableRecord() {
|
||||
String productId = createProduct("ab-terminate-pp-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String provisionedId = importProvisionedProduct(productId, artifactId, "ab-terminate-pp");
|
||||
|
||||
String recordId = call("TerminateProvisionedProduct", "{\"ProvisionedProductId\":\""
|
||||
+ provisionedId + "\",\"TerminateToken\":\"tok-terminate-pp\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.ProvisionedProductId", equalTo(provisionedId))
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"))
|
||||
.body("RecordDetail.RecordType", equalTo("TERMINATE_PROVISIONED_PRODUCT"))
|
||||
.extract().path("RecordDetail.RecordId");
|
||||
|
||||
call("DescribeProvisionedProduct", "{\"Id\":\"" + provisionedId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisionedProductDetail.Status", equalTo("TERMINATED"));
|
||||
|
||||
call("DescribeRecord", "{\"Id\":\"" + recordId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.RecordType", equalTo("TERMINATE_PROVISIONED_PRODUCT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void terminateProvisionedProduct_unknownProduct_returnsResourceNotFound() {
|
||||
call("TerminateProvisionedProduct", "{\"ProvisionedProductId\":\"pp-doesnotexist\","
|
||||
+ "\"TerminateToken\":\"tok-terminate-unknown\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code CreateProvisionedProductPlan},
|
||||
* {@code DescribeProvisionedProductPlan}, {@code ExecuteProvisionedProductPlan},
|
||||
* {@code DeleteProvisionedProductPlan} and {@code ListProvisionedProductPlans}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). This family had no persistence at all before this session's
|
||||
* fix: {@code createProvisionedProductPlan} built and returned a plan object without
|
||||
* ever storing it, so every other operation in the family failed on a freshly
|
||||
* created plan — {@code describeProvisionedProductPlan} and
|
||||
* {@code deleteProvisionedProductPlan} always 404'd, and
|
||||
* {@code listProvisionedProductPlans} scanned the wrong store entirely
|
||||
* (provisioned products, not plans). Persistence was added via
|
||||
* {@code associationStore} with a new {@code Type: "PROVISIONED_PRODUCT_PLAN"}
|
||||
* discriminator, per this project's established convention for relationships with
|
||||
* no dedicated store. Three of the five handler methods for this family each
|
||||
* expected different field names on the same conceptual object ({@code PlanId} vs
|
||||
* {@code Id}, {@code PlanName} vs {@code Name}) — the stored plan object carries
|
||||
* both names for every dual-named field so each handler's existing (untouched)
|
||||
* response-building code keeps working.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogProvisionedProductPlanConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String firstArtifactId(String productId) {
|
||||
return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails[0].Id");
|
||||
}
|
||||
|
||||
private static String createPlan(String productId, String artifactId, String planName) {
|
||||
return call("CreateProvisionedProductPlan", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"PlanName\":\"" + planName
|
||||
+ "\",\"PlanType\":\"CLOUDFORMATION\",\"ProvisionedProductName\":\"" + planName
|
||||
+ "-pp\",\"IdempotencyToken\":\"tok-" + planName + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("PlanId");
|
||||
}
|
||||
|
||||
// ---------- CreateProvisionedProductPlan ----------
|
||||
|
||||
/**
|
||||
* ProvisionedProductPlanType has exactly one member, CLOUDFORMATION. The plan was
|
||||
* created for any PlanType string and then described as CLOUDFORMATION regardless,
|
||||
* so a caller asking for a plan type AWS does not offer got a fake success.
|
||||
*/
|
||||
@Test
|
||||
void createProvisionedProductPlan_unknownPlanType_returnsInvalidParameters() {
|
||||
String productId = createProduct("ab-plan-badtype");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
|
||||
call("CreateProvisionedProductPlan", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId
|
||||
+ "\",\"PlanName\":\"ab-plan-badtype\",\"PlanType\":\"TERRAFORM\","
|
||||
+ "\"ProvisionedProductName\":\"ab-plan-badtype-pp\","
|
||||
+ "\"IdempotencyToken\":\"tok-ab-plan-badtype\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"))
|
||||
.body("message", org.hamcrest.Matchers.startsWith("PlanType must be one of"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createProvisionedProductPlan_returnsPlanMatchingRequest() {
|
||||
String productId = createProduct("ab-plan-create-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
|
||||
call("CreateProvisionedProductPlan", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"PlanName\":\"ab-create-plan\","
|
||||
+ "\"PlanType\":\"CLOUDFORMATION\",\"ProvisionedProductName\":\"ab-create-plan-pp\","
|
||||
+ "\"IdempotencyToken\":\"tok-create-plan\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("PlanName", equalTo("ab-create-plan"))
|
||||
.body("ProvisionProductId", equalTo(productId))
|
||||
.body("ProvisioningArtifactId", equalTo(artifactId))
|
||||
.body("PlanId", org.hamcrest.Matchers.notNullValue());
|
||||
}
|
||||
|
||||
// ---------- DescribeProvisionedProductPlan ----------
|
||||
|
||||
@Test
|
||||
void describeProvisionedProductPlan_returnsCreatedPlan() {
|
||||
String productId = createProduct("ab-plan-describe-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String planId = createPlan(productId, artifactId, "ab-describe-plan");
|
||||
|
||||
call("DescribeProvisionedProductPlan", "{\"PlanId\":\"" + planId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisionedProductPlanDetails.PlanId", equalTo(planId))
|
||||
.body("ProvisionedProductPlanDetails.PlanName", equalTo("ab-describe-plan"))
|
||||
.body("ProvisionedProductPlanDetails.ProvisionProductId", equalTo(productId))
|
||||
.body("ProvisionedProductPlanDetails.ProvisionProductName", equalTo("ab-describe-plan-pp"))
|
||||
.body("ProvisionedProductPlanDetails.ProductId", equalTo(productId))
|
||||
.body("ProvisionedProductPlanDetails.ProvisioningArtifactId", equalTo(artifactId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeProvisionedProductPlan_unknownId_returnsResourceNotFound() {
|
||||
call("DescribeProvisionedProductPlan", "{\"PlanId\":\"plan-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- ExecuteProvisionedProductPlan ----------
|
||||
|
||||
@Test
|
||||
void executeProvisionedProductPlan_returnsRecordDetail() {
|
||||
String productId = createProduct("ab-plan-execute-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String planId = createPlan(productId, artifactId, "ab-execute-plan");
|
||||
|
||||
call("ExecuteProvisionedProductPlan", "{\"PlanId\":\"" + planId
|
||||
+ "\",\"IdempotencyToken\":\"tok-execute-plan\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void executeProvisionedProductPlan_unknownId_returnsResourceNotFound() {
|
||||
call("ExecuteProvisionedProductPlan", "{\"PlanId\":\"plan-doesnotexist\","
|
||||
+ "\"IdempotencyToken\":\"tok-execute-unknown\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- DeleteProvisionedProductPlan ----------
|
||||
|
||||
@Test
|
||||
void deleteProvisionedProductPlan_removesPlan() {
|
||||
String productId = createProduct("ab-plan-delete-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String planId = createPlan(productId, artifactId, "ab-delete-plan");
|
||||
|
||||
call("DeleteProvisionedProductPlan", "{\"PlanId\":\"" + planId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("DescribeProvisionedProductPlan", "{\"PlanId\":\"" + planId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteProvisionedProductPlan_unknownId_returnsResourceNotFound() {
|
||||
call("DeleteProvisionedProductPlan", "{\"PlanId\":\"plan-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- ListProvisionedProductPlans ----------
|
||||
|
||||
@Test
|
||||
void listProvisionedProductPlans_scopedToProvisionProductId_returnsOnlyMatchingPlans() {
|
||||
String productA = createProduct("ab-plan-list-product-a");
|
||||
String artifactA = firstArtifactId(productA);
|
||||
String planA = createPlan(productA, artifactA, "ab-list-plan-a");
|
||||
|
||||
String productB = createProduct("ab-plan-list-product-b");
|
||||
String artifactB = firstArtifactId(productB);
|
||||
createPlan(productB, artifactB, "ab-list-plan-b");
|
||||
|
||||
call("ListProvisionedProductPlans", "{\"ProvisionProductId\":\"" + productA + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisionedProductPlans.PlanId", hasItem(planA))
|
||||
.body("ProvisionedProductPlans[0].PlanName", equalTo("ab-list-plan-a"))
|
||||
.body("ProvisionedProductPlans[0].ProvisionProductId", equalTo(productA))
|
||||
.body("ProvisionedProductPlans[0].ProvisionProductName", equalTo("ab-list-plan-a-pp"))
|
||||
.body("ProvisionedProductPlans.size()", equalTo(1));
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code ImportAsProvisionedProduct},
|
||||
* {@code GetProvisionedProductOutputs} and {@code ScanProvisionedProducts}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogProvisionedProductQueryConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String firstArtifactId(String productId) {
|
||||
return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails[0].Id");
|
||||
}
|
||||
|
||||
private static String importProvisionedProduct(String productId, String artifactId, String name) {
|
||||
return call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
|
||||
+ name + "\",\"PhysicalId\":\"phys-" + name + "\",\"IdempotencyToken\":\"tok-" + name + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("RecordDetail.ProvisionedProductId");
|
||||
}
|
||||
|
||||
// ---------- ImportAsProvisionedProduct ----------
|
||||
|
||||
@Test
|
||||
void importAsProvisionedProduct_returnsRecordMatchingRequest() {
|
||||
String productId = createProduct("ab-import-pp-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
|
||||
call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
|
||||
+ "ab-import-pp\",\"PhysicalId\":\"phys-ab-import-pp\",\"IdempotencyToken\":\""
|
||||
+ "tok-ab-import-pp\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.ProvisionedProductName", equalTo("ab-import-pp"))
|
||||
.body("RecordDetail.ProductId", equalTo(productId))
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"))
|
||||
.body("RecordDetail.RecordType", equalTo("IMPORT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void importAsProvisionedProduct_unknownProduct_returnsResourceNotFound() {
|
||||
call("ImportAsProvisionedProduct", "{\"ProductId\":\"prod-doesnotexist\","
|
||||
+ "\"ProvisioningArtifactId\":\"pa-anything\",\"ProvisionedProductName\":\"ab-x\","
|
||||
+ "\"PhysicalId\":\"phys-ab-x\",\"IdempotencyToken\":\"tok-ab-x\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- GetProvisionedProductOutputs ----------
|
||||
|
||||
@Test
|
||||
void getProvisionedProductOutputs_knownProduct_returnsEmptyOutputs() {
|
||||
String productId = createProduct("ab-outputs-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String provisionedId = importProvisionedProduct(productId, artifactId, "ab-outputs-pp");
|
||||
|
||||
call("GetProvisionedProductOutputs", "{\"ProvisionedProductId\":\"" + provisionedId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Outputs.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getProvisionedProductOutputs_unknownProduct_returnsResourceNotFound() {
|
||||
call("GetProvisionedProductOutputs", "{\"ProvisionedProductId\":\"pp-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getProvisionedProductOutputs_missingIdAndName_returnsInvalidParameters() {
|
||||
call("GetProvisionedProductOutputs", "{}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
|
||||
// ---------- ScanProvisionedProducts ----------
|
||||
|
||||
@Test
|
||||
void scanProvisionedProducts_includesImportedProduct() {
|
||||
String productId = createProduct("ab-scan-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String provisionedId = importProvisionedProduct(productId, artifactId, "ab-scan-pp");
|
||||
|
||||
call("ScanProvisionedProducts", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisionedProducts.Id", hasItem(provisionedId));
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code CreateProvisioningArtifact},
|
||||
* {@code UpdateProvisioningArtifact}, {@code DeleteProvisioningArtifact} and
|
||||
* {@code ListProvisioningArtifactsForServiceAction}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). {@code ListProvisioningArtifactsForServiceAction} always
|
||||
* returns an empty list — no association between service actions and provisioning
|
||||
* artifacts is tracked for this specific listing (documented as a limitation, not a
|
||||
* bug: unlike {@code ListServiceActions} before this session's fix, nothing else in
|
||||
* the codebase persists data this operation could read).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogProvisioningArtifactConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String firstArtifactId(String productId) {
|
||||
return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails[0].Id");
|
||||
}
|
||||
|
||||
// ---------- CreateProvisioningArtifact ----------
|
||||
|
||||
@Test
|
||||
void createProvisioningArtifact_addsSecondArtifact() {
|
||||
String productId = createProduct("ab-artifact-create");
|
||||
|
||||
call("CreateProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"Parameters\":{\"Name\":\"v2\"},\"IdempotencyToken\":\"tok-create-artifact\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisioningArtifactDetail.Name", equalTo("v2"))
|
||||
.body("Status", equalTo("AVAILABLE"));
|
||||
|
||||
call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisioningArtifactDetails.Name", hasItem("v2"))
|
||||
.body("ProvisioningArtifactDetails.size()", equalTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createProvisioningArtifact_unknownProduct_returnsResourceNotFound() {
|
||||
call("CreateProvisioningArtifact", "{\"ProductId\":\"prod-doesnotexist\","
|
||||
+ "\"Parameters\":{\"Name\":\"v2\"},\"IdempotencyToken\":\"tok-unknown-product\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- UpdateProvisioningArtifact ----------
|
||||
|
||||
@Test
|
||||
void updateProvisioningArtifact_changesName() {
|
||||
String productId = createProduct("ab-artifact-update");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
|
||||
call("UpdateProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"Name\":\"v1-renamed\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisioningArtifactDetail.Name", equalTo("v1-renamed"));
|
||||
|
||||
call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisioningArtifactDetails.Name", hasItem("v1-renamed"));
|
||||
}
|
||||
|
||||
// ---------- DeleteProvisioningArtifact ----------
|
||||
|
||||
@Test
|
||||
void deleteProvisioningArtifact_removesArtifact() {
|
||||
String productId = createProduct("ab-artifact-delete");
|
||||
call("CreateProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"Parameters\":{\"Name\":\"v2-to-delete\"},\"IdempotencyToken\":\"tok-delete-artifact\"}")
|
||||
.then().statusCode(200);
|
||||
String artifactId = call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails.find { it.Name == 'v2-to-delete' }.Id");
|
||||
|
||||
call("DeleteProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisioningArtifactDetails.Name", org.hamcrest.Matchers.not(hasItem("v2-to-delete")));
|
||||
}
|
||||
|
||||
// ---------- ListProvisioningArtifactsForServiceAction ----------
|
||||
|
||||
@Test
|
||||
void listProvisioningArtifactsForServiceAction_returnsEmptyList() {
|
||||
call("ListProvisioningArtifactsForServiceAction", "{\"ServiceActionId\":\"sa-anything\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProvisioningArtifactViews.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listProvisioningArtifactsForServiceAction_missingServiceActionId_returnsInvalidParameters() {
|
||||
call("ListProvisioningArtifactsForServiceAction", "{}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"));
|
||||
}
|
||||
}
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code DescribeRecord}, {@code ListRecordHistory},
|
||||
* {@code ListResourcesForTagOption}, {@code ListStackInstancesForProvisionedProduct}
|
||||
* and {@code ListServiceActionsForProvisioningArtifact}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). {@code describeRecord} looked up records via a
|
||||
* {@code Type: "RECORD"} association row that nothing ever wrote — every
|
||||
* record-producing operation generated a throwaway random {@code RecordId} in the
|
||||
* handler layer and discarded it, so {@code DescribeRecord} 404'd unconditionally.
|
||||
* Fixed for {@code ImportAsProvisionedProduct}'s path (the one this session already
|
||||
* covers): the service now persists a {@code RECORD} row and returns its id, and the
|
||||
* handler uses that id instead of generating its own. Other record-producing
|
||||
* operations (e.g. {@code ExecuteProvisionedProductServiceAction},
|
||||
* {@code TerminateProvisionedProduct}) still generate unpersisted record ids and
|
||||
* remain undescribable — documented as a limitation, not fixed here (out of this
|
||||
* op-family's scope; same fix pattern applies when those ops are tested).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogRecordAndResourceQueryConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String firstArtifactId(String productId) {
|
||||
return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails[0].Id");
|
||||
}
|
||||
|
||||
// ---------- DescribeRecord ----------
|
||||
|
||||
@Test
|
||||
void describeRecord_returnsRecordForImportedProduct() {
|
||||
String productId = createProduct("ab-record-describe-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String recordId = call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
|
||||
+ "ab-record-describe-pp\",\"PhysicalId\":\"phys-ab-record-describe\","
|
||||
+ "\"IdempotencyToken\":\"tok-ab-record-describe\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("RecordDetail.RecordId");
|
||||
|
||||
call("DescribeRecord", "{\"Id\":\"" + recordId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.RecordId", equalTo(recordId))
|
||||
.body("RecordDetail.ProductId", equalTo(productId))
|
||||
.body("RecordDetail.RecordType", equalTo("IMPORT"))
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRecord_unknownId_returnsResourceNotFound() {
|
||||
call("DescribeRecord", "{\"Id\":\"rec-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- ListRecordHistory ----------
|
||||
|
||||
@Test
|
||||
void listRecordHistory_includesImportedProduct() {
|
||||
String productId = createProduct("ab-record-history-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String provisionedId = call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
|
||||
+ "ab-record-history-pp\",\"PhysicalId\":\"phys-ab-record-history\","
|
||||
+ "\"IdempotencyToken\":\"tok-ab-record-history\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("RecordDetail.ProvisionedProductId");
|
||||
|
||||
call("ListRecordHistory", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetails.ProvisionedProductId", hasItem(provisionedId));
|
||||
}
|
||||
|
||||
// ---------- ListResourcesForTagOption ----------
|
||||
|
||||
@Test
|
||||
void listResourcesForTagOption_returnsAssociatedProduct() {
|
||||
String productId = createProduct("ab-tagoption-product");
|
||||
String tagOptionId = call("CreateTagOption", "{\"Key\":\"env\",\"Value\":\"prod\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("TagOptionDetail.Id");
|
||||
call("AssociateTagOptionWithResource", "{\"ResourceId\":\"" + productId
|
||||
+ "\",\"TagOptionId\":\"" + tagOptionId + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("ListResourcesForTagOption", "{\"TagOptionId\":\"" + tagOptionId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ResourceDetails.Id", hasItem(productId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listResourcesForTagOption_unknownTagOption_returnsResourceNotFound() {
|
||||
call("ListResourcesForTagOption", "{\"TagOptionId\":\"tag-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- ListStackInstancesForProvisionedProduct ----------
|
||||
|
||||
@Test
|
||||
void listStackInstancesForProvisionedProduct_returnsInstanceForImportedProduct() {
|
||||
String productId = createProduct("ab-stackinstances-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String provisionedId = call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
|
||||
+ "ab-stackinstances-pp\",\"PhysicalId\":\"phys-ab-stackinstances\","
|
||||
+ "\"IdempotencyToken\":\"tok-ab-stackinstances\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("RecordDetail.ProvisionedProductId");
|
||||
|
||||
call("ListStackInstancesForProvisionedProduct", "{\"ProvisionedProductId\":\""
|
||||
+ provisionedId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("StackInstances.size()", org.hamcrest.Matchers.greaterThan(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listStackInstancesForProvisionedProduct_unknownProduct_returnsResourceNotFound() {
|
||||
call("ListStackInstancesForProvisionedProduct", "{\"ProvisionedProductId\":\"pp-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- ListServiceActionsForProvisioningArtifact ----------
|
||||
|
||||
@Test
|
||||
void listServiceActionsForProvisioningArtifact_knownArtifact_returnsEmptyList() {
|
||||
String productId = createProduct("ab-safpa-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
|
||||
call("ListServiceActionsForProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ServiceActionSummaries.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listServiceActionsForProvisioningArtifact_unknownArtifact_returnsResourceNotFound() {
|
||||
String productId = createProduct("ab-safpa-unknown-product");
|
||||
|
||||
call("ListServiceActionsForProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"pa-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Wire-level tests for the {@code ResourceInUseException} guard on
|
||||
* {@code DeletePortfolio} and {@code DeleteProduct}.
|
||||
*
|
||||
* <p>Both operations used to delete the resource and then cascade — removing every
|
||||
* association naming the portfolio and every share keyed to it. AWS does the opposite
|
||||
* and refuses the call: "You cannot delete a portfolio if it was shared with you or if
|
||||
* it has associated products, users, constraints, or shared accounts", and
|
||||
* "You cannot delete a product if it was shared with you or is associated with a
|
||||
* portfolio". Both model {@code ResourceInUseException}. The old behaviour turned a
|
||||
* recoverable no-op into unrecoverable data loss reported as 200, which is what these
|
||||
* tests pin.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogResourceInUseConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createPortfolio(String name) {
|
||||
return call("CreatePortfolio", "{\"DisplayName\":\"" + name + "\",\"ProviderName\":\"floci-test\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("PortfolioDetail.Id");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
// ---------- DeletePortfolio ----------
|
||||
|
||||
@Test
|
||||
void deletePortfolio_withAssociatedProduct_returnsResourceInUseAndKeepsPortfolio() {
|
||||
String portfolioId = createPortfolio("ab-inuse-portfolio-product");
|
||||
String productId = createProduct("ab-inuse-portfolio-product-prod");
|
||||
call("AssociateProductWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"ProductId\":\"" + productId + "\"}").then().statusCode(200);
|
||||
|
||||
call("DeletePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceInUseException"));
|
||||
|
||||
call("DescribePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("PortfolioDetail.Id", equalTo(portfolioId));
|
||||
|
||||
// the association the old cascade would have destroyed is still there
|
||||
call("ListPortfoliosForProduct", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("PortfolioDetails.Id", org.hamcrest.Matchers.hasItem(portfolioId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePortfolio_withAssociatedPrincipal_returnsResourceInUse() {
|
||||
String portfolioId = createPortfolio("ab-inuse-portfolio-principal");
|
||||
call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"PrincipalARN\":\"arn:aws:iam::000000000000:role/ab-inuse\","
|
||||
+ "\"PrincipalType\":\"IAM\"}").then().statusCode(200);
|
||||
|
||||
call("DeletePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceInUseException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePortfolio_withSharedAccount_returnsResourceInUse() {
|
||||
String portfolioId = createPortfolio("ab-inuse-portfolio-share");
|
||||
call("CreatePortfolioShare", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"AccountId\":\"111111111111\"}").then().statusCode(200);
|
||||
|
||||
call("DeletePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceInUseException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePortfolio_withNothingAssociated_deletesIt() {
|
||||
String portfolioId = createPortfolio("ab-inuse-portfolio-clean");
|
||||
|
||||
call("DeletePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("DescribePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- DeleteProduct ----------
|
||||
|
||||
@Test
|
||||
void deleteProduct_associatedWithPortfolio_returnsResourceInUseAndKeepsProduct() {
|
||||
String portfolioId = createPortfolio("ab-inuse-product-portfolio");
|
||||
String productId = createProduct("ab-inuse-product-associated");
|
||||
call("AssociateProductWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
|
||||
+ "\",\"ProductId\":\"" + productId + "\"}").then().statusCode(200);
|
||||
|
||||
call("DeleteProduct", "{\"Id\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceInUseException"));
|
||||
|
||||
call("DescribeProductAsAdmin", "{\"Id\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ProductViewDetail.ProductViewSummary.Id", equalTo(productId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteProduct_withNoPortfolioAssociation_deletesIt() {
|
||||
String productId = createProduct("ab-inuse-product-clean");
|
||||
|
||||
call("DeleteProduct", "{\"Id\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("DescribeProductAsAdmin", "{\"Id\":\"" + productId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code AssociateServiceActionWithProvisioningArtifact},
|
||||
* {@code DisassociateServiceActionFromProvisioningArtifact},
|
||||
* {@code BatchAssociateServiceActionWithProvisioningArtifact} and
|
||||
* {@code BatchDisassociateServiceActionFromProvisioningArtifact}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). Found two real bugs in this family:
|
||||
*
|
||||
* <ol>
|
||||
* <li>{@code disassociateServiceActionFromProvisioningArtifact} validated the
|
||||
* product/artifact existed but never actually deleted the association — a
|
||||
* complete no-op beyond validation. Fixed to look up and delete the row.</li>
|
||||
* <li>the single-op, batch-associate, and batch-disassociate paths each computed
|
||||
* a <em>different</em> association-store key for the conceptually identical
|
||||
* (product, artifact, service action) triple — batch-associate omitted
|
||||
* {@code productId} entirely, and batch-disassociate used a hand-rolled key with
|
||||
* a missing underscore ({@code "serviceaction|..."} vs {@code "service_action|..."})
|
||||
* that didn't match either of the other two. Associations created one way could
|
||||
* not be found or removed another way. Unified all three onto the single-op's key
|
||||
* formula.</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p>{@code associateServiceActionWithProvisioningArtifact_thenDisassociatedViaBatch}
|
||||
* and its mirror below are what would have caught #2 — they cross the single/batch
|
||||
* boundary deliberately.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogServiceActionArtifactAssociationConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createProduct(String name) {
|
||||
return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
|
||||
+ "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
}
|
||||
|
||||
private static String firstArtifactId(String productId) {
|
||||
return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails[0].Id");
|
||||
}
|
||||
|
||||
private static String createServiceAction(String name) {
|
||||
return call("CreateServiceAction", "{\"Name\":\"" + name + "\",\"DefinitionType\":\""
|
||||
+ "SSM_AUTOMATION\",\"Definition\":{\"Name\":\"AWS-RestartEC2Instance\"},"
|
||||
+ "\"IdempotencyToken\":\"tok-" + name + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ServiceActionDetail.ServiceActionSummary.Id");
|
||||
}
|
||||
|
||||
// ---------- AssociateServiceActionWithProvisioningArtifact ----------
|
||||
|
||||
@Test
|
||||
void associateServiceActionWithProvisioningArtifact_returnsEmptyBody() {
|
||||
String productId = createProduct("ab-assoc-sa-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String actionId = createServiceAction("ab-assoc-sa-action");
|
||||
|
||||
call("AssociateServiceActionWithProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
|
||||
+ actionId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
// ---------- DisassociateServiceActionFromProvisioningArtifact ----------
|
||||
|
||||
@Test
|
||||
void disassociateServiceActionFromProvisioningArtifact_removesAssociation() {
|
||||
String productId = createProduct("ab-disassoc-sa-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String actionId = createServiceAction("ab-disassoc-sa-action");
|
||||
call("AssociateServiceActionWithProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
|
||||
+ actionId + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("DisassociateServiceActionFromProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
|
||||
+ actionId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Repeating the disassociate proves the row is really gone, not just
|
||||
// validated: the second call must now fail since nothing is left to remove.
|
||||
call("DisassociateServiceActionFromProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
|
||||
+ actionId + "\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- BatchAssociateServiceActionWithProvisioningArtifact ----------
|
||||
|
||||
@Test
|
||||
void batchAssociateServiceActionWithProvisioningArtifact_returnsNoFailures() {
|
||||
String productId = createProduct("ab-batch-assoc-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String actionId = createServiceAction("ab-batch-assoc-action");
|
||||
|
||||
call("BatchAssociateServiceActionWithProvisioningArtifact", "{\"ServiceActionAssociations\":["
|
||||
+ "{\"ProductId\":\"" + productId + "\",\"ProvisioningArtifactId\":\"" + artifactId
|
||||
+ "\",\"ServiceActionId\":\"" + actionId + "\"}]}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FailedServiceActionAssociations.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void batchAssociateServiceActionWithProvisioningArtifact_unknownProduct_returnsFailureEntry() {
|
||||
call("BatchAssociateServiceActionWithProvisioningArtifact", "{\"ServiceActionAssociations\":["
|
||||
+ "{\"ProductId\":\"prod-doesnotexist\",\"ProvisioningArtifactId\":\"pa-x\","
|
||||
+ "\"ServiceActionId\":\"sa-x\"}]}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FailedServiceActionAssociations[0].ErrorCode", equalTo("RESOURCE_NOT_FOUND"));
|
||||
}
|
||||
|
||||
/** Crosses the single/batch boundary — proves the key formulas were unified. */
|
||||
@Test
|
||||
void associateViaBatch_thenDisassociatedViaSingleOp() {
|
||||
String productId = createProduct("ab-cross-batch-to-single-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String actionId = createServiceAction("ab-cross-batch-to-single-action");
|
||||
|
||||
call("BatchAssociateServiceActionWithProvisioningArtifact", "{\"ServiceActionAssociations\":["
|
||||
+ "{\"ProductId\":\"" + productId + "\",\"ProvisioningArtifactId\":\"" + artifactId
|
||||
+ "\",\"ServiceActionId\":\"" + actionId + "\"}]}")
|
||||
.then().statusCode(200)
|
||||
.body("FailedServiceActionAssociations.size()", equalTo(0));
|
||||
|
||||
call("DisassociateServiceActionFromProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
|
||||
+ actionId + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
// ---------- BatchDisassociateServiceActionFromProvisioningArtifact ----------
|
||||
|
||||
/** Crosses the single/batch boundary the other direction. */
|
||||
@Test
|
||||
void associateViaSingleOp_thenDisassociatedViaBatch() {
|
||||
String productId = createProduct("ab-cross-single-to-batch-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String actionId = createServiceAction("ab-cross-single-to-batch-action");
|
||||
|
||||
call("AssociateServiceActionWithProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
|
||||
+ actionId + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("BatchDisassociateServiceActionFromProvisioningArtifact", "{\"ServiceActionAssociations\":["
|
||||
+ "{\"ProductId\":\"" + productId + "\",\"ProvisioningArtifactId\":\"" + artifactId
|
||||
+ "\",\"ServiceActionId\":\"" + actionId + "\"}]}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void batchDisassociateServiceActionFromProvisioningArtifact_unknownAssociation_returnsFailureEntry() {
|
||||
String productId = createProduct("ab-batch-disassoc-unknown-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
|
||||
call("BatchDisassociateServiceActionFromProvisioningArtifact", "{\"ServiceActionAssociations\":["
|
||||
+ "{\"ProductId\":\"" + productId + "\",\"ProvisioningArtifactId\":\"" + artifactId
|
||||
+ "\",\"ServiceActionId\":\"sa-neverassociated\"}]}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("FailedServiceActionAssociations[0].ErrorCode", equalTo("RESOURCE_NOT_FOUND"));
|
||||
}
|
||||
}
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code CreateServiceAction}, {@code UpdateServiceAction},
|
||||
* {@code DeleteServiceAction} and {@code ListServiceActions}.
|
||||
*
|
||||
* <p>New class, not appended to an existing one, so falsifiability isolates per
|
||||
* operation (CS-001). These tests exercise the full create-update-delete-list
|
||||
* round trip deliberately: {@code createServiceAction} originally stored its record
|
||||
* under key {@code "service_action|" + id} while {@code deleteServiceAction} and
|
||||
* {@code updateServiceAction} looked it up / re-stored it under the raw {@code id} —
|
||||
* a key mismatch that made {@code DeleteServiceAction} always fail with
|
||||
* {@code ResourceNotFoundException} on a freshly-created action, and made
|
||||
* {@code UpdateServiceAction} silently duplicate the record instead of overwriting
|
||||
* it. {@code listServiceActions} was also a hardcoded-empty stub despite the other
|
||||
* three operations being fully storage-backed. All three were fixed together;
|
||||
* {@code listServiceActions_afterUpdate_hasNoDuplicates} is what would have caught
|
||||
* the duplication specifically.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ServiceCatalogServiceActionConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static String createServiceAction(String name) {
|
||||
return call("CreateServiceAction", "{\"Name\":\"" + name + "\",\"DefinitionType\":\""
|
||||
+ "SSM_AUTOMATION\",\"Definition\":{\"Name\":\"AWS-RestartEC2Instance\"},"
|
||||
+ "\"IdempotencyToken\":\"tok-" + name + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ServiceActionDetail.ServiceActionSummary.Id");
|
||||
}
|
||||
|
||||
// ---------- CreateServiceAction ----------
|
||||
|
||||
@Test
|
||||
void createServiceAction_returnsSummaryMatchingRequest() {
|
||||
call("CreateServiceAction", "{\"Name\":\"ab-create-action\",\"DefinitionType\":\""
|
||||
+ "SSM_AUTOMATION\",\"Definition\":{\"Name\":\"AWS-RestartEC2Instance\"},"
|
||||
+ "\"IdempotencyToken\":\"tok-create\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ServiceActionDetail.ServiceActionSummary.Name", equalTo("ab-create-action"))
|
||||
.body("ServiceActionDetail.ServiceActionSummary.DefinitionType", equalTo("SSM_AUTOMATION"))
|
||||
.body("ServiceActionDetail.ServiceActionSummary.Id", org.hamcrest.Matchers.notNullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* ServiceActionDefinitionType has exactly one member, SSM_AUTOMATION. Any other value
|
||||
* was stored verbatim and handed back by DescribeServiceAction as a real action type.
|
||||
*/
|
||||
@Test
|
||||
void createServiceAction_unknownDefinitionType_returnsInvalidParameters() {
|
||||
call("CreateServiceAction", "{\"Name\":\"ab-action-badtype\",\"DefinitionType\":\""
|
||||
+ "LAMBDA\",\"Definition\":{\"Name\":\"AWS-RestartEC2Instance\"},"
|
||||
+ "\"IdempotencyToken\":\"tok-badtype\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParametersException"))
|
||||
.body("message", org.hamcrest.Matchers.startsWith("DefinitionType must be one of"));
|
||||
}
|
||||
|
||||
// ---------- DeleteServiceAction ----------
|
||||
|
||||
@Test
|
||||
void deleteServiceAction_removesFreshlyCreatedAction() {
|
||||
String id = createServiceAction("ab-delete-action");
|
||||
|
||||
call("DeleteServiceAction", "{\"Id\":\"" + id + "\"}")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("ListServiceActions", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ServiceActionSummaries.Id", org.hamcrest.Matchers.not(hasItem(id)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteServiceAction_unknownId_returnsResourceNotFound() {
|
||||
call("DeleteServiceAction", "{\"Id\":\"sa-doesnotexist\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ---------- UpdateServiceAction ----------
|
||||
|
||||
@Test
|
||||
void updateServiceAction_changesName() {
|
||||
String id = createServiceAction("ab-update-action-before");
|
||||
|
||||
call("UpdateServiceAction", "{\"Id\":\"" + id + "\",\"Name\":\"ab-update-action-after\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ServiceActionDetail.ServiceActionSummary.Id", equalTo(id))
|
||||
.body("ServiceActionDetail.ServiceActionSummary.Name", equalTo("ab-update-action-after"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listServiceActions_afterUpdate_hasNoDuplicates() {
|
||||
String id = createServiceAction("ab-update-nodupe");
|
||||
call("UpdateServiceAction", "{\"Id\":\"" + id + "\",\"Name\":\"ab-update-nodupe-2\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
Response list = call("ListServiceActions", "{}");
|
||||
list.then().statusCode(200);
|
||||
java.util.List<String> ids = list.jsonPath().getList("ServiceActionSummaries.Id", String.class);
|
||||
long matches = ids.stream().filter(id::equals).count();
|
||||
org.junit.jupiter.api.Assertions.assertEquals(1L, matches,
|
||||
"expected exactly one entry for " + id + " after update, found " + matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code associateServiceActionWithProvisioningArtifact} stores its association
|
||||
* row with the same {@code Type: "SERVICE_ACTION"} discriminator that service
|
||||
* action records themselves use, distinguished only by which fields are present
|
||||
* (association rows have no {@code Id} field). {@code listServiceActions()} must
|
||||
* filter those out, not just match on {@code Type}.
|
||||
*/
|
||||
@Test
|
||||
void listServiceActions_ignoresProvisioningArtifactAssociationRows() {
|
||||
String productId = call("CreateProduct", "{\"Name\":\"ab-action-artifact-product\","
|
||||
+ "\"Owner\":\"floci-test\",\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProductViewDetail.ProductViewSummary.Id");
|
||||
String artifactId = call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("ProvisioningArtifactDetails[0].Id");
|
||||
String actionId = createServiceAction("ab-action-for-artifact-assoc");
|
||||
|
||||
call("AssociateServiceActionWithProvisioningArtifact", "{\"ProductId\":\"" + productId
|
||||
+ "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
|
||||
+ actionId + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
Response list = call("ListServiceActions", "{}");
|
||||
list.then().statusCode(200);
|
||||
java.util.List<String> ids = list.jsonPath().getList("ServiceActionSummaries.Id", String.class);
|
||||
org.junit.jupiter.api.Assertions.assertFalse(ids.contains(""),
|
||||
"association row leaked into ListServiceActions with an empty Id: " + ids);
|
||||
org.junit.jupiter.api.Assertions.assertTrue(ids.contains(actionId),
|
||||
"the real service action should still be listed: " + ids);
|
||||
}
|
||||
|
||||
// ---------- ListServiceActions ----------
|
||||
|
||||
@Test
|
||||
void listServiceActions_includesCreatedAction() {
|
||||
String id = createServiceAction("ab-list-action");
|
||||
|
||||
call("ListServiceActions", "{}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ServiceActionSummaries.Id", hasItem(id));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user