Search in sources :

Example 6 with User

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

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

the class GitHubHooksControllerTests method skipOwnRequests.

@Test
public void skipOwnRequests() 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(gitHubApiMock.getGitHubClaUserLogin()).thenReturn("robwinch");
    when(mockIndividualSignatureRepository.findSignaturesFor(any(), any(), anyString())).thenReturn(Arrays.asList(individualSignature));
    mockMvc.perform(hookRequest().header("X-GitHub-Event", GithubEvents.PULL_REQUEST_REVIEW_COMMENT).content(getPayload("pull_request_review_comment.json"))).andExpect(status().isOk());
    verify(gitHubApiMock).getGitHubClaUserLogin();
    verifyNoMoreInteractions(gitHubApiMock);
}
Also used : User(io.pivotal.cla.data.User) AccessToken(io.pivotal.cla.data.AccessToken) Test(org.junit.Test)

Example 8 with User

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

the class GitHubHooksControllerTests method markCommitStatusSuccessCorporate.

@Test
@SuppressWarnings("unchecked")
public void markCommitStatusSuccessCorporate() 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(mockGitHub.getOrganizations(anyString())).thenReturn(Arrays.asList("organization"));
    when(mockCorporateSignatureRepository.findSignature(anyString(), anySet(), anyCollectionOf(String.class))).thenReturn(corporateSignature);
    mockMvc.perform(hookRequest().header("X-GitHub-Event", GithubEvents.PULL_REQUEST).content(getPayload("pull_request.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) Matchers.anyString(org.mockito.Matchers.anyString) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) Test(org.junit.Test)

Example 9 with User

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

the class WithClaAuthorUserFactory method create.

public static User create() {
    User user = WithAdminUserFactory.create();
    user.setClaAuthor(true);
    return user;
}
Also used : User(io.pivotal.cla.data.User)

Example 10 with User

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

the class WithSigningUserFactory method createSecurityContext.

@Override
public SecurityContext createSecurityContext(WithSigningUser user) {
    User principal = create();
    principal.setAdminAccessRequested(user.requestedAdmin());
    UserAuthentication auth = new UserAuthentication(principal);
    SecurityContext context = SecurityContextHolder.createEmptyContext();
    context.setAuthentication(auth);
    return context;
}
Also used : User(io.pivotal.cla.data.User) SecurityContext(org.springframework.security.core.context.SecurityContext) UserAuthentication(io.pivotal.cla.security.Login.UserAuthentication)

Aggregations

User (io.pivotal.cla.data.User)31 Test (org.junit.Test)22 WithSigningUser (io.pivotal.cla.security.WithSigningUser)11 AccessToken (io.pivotal.cla.data.AccessToken)9 CurrentUserRequest (io.pivotal.cla.service.github.CurrentUserRequest)8 PullRequestStatus (io.pivotal.cla.service.github.PullRequestStatus)6 SignClaPage (io.pivotal.cla.webdriver.pages.SignClaPage)4 AdminLinkClaPage (io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage)4 EnqueueRequests (okhttp3.mockwebserver.EnqueueRequests)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 UserAuthentication (io.pivotal.cla.security.Login.UserAuthentication)3 OAuthAccessTokenParams (io.pivotal.cla.service.github.OAuthAccessTokenParams)3 Matchers.anyString (org.mockito.Matchers.anyString)3 SecurityContext (org.springframework.security.core.context.SecurityContext)3 WithAnonymousUser (org.springframework.security.test.context.support.WithAnonymousUser)3 IndividualSignature (io.pivotal.cla.data.IndividualSignature)1 PullRequestId (io.pivotal.cla.egit.github.core.PullRequestId)1 WithAdminUser (io.pivotal.cla.security.WithAdminUser)1 ContributingUrlsResponse (io.pivotal.cla.service.github.ContributingUrlsResponse)1 CreatePullRequestHookRequest (io.pivotal.cla.service.github.CreatePullRequestHookRequest)1