Testing security policies with Spring Security Test
Has something crossed your mind? Didn’t we check out security stuff when we wrote that HomeControllerTest
class earlier in this chapter?
Yes… and no.
We used the @WithMockUser
annotation from Spring Security Test earlier in this chapter. But that’s because any @WebMvcTest
-annotated test class will, by default, have our Spring Security policies in effect.
But we didn’t cover all the necessary security paths. And in security, there are often many paths to cover. And as we dig, we’ll discover exactly what this means.
For starters, we need a new test class, as shown here:
@WebMvcTest (controllers = HomeController.class) public class SecurityBasedTest { @Autowired MockMvc mvc; @MockBean VideoService videoService; }
Hopefully, things are starting to look familiar:
@WebMvcTest
: This Spring Boot Test annotation indicates this is a web-based test class focused...