79641903

Date: 2025-05-28 09:29:24
Score: 1
Natty:
Report link

You got a 401 running your test because with @WebMvcTest, Spring does not load your security configuration. So, on your test class AuthenticationControllerTest, you should add an @Import with the configuration class that define your securityFilterChain bean. If the securityFilterChain bean is not in context, Spring uses defaults where all endpoints require authentication.

Also annotate your test method with @WithMockUser.

Hope this helps

Reasons:
  • Whitelisted phrase (-1): Hope this helps
  • No code block (0.5):
  • User mentioned (1): @WebMvcTest
  • User mentioned (0): @Import
  • User mentioned (0): @WithMockUser
  • Low reputation (0.5):
Posted by: FBibonne