Search in sources :

Example 21 with User

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

the class MylynGitHubApiITests method getCurrentUserAdminAndClaAuthor.

@Test
@EnqueueRequests({ "getAccessToken", "getEmailsPivotal", "getUserRwinch", "getTeamMembers" })
public void getCurrentUserAdminAndClaAuthor() throws Exception {
    OAuthAccessTokenParams oauthParams = new OAuthAccessTokenParams();
    oauthParams.setCallbackUrl("https://example.com/oauth/callback");
    oauthParams.setCode("code-123");
    oauthParams.setState("state-456");
    CurrentUserRequest userRequest = new CurrentUserRequest();
    userRequest.setOauthParams(oauthParams);
    userRequest.setRequestAdminAccess(true);
    User user = service.getCurrentUser(userRequest);
    assertThat(user.getAccessToken()).isEqualTo("access-token-123");
    assertThat(user.getAvatarUrl()).isEqualTo("https://avatars.githubusercontent.com/u/362503?v=3");
    assertThat(user.getEmails()).containsOnly("rob@example.com", "rob@pivotal.io");
    assertThat(user.getGitHubLogin()).isEqualTo("rwinch");
    assertThat(user.getName()).isEqualTo("Rob Winch");
    assertThat(user.isAdminAccessRequested()).isTrue();
    assertThat(user.isAdmin()).isTrue();
    assertThat(user.isClaAuthor()).isTrue();
    RecordedRequest request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/login/oauth/access_token");
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"code\":\"code-123\",\"client_secret\":\"client-secret\",\"state\":\"state-456\",\"client_id\":\"client-id\",\"redirect_url\":\"https://example.com/oauth/callback\"}");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user/emails?per_page=100&page=1");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) User(io.pivotal.cla.data.User) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 22 with User

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

the class MylynGitHubApiITests method getCurrentUserAdminAndNotClaAuthor.

@Test
@EnqueueRequests({ "getAccessToken", "getEmailsPivotal", "getUserRwinch", "getTeamMembersNotFound" })
public void getCurrentUserAdminAndNotClaAuthor() throws Exception {
    OAuthAccessTokenParams oauthParams = new OAuthAccessTokenParams();
    oauthParams.setCallbackUrl("https://example.com/oauth/callback");
    oauthParams.setCode("code-123");
    oauthParams.setState("state-456");
    CurrentUserRequest userRequest = new CurrentUserRequest();
    userRequest.setOauthParams(oauthParams);
    userRequest.setRequestAdminAccess(true);
    User user = service.getCurrentUser(userRequest);
    assertThat(user.getAccessToken()).isEqualTo("access-token-123");
    assertThat(user.getAvatarUrl()).isEqualTo("https://avatars.githubusercontent.com/u/362503?v=3");
    assertThat(user.getEmails()).containsOnly("rob@example.com", "rob@pivotal.io");
    assertThat(user.getGitHubLogin()).isEqualTo("rwinch");
    assertThat(user.getName()).isEqualTo("Rob Winch");
    assertThat(user.isAdminAccessRequested()).isTrue();
    assertThat(user.isAdmin()).isTrue();
    assertThat(user.isClaAuthor()).isFalse();
    RecordedRequest request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/login/oauth/access_token");
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"code\":\"code-123\",\"client_secret\":\"client-secret\",\"state\":\"state-456\",\"client_id\":\"client-id\",\"redirect_url\":\"https://example.com/oauth/callback\"}");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user/emails?per_page=100&page=1");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) User(io.pivotal.cla.data.User) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 23 with User

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

the class MylynGitHubApiITests method getCurrentUserSigning.

