mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix: support wildcard filtering in EC2 filters (#837)
* fix: support wildcard filtering in EC2 filters Add wildcard pattern matching support to EC2 filter values to match AWS behavior. Changes: - Added wildcardToRegex() method to convert AWS wildcard patterns (* and ?) to Java regex - Added matchesValue() method for pattern-based value matching - Updated all filter matching logic to use wildcard patterns instead of exact string matching - Supports wildcard filtering for all filter types: tag filters, tag-key, tag-value, and resource-specific filters - Applies to all EC2 resources: VPCs, Subnets, Security Groups, Instances, Internet Gateways, Route Tables, Volumes Added comprehensive integration tests: - describeVpcsWithWildcardTagFilter: Tests asterisk wildcard patterns - describeVpcsWithWildcardQuestionMark: Tests question mark wildcard patterns All 69 EC2 integration tests pass. Backward compatible with exact string matching. Fixes #830 * fix: reorganize imports in Ec2Service and Ec2IntegrationTest for clarity * Potential fix for pull request finding
This commit is contained in:
1 parent
6a8c44fad5
commit
e4666dfa7a
2 files changed
+244
-42
No files matched your search
@@ -1,13 +1,17 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Integration tests for EC2 via the EC2 Query Protocol (form-encoded POST, XML response).
|
||||
@@ -1117,4 +1121,126 @@ class Ec2IntegrationTest {
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("UnsupportedOperation"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Wildcard filtering
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
@Order(300)
|
||||
void describeVpcsWithWildcardTagFilter() {
|
||||
// Create a VPC with a specific tag value
|
||||
String vpcWithWildcard = given()
|
||||
.formParam("Action", "CreateVpc")
|
||||
.formParam("CidrBlock", "10.1.0.0/16")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("CreateVpcResponse.vpc.vpcId");
|
||||
|
||||
// Tag it with BEGINANDEND
|
||||
given()
|
||||
.formParam("Action", "CreateTags")
|
||||
.formParam("ResourceId.1", vpcWithWildcard)
|
||||
.formParam("Tag.1.Key", "Name")
|
||||
.formParam("Tag.1.Value", "BEGINANDEND")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Test exact match still works
|
||||
given()
|
||||
.formParam("Action", "DescribeVpcs")
|
||||
.formParam("Filter.1.Name", "tag:Name")
|
||||
.formParam("Filter.1.Value.1", "BEGINANDEND")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeVpcsResponse.vpcSet.item.vpcId", equalTo(vpcWithWildcard));
|
||||
|
||||
// Test wildcard with asterisk: BEGIN*END should match BEGINANDEND
|
||||
given()
|
||||
.formParam("Action", "DescribeVpcs")
|
||||
.formParam("Filter.1.Name", "tag:Name")
|
||||
.formParam("Filter.1.Value.1", "BEGIN*END")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeVpcsResponse.vpcSet.item.vpcId", equalTo(vpcWithWildcard));
|
||||
|
||||
// Test wildcard with middle asterisk: *AND* should match BEGINANDEND
|
||||
given()
|
||||
.formParam("Action", "DescribeVpcs")
|
||||
.formParam("Filter.1.Name", "tag:Name")
|
||||
.formParam("Filter.1.Value.1", "*AND*")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeVpcsResponse.vpcSet.item.vpcId", equalTo(vpcWithWildcard));
|
||||
|
||||
// Cleanup
|
||||
given()
|
||||
.formParam("Action", "DeleteVpc")
|
||||
.formParam("VpcId", vpcWithWildcard)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(301)
|
||||
void describeVpcsWithWildcardQuestionMark() {
|
||||
// Create a VPC with a specific tag value
|
||||
String vpcId1 = given()
|
||||
.formParam("Action", "CreateVpc")
|
||||
.formParam("CidrBlock", "10.2.0.0/16")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("CreateVpcResponse.vpc.vpcId");
|
||||
|
||||
// Tag it with "test1"
|
||||
given()
|
||||
.formParam("Action", "CreateTags")
|
||||
.formParam("ResourceId.1", vpcId1)
|
||||
.formParam("Tag.1.Key", "Name")
|
||||
.formParam("Tag.1.Value", "test1")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Test wildcard with question mark: test? should match test1
|
||||
given()
|
||||
.formParam("Action", "DescribeVpcs")
|
||||
.formParam("Filter.1.Name", "tag:Name")
|
||||
.formParam("Filter.1.Value.1", "test?")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeVpcsResponse.vpcSet.item.vpcId", equalTo(vpcId1));
|
||||
|
||||
// Cleanup
|
||||
given()
|
||||
.formParam("Action", "DeleteVpc")
|
||||
.formParam("VpcId", vpcId1)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user