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.
Merge pull request quarkusio#5316 from jaikiran/qk-5293
Fix NPE when processing a @WebServlet which has additional annotations other than @ServletSecurity
- Loading branch information
Showing
3 changed files
with
66 additions
and
2 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
29 changes: 29 additions & 0 deletions
29
extensions/undertow/deployment/src/test/java/io/quarkus/undertow/test/AnnotatedServlet.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,29 @@ | ||
package io.quarkus.undertow.test; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.annotation.security.RunAs; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* | ||
*/ | ||
@WebServlet(urlPatterns = AnnotatedServlet.SERVLET_ENDPOINT) | ||
// we aren't really interested in testing the RunAs feature, instead this is there to reproduce | ||
// a NPE https://github.com/quarkusio/quarkus/issues/5293 | ||
@RunAs("dummy") | ||
public class AnnotatedServlet extends HttpServlet { | ||
|
||
public static final String SERVLET_ENDPOINT = "/plainAnnotatedServlet"; | ||
|
||
public static final String OK_RESPONSE = "Success"; | ||
|
||
@Override | ||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { | ||
resp.getWriter().write(OK_RESPONSE); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../undertow/deployment/src/test/java/io/quarkus/undertow/test/AnnotatedServletTestCase.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,35 @@ | ||
package io.quarkus.undertow.test; | ||
|
||
import static io.restassured.RestAssured.when; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* | ||
*/ | ||
public class AnnotatedServletTestCase { | ||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(AnnotatedServlet.class)); | ||
|
||
/** | ||
* Tests the issue noted in https://github.com/quarkusio/quarkus/issues/5293 | ||
* where {@code UndertowBuildStep} would throw an NPE when the annotated servlet | ||
* had additional annotation(s) but not the {@code @ServletSecurity} annotation | ||
* | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void testNPE() throws Exception { | ||
when().get(AnnotatedServlet.SERVLET_ENDPOINT).then() | ||
.statusCode(200) | ||
.body(is(AnnotatedServlet.OK_RESPONSE)); | ||
} | ||
} |