Search in sources :

Example 46 with WithMockUser

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
}
Also used : ReactiveClientRegistrationRepository(org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository) InMemoryReactiveClientRegistrationRepository(org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository) ServerOAuth2AuthorizedClientRepository(org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 47 with WithMockUser

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();
}
Also used : SpringSecurityLdapTemplate(org.springframework.security.ldap.SpringSecurityLdapTemplate) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 48 with WithMockUser

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));
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 49 with WithMockUser

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));
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 50 with WithMockUser

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));
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Aggregations

WithMockUser (org.springframework.security.test.context.support.WithMockUser)3415 Test (org.junit.jupiter.api.Test)2107 Test (org.junit.Test)1226 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)865 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)427 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)409 MvcResult (org.springframework.test.web.servlet.MvcResult)304 ResultActions (org.springframework.test.web.servlet.ResultActions)278 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)275 Transactional (org.springframework.transaction.annotation.Transactional)220 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)179 User (io.github.jhipster.sample.domain.User)149 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)136 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)130 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)130 Course (de.tum.in.www1.artemis.domain.Course)124 ArrayList (java.util.ArrayList)124 Exam (de.tum.in.www1.artemis.domain.exam.Exam)114 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)103 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)102