use of org.springframework.security.test.context.support.WithMockUser in project spring-security by spring-projects.
the class OAuth2ClientSpecTests method registeredOAuth2AuthorizedClientWhenAuthenticatedThenRedirects.
@Test
@WithMockUser
public void registeredOAuth2AuthorizedClientWhenAuthenticatedThenRedirects() {
this.spring.register(Config.class, AuthorizedClientController.class).autowire();
ReactiveClientRegistrationRepository repository = this.spring.getContext().getBean(ReactiveClientRegistrationRepository.class);
ServerOAuth2AuthorizedClientRepository authorizedClientRepository = this.spring.getContext().getBean(ServerOAuth2AuthorizedClientRepository.class);
given(repository.findByRegistrationId(any())).willReturn(Mono.just(TestClientRegistrations.clientRegistration().build()));
given(authorizedClientRepository.loadAuthorizedClient(any(), any(), any())).willReturn(Mono.empty());
// @formatter:off
this.client.get().uri("/").exchange().expectStatus().is3xxRedirection();
// @formatter:on
}
use of org.springframework.security.test.context.support.WithMockUser in project spring-security by spring-projects.
the class LdapUserDetailsManagerModifyPasswordTests method changePasswordWhenOldPasswordIsCorrectThenPasses.
@Test
@WithMockUser(username = "bob", password = "bobspassword", authorities = "ROLE_USER")
public void changePasswordWhenOldPasswordIsCorrectThenPasses() {
SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(this.contextSource);
this.userDetailsManager.changePassword("bobspassword", "bobsshinynewandformidablylongandnearlyimpossibletorememberthoughdemonstrablyhardtocrackduetoitshighlevelofentropypasswordofjustice");
assertThat(template.compare("uid=bob,ou=people", "userPassword", "bobsshinynewandformidablylongandnearlyimpossibletorememberthoughdemonstrablyhardtocrackduetoitshighlevelofentropypasswordofjustice")).isTrue();
}
use of org.springframework.security.test.context.support.WithMockUser in project spring-security by spring-projects.
the class LogoutConfigurerClearSiteDataTests method logoutWhenRequestTypePostAndSecureThenHeaderIsPresent.
@Test
@WithMockUser
public void logoutWhenRequestTypePostAndSecureThenHeaderIsPresent() throws Exception {
this.spring.register(HttpLogoutConfig.class).autowire();
MockHttpServletRequestBuilder logoutRequest = post("/logout").secure(true).with(csrf());
this.mvc.perform(logoutRequest).andExpect(header().stringValues(CLEAR_SITE_DATA_HEADER, HEADER_VALUE));
}
use of org.springframework.security.test.context.support.WithMockUser in project spring-security by spring-projects.
the class LogoutConfigurerClearSiteDataTests method logoutWhenRequestTypePostAndNotSecureThenHeaderNotPresent.
@Test
@WithMockUser
public void logoutWhenRequestTypePostAndNotSecureThenHeaderNotPresent() throws Exception {
this.spring.register(HttpLogoutConfig.class).autowire();
MockHttpServletRequestBuilder logoutRequest = post("/logout").with(csrf());
this.mvc.perform(logoutRequest).andExpect(header().doesNotExist(CLEAR_SITE_DATA_HEADER));
}
use of org.springframework.security.test.context.support.WithMockUser in project spring-security by spring-projects.
the class LogoutConfigurerClearSiteDataTests method logoutWhenRequestTypeGetThenHeaderNotPresentt.
@Test
@WithMockUser
public void logoutWhenRequestTypeGetThenHeaderNotPresentt() throws Exception {
this.spring.register(HttpLogoutConfig.class).autowire();
MockHttpServletRequestBuilder logoutRequest = get("/logout").secure(true).with(csrf());
this.mvc.perform(logoutRequest).andExpect(header().doesNotExist(CLEAR_SITE_DATA_HEADER));
}
Aggregations