I'm using Spring boot and have Spring Security setup to use token authorization. I have my test is setup like so:
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {
})
@AutoConfigureMockMvc()
@EnableAutoConfiguration(exclude = {
})
public class ApplicationTests {
@Test
public void shouldReturnRepositoryIndex() throws Exception {
mockMvc.perform(get("/")).andDo(print()).andExpect(status().isOk()).andExpect(
jsonPath("$._links.people").exists());
}
}
I need get("/")
to send a header "X-AUTH: SOMETOKEN"
How do I do that?
.header("X-AUTH" , "SOMETOKEN")
should work.
Here is the modified mockMvc code:
mockMvc.perform(get("/").header("X-AUTH" , "SOMETOKEN")).andDo(print()).andExpect(status().isOk()).andExpect(
jsonPath("$._links.people").exists());
The output is:
MockHttpServletRequest:
HTTP Method = GET
Request URI = /
Parameters = {}
Headers = {X-AUTH=[SOMETOKEN]}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments