Closed
Description
I created a Resource server example project using Spring WebMvc RouterFunction and Auth0 IDP.
https://github.com/hantsy/spring-webmvc-auth0-sample
When adding tests, I followed the Spring Security Samples.
I tried to use @MockMvc
to test the functionality but failed. The @MockMvc
can not recognize RouterFunction
bean and the new Spring Security Servlet SecurityFilterChain
.
- https://github.com/hantsy/spring-webmvc-auth0-sample/blob/master/src/main/java/com/example/demo/config/WebConfig.java#L17
- https://github.com/hantsy/spring-webmvc-auth0-sample/blob/master/src/main/java/com/example/demo/config/SecurityConfig.java#L31
Then I created a MockMvc
from WebApplicationContext
, check https://github.com/hantsy/spring-webmvc-auth0-sample/blob/master/src/test/java/com/example/demo/ApplicationTests.java, but failed due to an exception.
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.test.web.servlet.DefaultMvcResult.setHandler(Object)" because "mvcResult" is null
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
Also posted on stackoverflow, https://stackoverflow.com/questions/67171628/resource-server-test-failes-with-auth0-issuer-uri