@Test
@EnqueueRequests({ "getAccessToken", "getEmailsNotPivotal", "getUserRwinch" })
public void getCurrentUserSigning() throws Exception {
    OAuthAccessTokenParams oauthParams = new OAuthAccessTokenParams();
    oauthParams.setCallbackUrl("https://example.com/oauth/callback");
    oauthParams.setCode("code-123");
    oauthParams.setState("state-456");
    CurrentUserRequest userRequest = new CurrentUserRequest();
    userRequest.setOauthParams(oauthParams);
    userRequest.setRequestAdminAccess(false);
    User user = service.getCurrentUser(userRequest);
    assertThat(user.getAccessToken()).isEqualTo("access-token-123");
    assertThat(user.getAvatarUrl()).isEqualTo("https://avatars.githubusercontent.com/u/362503?v=3");
    assertThat(user.getEmails()).containsOnly("rob@example.com");
    assertThat(user.getGitHubLogin()).isEqualTo("rwinch");
    assertThat(user.getName()).isEqualTo("Rob Winch");
    assertThat(user.isAdminAccessRequested()).isFalse();
    assertThat(user.isAdmin()).isFalse();
    RecordedRequest request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/login/oauth/access_token");
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"code\":\"code-123\",\"client_secret\":\"client-secret\",\"state\":\"state-456\",\"client_id\":\"client-id\",\"redirect_url\":\"https://example.com/oauth/callback\"}");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user/emails?per_page=100&page=1");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) User(io.pivotal.cla.data.User) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 24 with User

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

the class MylynGitHubApiITests method getCurrentUserAdminRequestedButNotAdmin.

@Test
@EnqueueRequests({ "getAccessToken", "getEmailsNotPivotal", "getUserRwinch" })
public void getCurrentUserAdminRequestedButNotAdmin() throws Exception {
    OAuthAccessTokenParams oauthParams = new OAuthAccessTokenParams();
    oauthParams.setCallbackUrl("https://example.com/oauth/callback");
    oauthParams.setCode("code-123");
    oauthParams.setState("state-456");
    CurrentUserRequest userRequest = new CurrentUserRequest();
    userRequest.setOauthParams(oauthParams);
    userRequest.setRequestAdminAccess(true);
    User user = service.getCurrentUser(userRequest);
    assertThat(user.getAccessToken()).isEqualTo("access-token-123");
    assertThat(user.getAvatarUrl()).isEqualTo("https://avatars.githubusercontent.com/u/362503?v=3");
    assertThat(user.getEmails()).containsOnly("rob@example.com");
    assertThat(user.getGitHubLogin()).isEqualTo("rwinch");
    assertThat(user.getName()).isEqualTo("Rob Winch");
    assertThat(user.isAdminAccessRequested()).isTrue();
    assertThat(user.isAdmin()).isFalse();
    RecordedRequest request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("POST");
    assertThat(request.getPath()).isEqualTo("/login/oauth/access_token");
    assertThat(request.getBody().readUtf8()).isEqualTo("{\"code\":\"code-123\",\"client_secret\":\"client-secret\",\"state\":\"state-456\",\"client_id\":\"client-id\",\"redirect_url\":\"https://example.com/oauth/callback\"}");
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user/emails?per_page=100&page=1");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
    request = server.getServer().takeRequest();
    assertThat(request.getMethod()).isEqualTo("GET");
    assertThat(request.getPath()).isEqualTo("/api/v3/user");
    assertThat(request.getHeader("Authorization")).isEqualTo("token " + user.getAccessToken());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) User(io.pivotal.cla.data.User) Test(org.junit.Test) EnqueueRequests(okhttp3.mockwebserver.EnqueueRequests)

Example 25 with User

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

the class GitHubHooksControllerTests method skipRequestsWithoutPullRequest.

@Test
public void skipRequestsWithoutPullRequest() 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));
    mockMvc.perform(hookRequest().header("X-GitHub-Event", GithubEvents.PULL_REQUEST).content(getPayload("issue.json"))).andExpect(status().isBadRequest());
    verifyZeroInteractions(mockGitHub);
}
Also used : User(io.pivotal.cla.data.User) AccessToken(io.pivotal.cla.data.AccessToken) Test(org.junit.Test)

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