Search in sources :

Example 1 with WithAnonymousUser

use of org.springframework.security.test.context.support.WithAnonymousUser in project code-chill by CodeChillAlluna.

the class AuthenticationRestControllerTest method successfulAuthenticationWithAnonymousUser.

@Test
@WithAnonymousUser
public void successfulAuthenticationWithAnonymousUser() throws Exception {
    JwtAuthenticationRequest jwtAuthenticationRequest = new JwtAuthenticationRequest("user", "password");
    this.mvc.perform(post("/auth").contentType(MediaType.APPLICATION_JSON).content(new ObjectMapper().writeValueAsString(jwtAuthenticationRequest))).andExpect(status().is2xxSuccessful());
}
Also used : JwtAuthenticationRequest(fr.codechill.spring.security.JwtAuthenticationRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with WithAnonymousUser

use of org.springframework.security.test.context.support.WithAnonymousUser in project uhgroupings by uhawaii-system-its-ti-iam.

the class HomeControllerTest method loginViaAnonymous.

@Test
@WithAnonymousUser
public void loginViaAnonymous() throws Exception {
    MvcResult mvcResult = mockMvc.perform(get("/login")).andExpect(status().is3xxRedirection()).andExpect(status().is(302)).andExpect(redirectedUrlPattern(casLoginUrl + "**")).andReturn();
    assertNotNull(mvcResult);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with WithAnonymousUser

use of org.springframework.security.test.context.support.WithAnonymousUser in project pivotal-cla by pivotalsoftware.

the class ClaControllerTests method viewSignedWithRepositoryIdAndPullRequestIdNewUser.

@Test
@WithAnonymousUser
public void viewSignedWithRepositoryIdAndPullRequestIdNewUser() throws Exception {
    String repositoryId = "spring-projects/spring-security";
    User signingUser = WithSigningUserFactory.create();
    when(mockGitHub.getCurrentUser(any())).thenReturn(signingUser);
    when(mockGitHub.getShaForPullRequest(any(PullRequestStatus.class))).thenReturn("abc123");
    when(mockIndividualSignatureRepository.findSignaturesFor(any(), eq(signingUser), eq(cla.getName()))).thenReturn(Arrays.asList(individualSignature));
    when(mockIndividualSignatureRepository.findSignaturesFor(any(), eq(signingUser))).thenReturn(Arrays.asList(individualSignature));
    when(mockTokenRepo.findOne(repositoryId)).thenReturn(new AccessToken(repositoryId, "access-token-123"));
    int pullRequestId = 123;
    SignClaPage home = SignClaPage.go(driver, cla.getName(), repositoryId, pullRequestId);
    home.assertAt();
    home.assertClaLinksWithPullRequest(cla.getName(), repositoryId, pullRequestId);
    home.assertPullRequestLink(repositoryId, pullRequestId);
    home.assertImported();
    ArgumentCaptor<PullRequestStatus> updatePullRequestCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
    verify(mockGitHub).save(updatePullRequestCaptor.capture());
    PullRequestStatus updatePr = updatePullRequestCaptor.getValue();
    String commitStatusUrl = "http://localhost/sign/" + cla.getName() + "?repositoryId=" + repositoryId + "&pullRequestId=" + pullRequestId;
    assertThat(updatePr.getUrl()).isEqualTo(commitStatusUrl);
    assertThat(updatePr.getGitHubUsername()).isEqualTo(signingUser.getGitHubLogin());
    assertThat(updatePr.getPullRequestId()).isEqualTo(pullRequestId);
    assertThat(updatePr.getRepoId()).isEqualTo(repositoryId);
}
Also used : SignClaPage(io.pivotal.cla.webdriver.pages.SignClaPage) WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) AccessToken(io.pivotal.cla.data.AccessToken) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) Test(org.junit.Test)

Example 4 with WithAnonymousUser

use of org.springframework.security.test.context.support.WithAnonymousUser in project pivotal-cla by pivotalsoftware.

the class IclaControllerTests method view.

@Test
@WithAnonymousUser
public void view() {
    when(mockClaRepository.findByNameAndPrimaryTrue(cla.getName())).thenReturn(cla);
    ViewIclaPage signPage = ViewIclaPage.go(getDriver(), cla.getName());
    assertThat(signPage.getIndividualCla()).isEqualTo(cla.getIndividualContent().getHtml());
}
Also used : ViewIclaPage(io.pivotal.cla.webdriver.pages.ViewIclaPage) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) Test(org.junit.Test)

Example 5 with WithAnonymousUser

use of org.springframework.security.test.context.support.WithAnonymousUser in project nixmash-blog by mintster.

the class AdminControllerTests method anonymousCannotAccessAdmin.

@Test
@WithAnonymousUser
public void anonymousCannotAccessAdmin() throws Exception {
    // Whereas Erwin is forbidden, anonymous users redirected to login page
    RequestBuilder request = get("/admin").with(csrf());
    mvc.perform(request).andExpect(status().is3xxRedirection()).andExpect(loginPage());
}
Also used : RequestBuilder(org.springframework.test.web.servlet.RequestBuilder) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 WithAnonymousUser (org.springframework.security.test.context.support.WithAnonymousUser)12 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 MvcResult (org.springframework.test.web.servlet.MvcResult)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 UserToken (com.nixmash.blog.jpa.model.UserToken)1 JwtAuthenticationRequest (fr.codechill.spring.security.JwtAuthenticationRequest)1 AccessToken (io.pivotal.cla.data.AccessToken)1 User (io.pivotal.cla.data.User)1 WithSigningUser (io.pivotal.cla.security.WithSigningUser)1 PullRequestStatus (io.pivotal.cla.service.github.PullRequestStatus)1 SignClaPage (io.pivotal.cla.webdriver.pages.SignClaPage)1 ViewCclaPage (io.pivotal.cla.webdriver.pages.ViewCclaPage)1 ViewIclaPage (io.pivotal.cla.webdriver.pages.ViewIclaPage)1 ResultActions (org.springframework.test.web.servlet.ResultActions)1