Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebTestUtils test runtime hints #12216

Closed
marcusdacoregio opened this issue Nov 16, 2022 · 0 comments
Closed

Add WebTestUtils test runtime hints #12216

marcusdacoregio opened this issue Nov 16, 2022 · 0 comments
Assignees
Labels
in: test An issue in spring-security-test type: enhancement A general enhancement
Milestone

Comments

@marcusdacoregio
Copy link
Contributor

When running ./gradlew security:security-thymeleaf:nativeTest in the AOT smoke tests, the test fails with:

Failures (3):
  JUnit Jupiter:SecurityThymeleafApplicationTests:loginWithInvalidUserThenUnauthenticated()
    MethodSource [className = 'com.example.security.thymeleaf.SecurityThymeleafApplicationTests', methodName = 'loginWithInvalidUserThenUnauthenticated', methodParameterTypes = '']
    => java.lang.IllegalArgumentException: Could not find field 'tokenRepository' on target object [org.springframework.security.web.csrf.CsrfFilter@6c4f796d] or target class [class org.springframework.security.web.csrf.CsrfFilter]
       org.springframework.test.util.ReflectionTestUtils.getField(ReflectionTestUtils.java:275)
       org.springframework.test.util.ReflectionTestUtils.getField(ReflectionTestUtils.java:217)
       org.springframework.security.test.web.support.WebTestUtils.getCsrfTokenRepository(WebTestUtils.java:111)
       org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors$CsrfRequestPostProcessor.postProcessRequest(SecurityMockMvcRequestPostProcessors.java:517)
       org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders$FormLoginRequestBuilder.buildRequest(SecurityMockMvcRequestBuilders.java:187)
       org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:172)
       com.example.security.thymeleaf.SecurityThymeleafApplicationTests.loginWithInvalidUserThenUnauthenticated(SecurityThymeleafApplicationTests.java:36)
       java.base@17.0.5/java.lang.reflect.Method.invoke(Method.java:568)
       org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
       org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
       [...]
  JUnit Jupiter:SecurityThymeleafApplicationTests:loginWithValidUserThenAuthenticated()
    MethodSource [className = 'com.example.security.thymeleaf.SecurityThymeleafApplicationTests', methodName = 'loginWithValidUserThenAuthenticated', methodParameterTypes = '']
    => java.lang.IllegalArgumentException: Could not find field 'tokenRepository' on target object [org.springframework.security.web.csrf.CsrfFilter@6c4f796d] or target class [class org.springframework.security.web.csrf.CsrfFilter]
       org.springframework.test.util.ReflectionTestUtils.getField(ReflectionTestUtils.java:275)
       org.springframework.test.util.ReflectionTestUtils.getField(ReflectionTestUtils.java:217)
       org.springframework.security.test.web.support.WebTestUtils.getCsrfTokenRepository(WebTestUtils.java:111)
       org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors$CsrfRequestPostProcessor.postProcessRequest(SecurityMockMvcRequestPostProcessors.java:517)
       org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders$FormLoginRequestBuilder.buildRequest(SecurityMockMvcRequestBuilders.java:187)
       org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:172)
       com.example.security.thymeleaf.SecurityThymeleafApplicationTests.loginWithValidUserThenAuthenticated(SecurityThymeleafApplicationTests.java:29)
       java.base@17.0.5/java.lang.reflect.Method.invoke(Method.java:568)
       org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
       org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
       [...]

This is because the WebTestUtils uses reflection to get and set some fields, therefore, runtime hints need to be added to support test running in native mode.

@marcusdacoregio marcusdacoregio added in: test An issue in spring-security-test type: enhancement A general enhancement labels Nov 16, 2022
@marcusdacoregio marcusdacoregio added this to the 6.0.0 milestone Nov 16, 2022
@marcusdacoregio marcusdacoregio self-assigned this Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test An issue in spring-security-test type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant