-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36531 from gsmet/3.2.7-backports-1
3.2.7 backports 1
- Loading branch information
Showing
5 changed files
with
218 additions
and
5 deletions.
There are no files selected for viewing
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
109 changes: 109 additions & 0 deletions
109
...test/java/io/quarkus/resteasy/reactive/server/test/simple/GenericsParamConverterTest.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,109 @@ | ||
package io.quarkus.resteasy.reactive.server.test.simple; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.QueryParam; | ||
import jakarta.ws.rs.ext.ParamConverter; | ||
import jakarta.ws.rs.ext.ParamConverterProvider; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class GenericsParamConverterTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(TestEnum.class, Wrapper.class, | ||
WrapperParamConverterProvider.class, WrapperParamConverterProvider.WrapperParamConverter.class, | ||
TestResource.class)); | ||
|
||
@Test | ||
public void wrapper() { | ||
given() | ||
.when().get("/test/single?wrapper=ACTIVE") | ||
.then() | ||
.statusCode(200) | ||
.body(is("ACTIVE")); | ||
} | ||
|
||
@Test | ||
public void wrapperList() { | ||
given() | ||
.when().get("/test/list?wrapperList=INACTIVE&wrapperList=ACTIVE") | ||
.then() | ||
.statusCode(200) | ||
.body(is("INACTIVE,ACTIVE")); | ||
} | ||
|
||
@Path("/test") | ||
public static class TestResource { | ||
|
||
@GET | ||
@Path("/list") | ||
public String list(@QueryParam("wrapperList") final List<Wrapper<TestEnum>> wrapperList) { | ||
return wrapperList.stream().map(w -> w.getValue().name()).collect(Collectors.joining(",")); | ||
} | ||
|
||
@GET | ||
@Path("/single") | ||
public String single(@QueryParam("wrapper") final Wrapper<TestEnum> wrapper) { | ||
return wrapper.getValue().toString(); | ||
} | ||
} | ||
|
||
public enum TestEnum { | ||
ACTIVE, | ||
INACTIVE | ||
} | ||
|
||
public static class Wrapper<E extends Enum<E>> { | ||
private final E value; | ||
|
||
public Wrapper(final E value) { | ||
this.value = value; | ||
} | ||
|
||
public E getValue() { | ||
return value; | ||
} | ||
} | ||
|
||
@Provider | ||
public static class WrapperParamConverterProvider implements ParamConverterProvider { | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, | ||
final Annotation[] annotations) { | ||
if (Wrapper.class.isAssignableFrom(rawType)) { | ||
return (ParamConverter<T>) new WrapperParamConverter(); | ||
} | ||
return null; | ||
} | ||
|
||
public static class WrapperParamConverter implements ParamConverter<Wrapper<?>> { | ||
|
||
@Override | ||
public Wrapper<?> fromString(String value) { | ||
return new Wrapper<>(Enum.valueOf(TestEnum.class, value)); | ||
} | ||
|
||
@Override | ||
public String toString(Wrapper<?> wrapper) { | ||
return wrapper != null ? wrapper.getValue().toString() : null; | ||
} | ||
} | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...ttp/deployment/src/test/java/io/quarkus/vertx/http/http2/Http2RSTFloodProtectionTest.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,104 @@ | ||
package io.quarkus.vertx.http.http2; | ||
|
||
import static io.vertx.core.http.HttpMethod.GET; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Assumptions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.vertx.core.runtime.VertxCoreRecorder; | ||
import io.vertx.core.http.HttpClient; | ||
import io.vertx.core.http.HttpClientOptions; | ||
import io.vertx.core.http.HttpClientRequest; | ||
import io.vertx.core.http.HttpVersion; | ||
import io.vertx.core.net.JdkSSLEngineOptions; | ||
import io.vertx.ext.web.Router; | ||
|
||
/** | ||
* Reproduce CVE-2023-44487. | ||
*/ | ||
public class Http2RSTFloodProtectionTest { | ||
|
||
@TestHTTPResource(value = "/ping", ssl = true) | ||
URL sslUrl; | ||
|
||
@TestHTTPResource(value = "/ping") | ||
URL url; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(MyBean.class) | ||
.addAsResource(new File("src/test/resources/conf/ssl-jks.conf"), "application.properties") | ||
.addAsResource(new File("src/test/resources/conf/server-keystore.jks"), "server-keystore.jks")); | ||
|
||
@Test | ||
void testRstFloodProtectionWithTlsEnabled() throws Exception { | ||
Assumptions.assumeTrue(JdkSSLEngineOptions.isAlpnAvailable()); //don't run on JDK8 | ||
HttpClientOptions options = new HttpClientOptions() | ||
.setUseAlpn(true) | ||
.setProtocolVersion(HttpVersion.HTTP_2) | ||
.setSsl(true) | ||
.setTrustAll(true); | ||
|
||
var client = VertxCoreRecorder.getVertx().get().createHttpClient(options); | ||
int port = sslUrl.getPort(); | ||
run(client, port, false); | ||
} | ||
|
||
@Test | ||
public void testRstFloodProtection() throws InterruptedException { | ||
HttpClientOptions options = new HttpClientOptions() | ||
.setProtocolVersion(HttpVersion.HTTP_2) | ||
.setHttp2ClearTextUpgrade(true); | ||
var client = VertxCoreRecorder.getVertx().get().createHttpClient(options); | ||
run(client, url.getPort(), true); | ||
} | ||
|
||
void run(HttpClient client, int port, boolean plain) throws InterruptedException { | ||
CountDownLatch latch = new CountDownLatch(1); | ||
client.connectionHandler(conn -> conn.goAwayHandler(ga -> { | ||
Assertions.assertEquals(11, ga.getErrorCode()); | ||
latch.countDown(); | ||
})); | ||
|
||
if (plain) { | ||
// Emit a first request to establish a connection. | ||
// It's HTTP/1 so, does not count in the number of requests. | ||
client.request(GET, port, "localhost", "/ping") | ||
.compose(HttpClientRequest::send); | ||
} | ||
|
||
for (int i = 0; i < 250; i++) { // must be higher thant the NEtty limit (200 / 30s) | ||
client.request(GET, port, "localhost", "/ping") | ||
.onSuccess(req -> req.end().onComplete(v -> req.reset())); | ||
} | ||
|
||
if (!latch.await(10, TimeUnit.SECONDS)) { | ||
fail("RST flood protection failed"); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class MyBean { | ||
|
||
public void register(@Observes Router router) { | ||
router.get("/ping").handler(rc -> { | ||
// Do nothing. | ||
}); | ||
} | ||
|
||
} | ||
} |
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