Search in sources :

Example 1 with AccessToken

use of io.pivotal.cla.data.AccessToken in project pivotal-cla by pivotalsoftware.

the class CclaControllerTests method signWithRepositoryIdWithPullRequestId.

@Test
public void signWithRepositoryIdWithPullRequestId() throws Exception {
    String repositoryId = "rwinch/176_test";
    when(mockClaRepository.findByNameAndPrimaryTrue(cla.getName())).thenReturn(cla);
    when(mockClaRepository.findOne(cla.getId())).thenReturn(cla);
    when(mockGitHub.getOrganizations(anyString())).thenReturn(Arrays.asList("spring", "pivotal"));
    when(mockGitHub.getShaForPullRequest(any(PullRequestStatus.class))).thenReturn("abc123");
    when(mockCorporateSignatureRepository.findSignature(anyString(), anyCollectionOf(String.class), anyCollectionOf(String.class))).thenReturn(null, corporateSignature);
    when(mockTokenRepo.findOne(repositoryId)).thenReturn(new AccessToken(repositoryId, "access-token-123"));
    int pullRequestId = 2;
    SignCclaPage signPage = SignCclaPage.go(getDriver(), cla.getName(), repositoryId, pullRequestId);
    signPage = signPage.form().name("Rob Winch").email("rob@gmail.com").mailingAddress("123 Seasame St").country("USA").telephone("123.456.7890").companyName("Pivotal").gitHubOrganization("pivotal").title("Director").confirm().sign(SignCclaPage.class);
    signPage.assertAt();
    signPage.assertPullRequestLink(repositoryId, pullRequestId);
    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(WithSigningUserFactory.create().getGitHubLogin());
    assertThat(updatePr.getPullRequestId()).isEqualTo(pullRequestId);
    assertThat(updatePr.getRepoId()).isEqualTo(repositoryId);
}
Also used : AccessToken(io.pivotal.cla.data.AccessToken) SignCclaPage(io.pivotal.cla.webdriver.pages.SignCclaPage) Matchers.anyString(org.mockito.Matchers.anyString) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) Test(org.junit.Test)

Example 2 with AccessToken

use of io.pivotal.cla.data.AccessToken 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 3 with AccessToken

use of io.pivotal.cla.data.AccessToken in project pivotal-cla by pivotalsoftware.

the class AdminLinkClaTests method linkClaRepositories.

@Test
@SuppressWarnings("unchecked")
public void linkClaRepositories() throws Exception {
    AccessToken token = new AccessToken(AccessToken.CLA_ACCESS_TOKEN_ID, "linkClaValidationRepositories_access_token_abc123");
    when(mockTokenRepo.findOne(AccessToken.CLA_ACCESS_TOKEN_ID)).thenReturn(token);
    when(mockGitHub.getContributingUrls(anyList())).thenReturn(new ContributingUrlsResponse());
    User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    AdminLinkClaPage link = AdminLinkClaPage.to(getDriver());
    link = link.link("test/this", cla.getName(), AdminLinkClaPage.class);
    link.assertRepositories().hasNoErrors();
    link.assertClaName().hasNoErrors();
    ArgumentCaptor<CreatePullRequestHookRequest> requestCaptor = ArgumentCaptor.forClass(CreatePullRequestHookRequest.class);
    verify(mockGitHub).createPullRequestHooks(requestCaptor.capture());
    CreatePullRequestHookRequest request = requestCaptor.getValue();
    assertThat(request.getAccessToken()).isEqualTo(user.getAccessToken());
    assertThat(request.getRepositoryIds()).containsOnly("test/this");
    assertThat(request.getGitHubEventUrl()).isEqualTo("http://localhost/github/hooks/pull_request/" + cla.getName());
    assertThat(request.getSecret()).isEqualTo(token.getToken());
    assertThat(driver.getPageSource()).doesNotContain(token.getToken());
    ArgumentCaptor<AccessToken> tokenCaptor = ArgumentCaptor.forClass(AccessToken.class);
    verify(mockTokenRepo).save(tokenCaptor.capture());
    AccessToken savedToken = tokenCaptor.getValue();
    assertThat(savedToken.getId()).isEqualTo("test/this");
    assertThat(savedToken.getToken()).isEqualTo(user.getAccessToken());
    PullRequestStatus expectedStatus = new PullRequestStatus();
    expectedStatus.setAccessToken("access-token-123");
    expectedStatus.setGitHubUsername("username");
    expectedStatus.setPullRequestId(1);
    expectedStatus.setRepoId("repo");
    expectedStatus.setSha("12345678");
    expectedStatus.setUrl("https://cla.pivotal.io/sign/pivotal");
    when(mockGitHub.createUpdatePullRequestStatuses(any())).thenReturn(Arrays.asList(expectedStatus));
    link = link.migrate();
    ArgumentCaptor<PullRequestStatus> statusCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
    verify(mockGitHub).save(statusCaptor.capture());
    PullRequestStatus status = statusCaptor.getValue();
    assertThat(status.getAccessToken()).isEqualTo(expectedStatus.getAccessToken());
    assertThat(status.getGitHubUsername()).isEqualTo(expectedStatus.getGitHubUsername());
    assertThat(status.getPullRequestId()).isEqualTo(expectedStatus.getPullRequestId());
    assertThat(status.getRepoId()).isEqualTo(expectedStatus.getRepoId());
    assertThat(status.getSha()).isEqualTo(expectedStatus.getSha());
    assertThat(status.getSuccess()).isFalse();
    assertThat(status.getUrl()).isEqualTo(expectedStatus.getUrl());
}
Also used : WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) WithAdminUser(io.pivotal.cla.security.WithAdminUser) CreatePullRequestHookRequest(io.pivotal.cla.service.github.CreatePullRequestHookRequest) AccessToken(io.pivotal.cla.data.AccessToken) ContributingUrlsResponse(io.pivotal.cla.service.github.ContributingUrlsResponse) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) AdminLinkClaPage(io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage) Test(org.junit.Test)

