2016-04-13 19 views
6

私はスプリングブートアプリケーション用のカスタムログインフォームを作成しました。私のフォームの統合テストで 、私はクッキーがJSESSIONIDXSRF-TOKENが含まれている受信確認したいです。Spring MVCテスト(セキュリティ統合テスト)、JSESSIONIDは存在しません

しかし、私はXSRF-TOKENしか受け取りませんでした。

@RunWith(SpringJUnit4ClassRunner.class) 
@SpringApplicationConfiguration(classes = Application.class) 
@WebAppConfiguration 
@IntegrationTest("server.port:0") 
public class UserIT { 

    @Autowired 
    private WebApplicationContext context; 
    @Autowired 
    private FilterChainProxy springSecurityFilterChain; 

    @Value("${local.server.port}") 
    private Integer port; 

    private MockMvc mockMvc; 

    @Before 
    public void setup() { 
     mockMvc = 
       MockMvcBuilders.webAppContextSetup(context).addFilters(springSecurityFilterChain) 
         .build(); 
    } 

    @Test 
    public void getUserInfoTest() throws Exception { 
     disableSslVerification(); 

     MvcResult result = 
       mockMvc.perform(formLogin("/login").user("roy").password("spring")).andExpect(authenticated()) 
         .andReturn(); 
     Cookie sessionId = result.getResponse().getCookie("JSESSIONID"); 
     Cookie token = result.getResponse().getCookie("XSRF-TOKEN"); 
} 

セキュリティconfに:

@Override 
    public void configure(HttpSecurity http) throws Exception { 
     // @formatter:off 
     http 
      //.httpBasic() 
      //.and() 
       .headers().frameOptions().disable() 
      .and() 
       .antMatcher("/**").authorizeRequests() 
       .antMatchers("/actuator/health").permitAll() 
       .antMatchers("/actuator/**").hasAuthority(Authority.Type.ROLE_ADMIN.getName()) 
       .antMatchers("/login**", "/index.html", "/home.html").permitAll() 
       .anyRequest().authenticated() 
      .and() 
       .formLogin().loginPage("/login.jsp") 
        .usernameParameter("username") 
        .passwordParameter("password") 
        .loginProcessingUrl("/login") 
        .permitAll() 
      .and() 
       .logout().logoutSuccessUrl("/login.jsp").permitAll() 
      .and() 
       .csrf().csrfTokenRepository(csrfTokenRepository()) 
      .and() 
       .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class) 
       .addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class); 
     // @formatter:on 
    } 

は、必要な結果を得るために私を助けてください

は、ここに私のテストです。

答えて

関連する問題