मैंने अपने वसंत बूट ऐप के लिए कस्टम लॉगिन फॉर्म बनाया है। मेरे फॉर्म एकीकरण परीक्षण में, मैं यह जांचना चाहता हूं कि प्राप्त कुकीज़ में JSESSIONID और XSRF-TOKEN शामिल हैं।स्प्रिंग एमवीसी परीक्षण (सुरक्षा एकीकरण परीक्षण), JSESSIONID मौजूद नहीं है
लेकिन, मुझे केवल एक्सएसआरएफ-टोकन प्राप्त हुआ।
@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
}
कृपया, मेरी मदद की आवश्यकता परिणाम प्राप्त करने के लिए
यहाँ मेरी परीक्षा है।