Example 4 with AccessToken

use of io.pivotal.cla.data.AccessToken in project pivotal-cla by pivotalsoftware.

the class GitHubHooksControllerTests method markCommitStatusSuccessIndividualAcceptingIssueComments.

@Test
public void markCommitStatusSuccessIndividualAcceptingIssueComments() throws Exception {
    User user = WithSigningUserFactory.create();
    when(mockUserRepo.findOne(anyString())).thenReturn(user);
    when(mockTokenRepo.findOne("rwinch/176_test")).thenReturn(new AccessToken("rwinch/176_test", "mock_access_token_value"));
    when(mockIndividualSignatureRepository.findSignaturesFor(any(), any(), anyString())).thenReturn(Arrays.asList(individualSignature));
    when(gitHubApiMock.getShaForPullRequest(any(PullRequestId.class))).thenReturn("a6befb598a35c1c206e1bf7bbb3018f4403b9610");
    mockMvc.perform(hookRequest().header("X-GitHub-Event", GithubEvents.ISSUE_COMMENT).content(getPayload("issue_comment.json"))).andExpect(status().isOk());
    ArgumentCaptor<PullRequestStatus> statusCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
    verify(mockGitHub).save(statusCaptor.capture());
    PullRequestStatus status = statusCaptor.getValue();
    assertThat(status.getRepoId()).isEqualTo("rwinch/176_test");
    assertThat(status.getAccessToken()).isEqualTo("mock_access_token_value");
    assertThat(status.getPullRequestId()).isEqualTo(2);
    assertThat(status.getSha()).isEqualTo("a6befb598a35c1c206e1bf7bbb3018f4403b9610");
    assertThat(status.getUrl()).isEqualTo("http://localhost/sign/pivotal?repositoryId=rwinch/176_test&pullRequestId=2");
    assertThat(status.isSuccess()).isTrue();
    assertThat(status.getGitHubUsername()).isEqualTo(user.getGitHubLogin());
}
Also used : User(io.pivotal.cla.data.User) AccessToken(io.pivotal.cla.data.AccessToken) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) PullRequestId(io.pivotal.cla.egit.github.core.PullRequestId) Test(org.junit.Test)

Example 5 with AccessToken

use of io.pivotal.cla.data.AccessToken in project pivotal-cla by pivotalsoftware.

the class GitHubHooksControllerTests method userNeverAuthenticatedNoToken.

@Test
public void userNeverAuthenticatedNoToken() throws Exception {
    accessToken = null;
    when(mockTokenRepo.findOne("rwinch/176_test")).thenReturn(new AccessToken("rwinch/176_test", "mock_access_token_value"));
    mockMvc.perform(hookRequest().header("X-GitHub-Event", GithubEvents.PULL_REQUEST).content(getPayload("pull_request.json"))).andExpect(status().isUnauthorized());
}
Also used : AccessToken(io.pivotal.cla.data.AccessToken) Test(org.junit.Test)

Aggregations

AccessToken (io.pivotal.cla.data.AccessToken)19 Test (org.junit.Test)13 PullRequestStatus (io.pivotal.cla.service.github.PullRequestStatus)10 User (io.pivotal.cla.data.User)9 WithSigningUser (io.pivotal.cla.security.WithSigningUser)2 ContributingUrlsResponse (io.pivotal.cla.service.github.ContributingUrlsResponse)2 CreatePullRequestHookRequest (io.pivotal.cla.service.github.CreatePullRequestHookRequest)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 PullRequestId (io.pivotal.cla.egit.github.core.PullRequestId)1 UrlBuilder (io.pivotal.cla.mvc.util.UrlBuilder)1 WithAdminUser (io.pivotal.cla.security.WithAdminUser)1 SignCclaPage (io.pivotal.cla.webdriver.pages.SignCclaPage)1 SignClaPage (io.pivotal.cla.webdriver.pages.SignClaPage)1 SignIclaPage (io.pivotal.cla.webdriver.pages.SignIclaPage)1 AdminLinkClaPage (io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage)1 SneakyThrows (lombok.SneakyThrows)1 WithAnonymousUser (org.springframework.security.test.context.support.WithAnonymousUser)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1