Search in sources :

Example 36 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.

the class SecurityMockMvcRequestPostProcessorsCertificateTests method x509ResourceName.

@Test
public void x509ResourceName() throws Exception {
    MockHttpServletRequest postProcessedRequest = x509("rod.cer").postProcessRequest(request);
    X509Certificate[] certificates = (X509Certificate[]) postProcessedRequest.getAttribute("javax.servlet.request.X509Certificate");
    assertThat(certificates.length).isEqualTo(1);
    assertThat(certificates[0].getSubjectDN().getName()).isEqualTo("CN=rod, OU=Spring Security, O=Spring Framework");
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 37 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.

the class SecurityMockMvcRequestPostProcessorsCsrfDebugFilterTests method findCookieCsrfTokenRepository.

// SEC-3836
@Test
public void findCookieCsrfTokenRepository() throws Exception {
    MockHttpServletRequest request = post("/").buildRequest(wac.getServletContext());
    CsrfTokenRepository csrfTokenRepository = WebTestUtils.getCsrfTokenRepository(request);
    assertThat(csrfTokenRepository).isNotNull();
    assertThat(csrfTokenRepository).isEqualTo(Config.cookieCsrfTokenRepository);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) CookieCsrfTokenRepository(org.springframework.security.web.csrf.CookieCsrfTokenRepository) CsrfTokenRepository(org.springframework.security.web.csrf.CsrfTokenRepository) Test(org.junit.Test)

Example 38 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.

the class SecurityMockMvcRequestPostProcessorsDigestTests method digestWithFilterCustomUsername.

@Test
public void digestWithFilterCustomUsername() throws Exception {
    String username = "admin";
    MockHttpServletRequest postProcessedRequest = digest(username).postProcessRequest(request);
    assertThat(extractUser()).isEqualTo(username);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 39 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.

the class SecurityMockMvcRequestPostProcessorsDigestTests method setup.

@Before
public void setup() {
    this.password = "password";
    request = new MockHttpServletRequest();
    entryPoint = new DigestAuthenticationEntryPoint();
    entryPoint.setKey("key");
    entryPoint.setRealmName("Spring Security");
    filter = new DigestAuthenticationFilter();
    filter.setUserDetailsService(new UserDetailsService() {

        public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
            return new User(username, password, AuthorityUtils.createAuthorityList("ROLE_USER"));
        }
    });
    filter.setAuthenticationEntryPoint(entryPoint);
    filter.afterPropertiesSet();
}
Also used : DigestAuthenticationEntryPoint(org.springframework.security.web.authentication.www.DigestAuthenticationEntryPoint) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserDetails(org.springframework.security.core.userdetails.UserDetails) User(org.springframework.security.core.userdetails.User) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DigestAuthenticationFilter(org.springframework.security.web.authentication.www.DigestAuthenticationFilter) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Before(org.junit.Before)

Example 40 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.

the class AbstractAuthorizeTagTests method setup.

@Before
public void setup() {
    tag = new AuthzTag();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    servletContext = new MockServletContext();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Before(org.junit.Before)

Aggregations

MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1136 Test (org.junit.Test)882 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)605 Before (org.junit.Before)107 MockFilterChain (org.springframework.mock.web.MockFilterChain)93 MockServletContext (org.springframework.mock.web.MockServletContext)82 FilterChain (javax.servlet.FilterChain)79 Authentication (org.springframework.security.core.Authentication)70 HttpServletRequest (javax.servlet.http.HttpServletRequest)62 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)60 MockRequestContext (org.springframework.webflow.test.MockRequestContext)53 MockHttpSession (org.springframework.mock.web.MockHttpSession)51 HttpServletResponse (javax.servlet.http.HttpServletResponse)48 Cookie (javax.servlet.http.Cookie)46 HashMap (java.util.HashMap)39 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)33 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 ModelAndView (org.springframework.web.servlet.ModelAndView)32 RegisteredService (org.apereo.cas.services.RegisteredService)30 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)30