mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): use ConfigProvider for runtime config lookup in S3VirtualHostFilter (#288)
Replace @ConfigProperty constructor injection with programmatic ConfigProvider.getConfig() lookup to fix native image crash when FLOCI_HOSTNAME is set at runtime. @PreMatching JAX-RS filters run before CDI beans are fully initialized, so neither @ConfigProperty nor @ConfigMapping beans are available during filter construction. Also make bucket extraction hostname-aware: only treat the first label as a bucket name when the remainder matches the configured base hostname (or a well-known AWS S3 domain). This prevents false positives when Floci sits behind a multi-label hostname like floci.svc.cluster.local.
This commit is contained in:
1 parent
17841d2d5a
commit
944fddf5ac
2 files changed
+43
-20
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.NullSource;
|
||||
@@ -9,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
class S3VirtualHostFilterTest {
|
||||
|
||||
// ── Virtual-hosted style: bucket prefix + matching baseHostname ─────────
|
||||
// --- extractBucket with baseHostname ---
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
@@ -33,7 +34,7 @@ class S3VirtualHostFilterTest {
|
||||
assertEquals(expectedBucket, S3VirtualHostFilter.extractBucket(host, baseHostname));
|
||||
}
|
||||
|
||||
// ── Path-style: service hostname alone — must NOT extract a bucket ───────
|
||||
// --- Path-style: service hostname alone — must NOT extract a bucket ---
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
@@ -70,7 +71,14 @@ class S3VirtualHostFilterTest {
|
||||
assertNull(S3VirtualHostFilter.extractBucket(host, "localhost"));
|
||||
}
|
||||
|
||||
// ── Hostname extraction from URL ─────────────────────────────────────────
|
||||
@Test
|
||||
void returnsNullForNullBaseHostname() {
|
||||
// Without a baseHostname, only AWS S3 domains should match
|
||||
assertNull(S3VirtualHostFilter.extractBucket("my-bucket.localhost:4566", null));
|
||||
assertEquals("my-bucket", S3VirtualHostFilter.extractBucket("my-bucket.s3.amazonaws.com", null));
|
||||
}
|
||||
|
||||
// --- Hostname extraction from URL ---
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
@@ -83,4 +91,9 @@ class S3VirtualHostFilterTest {
|
||||
void extractsHostnameFromUrl(String url, String expectedHostname) {
|
||||
assertEquals(expectedHostname, S3VirtualHostFilter.extractHostnameFromUrl(url));
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractHostnameFromUrlReturnsNullForNull() {
|
||||
assertNull(S3VirtualHostFilter.extractHostnameFromUrl(null));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user