use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.
the class SecurityMockMvcRequestBuildersFormLoginTests method usesAcceptMediaForContentNegotiation.
// gh-3920
@Test
public void usesAcceptMediaForContentNegotiation() throws Exception {
MockHttpServletRequest request = formLogin("/login").user("username", "admin").password("password", "secret").buildRequest(this.servletContext);
assertThat(request.getHeader("Accept")).isEqualTo(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
}
use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.
the class SecurityMockMvcRequestBuildersFormLoginTests method defaults.
@Test
public void defaults() throws Exception {
MockHttpServletRequest request = formLogin().buildRequest(this.servletContext);
CsrfToken token = (CsrfToken) request.getAttribute(CsrfRequestPostProcessor.TestCsrfTokenRepository.TOKEN_ATTR_NAME);
assertThat(request.getParameter("username")).isEqualTo("user");
assertThat(request.getParameter("password")).isEqualTo("password");
assertThat(request.getMethod()).isEqualTo("POST");
assertThat(request.getParameter(token.getParameterName())).isEqualTo(token.getToken());
assertThat(request.getRequestURI()).isEqualTo("/login");
assertThat(request.getParameter("_csrf")).isNotNull();
}
use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.
the class SecurityMockMvcRequestBuildersFormLoginTests method custom.
@Test
public void custom() throws Exception {
MockHttpServletRequest request = formLogin("/login").user("username", "admin").password("password", "secret").buildRequest(this.servletContext);
CsrfToken token = (CsrfToken) request.getAttribute(CsrfRequestPostProcessor.TestCsrfTokenRepository.TOKEN_ATTR_NAME);
assertThat(request.getParameter("username")).isEqualTo("admin");
assertThat(request.getParameter("password")).isEqualTo("secret");
assertThat(request.getMethod()).isEqualTo("POST");
assertThat(request.getParameter(token.getParameterName())).isEqualTo(token.getToken());
assertThat(request.getRequestURI()).isEqualTo("/login");
}
use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.
the class SecurityMockMvcRequestBuildersFormLogoutTests method defaults.
@Test
public void defaults() throws Exception {
MockHttpServletRequest request = logout().buildRequest(servletContext);
CsrfToken token = (CsrfToken) request.getAttribute(CsrfRequestPostProcessor.TestCsrfTokenRepository.TOKEN_ATTR_NAME);
assertThat(request.getMethod()).isEqualTo("POST");
assertThat(request.getParameter(token.getParameterName())).isEqualTo(token.getToken());
assertThat(request.getRequestURI()).isEqualTo("/logout");
}
use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.
the class SecurityMockMvcRequestBuildersFormLogoutTests method custom.
@Test
public void custom() throws Exception {
MockHttpServletRequest request = logout("/admin/logout").buildRequest(servletContext);
CsrfToken token = (CsrfToken) request.getAttribute(CsrfRequestPostProcessor.TestCsrfTokenRepository.TOKEN_ATTR_NAME);
assertThat(request.getMethod()).isEqualTo("POST");
assertThat(request.getParameter(token.getParameterName())).isEqualTo(token.getToken());
assertThat(request.getRequestURI()).isEqualTo("/admin/logout");
}
Aggregations