Spring MVC测试(安全集成测试),JSESSIONID不存在

Spring MVC测试(安全集成测试),JSESSIONID不存在,第1张

概述我为我的春季启动应用程序创建了自定义登录表单.在我的表单集成测试中,我想检查收到的cookie是否包含JSESSIONID和XSRF-TOKEN.但是,我只收到了XSRF-TOKEN.这是我的测试:@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes =

我为我的春季启动应用程序创建了自定义登录表单.
在我的表单集成测试中,我想检查收到的cookie是否包含JsESSIONID和XSRF-TOKEN.

但是,我只收到了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");}

安全配置:

@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    }

请帮助我获得所需的结果.最佳答案您也没有看到Set-cookie标头.对我而言,这是mockmvc的一个很大的局限.有关解决方法,请参阅Why does Spring MockMvc result not contain a cookie?. 总结

以上是内存溢出为你收集整理的Spring MVC测试(安全集成测试),JSESSIONID不存在全部内容,希望文章能够帮你解决Spring MVC测试(安全集成测试),JSESSIONID不存在所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1256124.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存