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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations