mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 07:11:11 -05:00
test(compat): run the China-absent tests per partition instead of allowlisting them (#5027)
* test(compat): run the China-absent tests per partition instead of allowlisting them Third batch of the cn-north-1 allowlist burn-down (#4272): the 13 tests that exercised something AWS does not offer in China. Seven keep running there with the China shape: - S3Test: only the us-east-1 endpoint creates a bucket in another region, so elsewhere the location-constraint round trip names the client's own region. - StsTest: the SAML assertion's Recipient is the partition's console sign-on URL (the CDK region facts), signin.amazonaws.cn in China. - Ec2Tests: China names its interface endpoint services cn.com.amazonaws, so the S3 gateway and interface offerings are two services there. - IamTest: GetAccountSummary reports GlobalEndpointTokenVersion only in the commercial partition, the one with a global STS endpoint. Six skip where the service has no endpoint: the five Marketplace tests (the regions botocore publishes for each) and Lightsail (commercial only). The allowlist's China-absent section is gone, 13 entries, 73 to 60. * test(compat): derive VPC endpoint names from the DNS suffix and keep Marketplace guards to us-east-1 The ECR interface service is named under the partition's DNS suffix reversed in every China, EUSC and ISO region (eu.amazonaws, gov.ic.c2s, ...), not only in China, so describeVpcEndpointServices now takes that prefix from the SDK's partition metadata. S3 keeps the China-only split, the only regions where AWS lists it. Floci serves Marketplace Agreement and Entitlement only in us-east-1, so their guards no longer admit the other regions AWS runs them in; widening both is a separate change.
This commit is contained in:
1 parent
d5fd4d52f1
commit
6deb0d4d2b
11 files changed
+110
-43
No files matched your search
@@ -1,12 +1,15 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.regions.RegionMetadata;
|
||||
import software.amazon.awssdk.services.ec2.Ec2Client;
|
||||
import software.amazon.awssdk.services.ec2.model.*;
|
||||
import software.amazon.awssdk.services.ec2.model.Tag;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -947,24 +950,46 @@ class Ec2Tests {
|
||||
DescribeVpcEndpointServicesResponse resp = ec2.describeVpcEndpointServices(
|
||||
DescribeVpcEndpointServicesRequest.builder().build());
|
||||
|
||||
assertThat(resp.serviceNames()).contains("com.amazonaws.us-east-1.s3");
|
||||
// The S3 gateway keeps com.amazonaws everywhere. Outside the commercial partition and GovCloud,
|
||||
// AWS names some interface services under the partition's DNS suffix reversed (cn.com.amazonaws,
|
||||
// eu.amazonaws, gov.ic.c2s, ...): ecr.api in every China, EUSC and ISO region, S3 only in China,
|
||||
// where the two S3 offerings therefore split.
|
||||
String region = TestFixtures.region().id();
|
||||
String reversedSuffix = reversedDnsSuffix();
|
||||
String s3Gateway = "com.amazonaws." + region + ".s3";
|
||||
String s3Interface = ("aws-cn".equals(TestFixtures.partition()) ? reversedSuffix : "com.amazonaws")
|
||||
+ "." + region + ".s3";
|
||||
assertThat(resp.serviceNames()).contains(s3Gateway, s3Interface);
|
||||
assertThat(resp.serviceDetails()).isNotEmpty();
|
||||
|
||||
ServiceDetail s3 = resp.serviceDetails().stream()
|
||||
.filter(d -> d.serviceName().equals("com.amazonaws.us-east-1.s3"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
// S3 is the one service offering both endpoint types.
|
||||
assertThat(s3.serviceType().stream().map(ServiceTypeDetail::serviceTypeAsString).toList())
|
||||
.containsExactlyInAnyOrder("Gateway", "Interface");
|
||||
assertThat(s3.availabilityZones()).isNotEmpty();
|
||||
if (s3Interface.equals(s3Gateway)) {
|
||||
// S3 is the one service offering both endpoint types.
|
||||
assertThat(serviceTypes(resp, s3Gateway)).containsExactlyInAnyOrder("Gateway", "Interface");
|
||||
} else {
|
||||
assertThat(serviceTypes(resp, s3Gateway)).containsExactly("Gateway");
|
||||
assertThat(serviceTypes(resp, s3Interface)).containsExactly("Interface");
|
||||
}
|
||||
assertThat(serviceDetail(resp, s3Gateway).availabilityZones()).isNotEmpty();
|
||||
assertThat(serviceTypes(resp, reversedSuffix + "." + region + ".ecr.api")).containsExactly("Interface");
|
||||
}
|
||||
|
||||
ServiceDetail ecr = resp.serviceDetails().stream()
|
||||
.filter(d -> d.serviceName().equals("com.amazonaws.us-east-1.ecr.api"))
|
||||
private static String reversedDnsSuffix() {
|
||||
RegionMetadata metadata = TestFixtures.region().metadata();
|
||||
List<String> labels = new ArrayList<>(List.of(
|
||||
(metadata == null ? "amazonaws.com" : metadata.partition().dnsSuffix()).split("\\.")));
|
||||
Collections.reverse(labels);
|
||||
return String.join(".", labels);
|
||||
}
|
||||
|
||||
private static ServiceDetail serviceDetail(DescribeVpcEndpointServicesResponse resp, String name) {
|
||||
return resp.serviceDetails().stream()
|
||||
.filter(d -> d.serviceName().equals(name))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
assertThat(ecr.serviceType().stream().map(ServiceTypeDetail::serviceTypeAsString).toList())
|
||||
.containsExactly("Interface");
|
||||
}
|
||||
|
||||
private static List<String> serviceTypes(DescribeVpcEndpointServicesResponse resp, String name) {
|
||||
return serviceDetail(resp, name).serviceType().stream().map(ServiceTypeDetail::serviceTypeAsString).toList();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -477,7 +477,11 @@ class IamTest {
|
||||
@Order(101)
|
||||
void getAccountSummary() {
|
||||
GetAccountSummaryResponse response = iam.getAccountSummary();
|
||||
assertThat(response.summaryMap()).hasSize(34);
|
||||
// GlobalEndpointTokenVersion reports the global STS endpoint, which only the commercial partition has.
|
||||
boolean globalSts = "aws".equals(TestFixtures.partition());
|
||||
assertThat(response.summaryMap()).hasSize(globalSts ? 34 : 33);
|
||||
assertThat(response.summaryMap().containsKey(SummaryKeyType.GLOBAL_ENDPOINT_TOKEN_VERSION))
|
||||
.isEqualTo(globalSts);
|
||||
assertThat(response.summaryMap().get(SummaryKeyType.USERS_QUOTA)).isEqualTo(5000);
|
||||
assertThat(response.summaryMap().get(SummaryKeyType.GROUPS_QUOTA)).isEqualTo(300);
|
||||
assertThat(response.summaryMap().get(SummaryKeyType.ROLES_QUOTA)).isEqualTo(1000);
|
||||
|
||||
@@ -15,6 +15,7 @@ import software.amazon.awssdk.services.lightsail.model.StaticIp;
|
||||
import software.amazon.awssdk.services.lightsail.model.Tag;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
class LightsailTest {
|
||||
|
||||
@@ -29,6 +30,8 @@ class LightsailTest {
|
||||
|
||||
@Test
|
||||
void sdkCanCreateAndManageCoreLightsailResources() {
|
||||
assumeTrue("aws".equals(TestFixtures.partition()),
|
||||
"Lightsail has no region outside the commercial partition");
|
||||
String instanceName = suffix + "-web";
|
||||
String diskName = suffix + "-data";
|
||||
String staticIpName = suffix + "-ip";
|
||||
|
||||
+7
@@ -4,12 +4,19 @@ import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.marketplaceagreement.MarketplaceAgreementClient;
|
||||
import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
class MarketplaceAgreementTest {
|
||||
|
||||
private static final List<String> REGIONS = List.of("us-east-1");
|
||||
|
||||
@Test
|
||||
void usesAwsSdkWireContract() {
|
||||
assumeTrue(REGIONS.contains(TestFixtures.region().id()),
|
||||
"Floci serves AWS Marketplace Agreement only in us-east-1");
|
||||
try (MarketplaceAgreementClient client = TestFixtures.marketplaceAgreementClient()) {
|
||||
SearchAgreementsResponse response = client.searchAgreements(r -> r.filters(
|
||||
f -> f.name("AgreementType").values("PurchaseAgreement")));
|
||||
|
||||
+7
@@ -4,12 +4,19 @@ import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.marketplacecatalog.MarketplaceCatalogClient;
|
||||
import software.amazon.awssdk.services.marketplacecatalog.model.ListEntitiesResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
class MarketplaceCatalogTest {
|
||||
|
||||
private static final List<String> REGIONS = List.of("us-east-1");
|
||||
|
||||
@Test
|
||||
void usesAwsSdkWireContract() {
|
||||
assumeTrue(REGIONS.contains(TestFixtures.region().id()),
|
||||
"AWS Marketplace Catalog has no endpoint in this region");
|
||||
try (MarketplaceCatalogClient client = TestFixtures.marketplaceCatalogClient()) {
|
||||
ListEntitiesResponse response = client.listEntities(r -> r.catalog("AWSMarketplace").entityType("SaaSProduct"));
|
||||
assertNotNull(response.entitySummaryList());
|
||||
|
||||
+8
-1
@@ -4,13 +4,20 @@ import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.marketplacedeployment.MarketplaceDeploymentClient;
|
||||
import software.amazon.awssdk.services.marketplacedeployment.model.PutDeploymentParameterResponse;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
class MarketplaceDeploymentTest {
|
||||
|
||||
private static final List<String> REGIONS = List.of("us-east-1");
|
||||
|
||||
@Test
|
||||
void usesAwsSdkWireContract() {
|
||||
assumeTrue(REGIONS.contains(TestFixtures.region().id()),
|
||||
"AWS Marketplace Deployment has no endpoint in this region");
|
||||
try (MarketplaceDeploymentClient client = TestFixtures.marketplaceDeploymentClient()) {
|
||||
PutDeploymentParameterResponse response = client.putDeploymentParameter(r -> r
|
||||
.catalog("AWSMarketplace")
|
||||
|
||||
+7
@@ -4,13 +4,20 @@ import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.marketplacediscovery.MarketplaceDiscoveryClient;
|
||||
import software.amazon.awssdk.services.marketplacediscovery.model.SearchListingsResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
class MarketplaceDiscoveryTest {
|
||||
|
||||
private static final List<String> REGIONS = List.of("us-east-1", "us-west-2", "eu-west-1");
|
||||
|
||||
@Test
|
||||
void usesAwsSdkWireContract() {
|
||||
assumeTrue(REGIONS.contains(TestFixtures.region().id()),
|
||||
"Marketplace Discovery has no endpoint in this region");
|
||||
try (MarketplaceDiscoveryClient client = TestFixtures.marketplaceDiscoveryClient()) {
|
||||
SearchListingsResponse response = client.searchListings(r -> r.searchText("sdk-compat"));
|
||||
assertTrue(response.totalResults() >= 0);
|
||||
|
||||
+7
@@ -4,13 +4,20 @@ import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.marketplaceentitlement.MarketplaceEntitlementClient;
|
||||
import software.amazon.awssdk.services.marketplaceentitlement.model.GetEntitlementsResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
class MarketplaceEntitlementTest {
|
||||
|
||||
private static final List<String> REGIONS = List.of("us-east-1");
|
||||
|
||||
@Test
|
||||
void usesAwsSdkWireContract() {
|
||||
assumeTrue(REGIONS.contains(TestFixtures.region().id()),
|
||||
"Floci serves AWS Marketplace Entitlement only in us-east-1");
|
||||
try (MarketplaceEntitlementClient client = TestFixtures.marketplaceEntitlementClient()) {
|
||||
GetEntitlementsResponse response = client.getEntitlements(r -> r.productCode("product-local"));
|
||||
assertNotNull(response.entitlements());
|
||||
|
||||
@@ -54,7 +54,11 @@ class S3Test {
|
||||
|
||||
private static S3Client s3;
|
||||
private static final String BUCKET = "sdk-test-bucket";
|
||||
private static final String EU_BUCKET = "sdk-test-bucket-eu";
|
||||
private static final String LOCATED_BUCKET = "sdk-test-bucket-located";
|
||||
// Only the us-east-1 endpoint creates a bucket in another region; any other endpoint takes its own.
|
||||
private static final BucketLocationConstraint LOCATION = TestFixtures.region().id().equals("us-east-1")
|
||||
? BucketLocationConstraint.EU_CENTRAL_1
|
||||
: BucketLocationConstraint.fromValue(TestFixtures.region().id());
|
||||
private static final String KEY = "test-file.txt";
|
||||
private static final String CONTENT = "Hello from AWS SDK v2!";
|
||||
|
||||
@@ -73,7 +77,7 @@ class S3Test {
|
||||
s3.deleteBucket(DeleteBucketRequest.builder().bucket(BUCKET).build());
|
||||
} catch (Exception ignored) {}
|
||||
try {
|
||||
s3.deleteBucket(DeleteBucketRequest.builder().bucket(EU_BUCKET).build());
|
||||
s3.deleteBucket(DeleteBucketRequest.builder().bucket(LOCATED_BUCKET).build());
|
||||
} catch (Exception ignored) {}
|
||||
s3.close();
|
||||
}
|
||||
@@ -89,20 +93,20 @@ class S3Test {
|
||||
@Order(2)
|
||||
void createBucketWithLocationConstraint() {
|
||||
s3.createBucket(CreateBucketRequest.builder()
|
||||
.bucket(EU_BUCKET)
|
||||
.bucket(LOCATED_BUCKET)
|
||||
.createBucketConfiguration(CreateBucketConfiguration.builder()
|
||||
.locationConstraint(BucketLocationConstraint.EU_CENTRAL_1)
|
||||
.locationConstraint(LOCATION)
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getBucketLocationEuCentral1() {
|
||||
void getBucketLocationReturnsTheConstraint() {
|
||||
GetBucketLocationResponse response = s3.getBucketLocation(
|
||||
GetBucketLocationRequest.builder().bucket(EU_BUCKET).build());
|
||||
GetBucketLocationRequest.builder().bucket(LOCATED_BUCKET).build());
|
||||
|
||||
assertThat(response.locationConstraint()).isEqualTo(BucketLocationConstraint.EU_CENTRAL_1);
|
||||
assertThat(response.locationConstraint()).isEqualTo(LOCATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -385,8 +389,8 @@ class S3Test {
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
void deleteEuBucket() {
|
||||
s3.deleteBucket(DeleteBucketRequest.builder().bucket(EU_BUCKET).build());
|
||||
void deleteLocatedBucket() {
|
||||
s3.deleteBucket(DeleteBucketRequest.builder().bucket(LOCATED_BUCKET).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.time.Instant;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -61,6 +62,14 @@ class StsTest {
|
||||
private static String allowedRoleArn;
|
||||
private static String allowedRoleName;
|
||||
|
||||
// The console sign-on URL a bearer assertion names, per partition (the CDK region facts). A
|
||||
// partition the CDK lists none for keeps the commercial URL, as Floci does.
|
||||
private static final Map<String, String> SAML_SIGN_ON_URLS = Map.of(
|
||||
"aws", "https://signin.aws.amazon.com/saml",
|
||||
"aws-cn", "https://signin.amazonaws.cn/saml",
|
||||
"aws-us-gov", "https://signin.amazonaws-us-gov.com/saml",
|
||||
"aws-iso", "https://signin.c2shome.ic.gov/saml",
|
||||
"aws-iso-b", "https://signin.sc2shome.sgov.gov/saml");
|
||||
private static final String OPEN_TRUST_POLICY = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"sts:AssumeRole\"}]}";
|
||||
|
||||
@BeforeAll
|
||||
@@ -433,7 +442,8 @@ class StsTest {
|
||||
String xml = "<saml:Assertion xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"" + id
|
||||
+ "\" Version=\"2.0\" IssueInstant=\"" + Instant.now() + "\"><saml:Issuer>" + issuer
|
||||
+ "</saml:Issuer><saml:Subject><saml:NameID Format=\"persistent\">sdk-test-subject</saml:NameID>"
|
||||
+ "<saml:SubjectConfirmation Method=\"urn:oasis:names:tc:SAML:2.0:cm:bearer\"><saml:SubjectConfirmationData Recipient=\"https://signin.aws.amazon.com/saml\" NotOnOrAfter=\""
|
||||
+ "<saml:SubjectConfirmation Method=\"urn:oasis:names:tc:SAML:2.0:cm:bearer\">"
|
||||
+ "<saml:SubjectConfirmationData Recipient=\"" + samlSignOnUrl() + "\" NotOnOrAfter=\""
|
||||
+ expiry + "\"/></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore=\""
|
||||
+ Instant.now().minusSeconds(30) + "\" NotOnOrAfter=\"" + expiry
|
||||
+ "\"><saml:AudienceRestriction><saml:Audience>urn:amazon:webservices</saml:Audience></saml:AudienceRestriction></saml:Conditions>"
|
||||
@@ -462,4 +472,8 @@ class StsTest {
|
||||
throw new IllegalStateException("Could not create SAML assertion", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String samlSignOnUrl() {
|
||||
return SAML_SIGN_ON_URLS.getOrDefault(TestFixtures.partition(), SAML_SIGN_ON_URLS.get("aws"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user