forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
27 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...ork/common/src/main/java/io/quarkus/test/common/http/TestHTTPConfigSourceInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.quarkus.test.common.http; | ||
|
||
import static io.quarkus.test.common.http.TestHTTPConfigSourceProvider.TEST_MANAGEMENT_URL_KEY; | ||
import static io.quarkus.test.common.http.TestHTTPConfigSourceProvider.TEST_MANAGEMENT_URL_SSL_KEY; | ||
import static io.quarkus.test.common.http.TestHTTPConfigSourceProvider.TEST_URL_KEY; | ||
import static io.quarkus.test.common.http.TestHTTPConfigSourceProvider.TEST_URL_SSL_KEY; | ||
|
||
import jakarta.annotation.Priority; | ||
|
||
import io.smallrye.config.ConfigSourceInterceptorContext; | ||
import io.smallrye.config.ConfigValue; | ||
import io.smallrye.config.ExpressionConfigSourceInterceptor; | ||
import io.smallrye.config.Priorities; | ||
|
||
/** | ||
* Override the expression expansion for test urls so they can be sanitized. A simple interceptor does not work | ||
* because the test urls values are nested expressions, so when the default expression interceptor runs, either we get | ||
* the full value expanded or the value unexpanded. In most cases, the test urls are used as expressions, so we need to | ||
* intercept the expression expansion directly to rewrite what we need. | ||
*/ | ||
@Priority(Priorities.LIBRARY + 299) | ||
public class TestHTTPConfigSourceInterceptor extends ExpressionConfigSourceInterceptor { | ||
@Override | ||
public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { | ||
if (name.equals(TEST_URL_KEY) || | ||
name.equals(TEST_MANAGEMENT_URL_KEY) || | ||
name.equals(TEST_URL_SSL_KEY) || | ||
name.equals(TEST_MANAGEMENT_URL_SSL_KEY)) { | ||
|
||
return sanitizeUrl(super.getValue(context, name)); | ||
} | ||
|
||
return context.proceed(name); | ||
} | ||
|
||
private static ConfigValue sanitizeUrl(ConfigValue configValue) { | ||
if (configValue == null || configValue.getValue() == null) { | ||
return configValue; | ||
} | ||
|
||
String url = configValue.getValue(); | ||
url = url.replace("0.0.0.0", "localhost"); | ||
if (url.endsWith("/")) { | ||
url = url.substring(0, url.length() - 1); | ||
} | ||
|
||
return configValue.from().withValue(url).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...rk/common/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.test.common.http.TestHTTPConfigSourceInterceptor |