I write a Spring Boot app and I was able to access and test Controller with MockMvc. The issue is that during testing security is not enforced and I can access Controller with no user.
Am I doing anything wrong? Is it intended behavior?
ControllerTest class:
@RunWith(MockitoJUnitRunner.class)
public class ControllerTest {
private MockMvc mockMvc;
@Mock
private Service service;
@InjectMocks
private Controller controller;
private final static String URL = "/test";
@Before
public void setUp() throws Exception {
mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
}
@Test
public void test() throws Exception {
mockMvc.perform(get(URL))
.andExpect(status().isOk());
}
}