use of io.pivotal.cla.data.User in project pivotal-cla by pivotalsoftware.
the class WithSigningUserFactory method create.
public static User create() {
User user = new User();
user.setAccessToken("mocked_access_token");
user.setAvatarUrl("https://avatars.githubusercontent.com/u/362503?v=3");
user.setEmails(Collections.singleton("rob@gmail.com"));
user.setGitHubLogin("robwinch");
return user;
}
use of io.pivotal.cla.data.User in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApi method getCurrentUser.
public User getCurrentUser(CurrentUserRequest request) {
AccessTokenRequest tokenRequest = new AccessTokenRequest();
tokenRequest.setCredentials(oauthConfig.getMain());
tokenRequest.setOauthParams(request.getOauthParams());
String accessToken = getToken(tokenRequest);
Set<String> verifiedEmails = getVerifiedEmails(accessToken);
org.eclipse.egit.github.core.User currentGitHubUser = getCurrentGitHubUser(accessToken);
User user = new User();
user.setName(currentGitHubUser.getName());
user.setAccessToken(accessToken);
user.setAvatarUrl(currentGitHubUser.getAvatarUrl());
user.setEmails(new TreeSet<>(verifiedEmails));
user.setGitHubLogin(currentGitHubUser.getLogin());
user.setAdminAccessRequested(request.isRequestAdminAccess());
boolean isAdmin = request.isRequestAdminAccess() && hasAdminEmail(user);
user.setAdmin(isAdmin);
if (isAdmin) {
boolean isClaAuthor = isAuthor(user.getGitHubLogin(), accessToken);
user.setClaAuthor(isClaAuthor);
}
return user;
}
use of io.pivotal.cla.data.User in project pivotal-cla by pivotalsoftware.
the class ClaService method hasSigned.
private boolean hasSigned(String gitHubLogin, String claName) {
User user = userRepository.findOne(gitHubLogin);
if (user == null) {
user = new User();
user.setGitHubLogin(gitHubLogin);
user.setEmails(new HashSet<>());
}
return hasSigned(user, claName);
}
use of io.pivotal.cla.data.User in project pivotal-cla by pivotalsoftware.
the class AccessDeniedTests method adminRedirectForUserNotRequestedAdmin.
@Test
@WithSigningUser
public void adminRedirectForUserNotRequestedAdmin() throws Exception {
User user = WithSigningUserFactory.create();
when(mockClaRepository.findByNameAndPrimaryTrue(cla.getName())).thenReturn(cla);
when(mockGitHub.getCurrentUser(any(CurrentUserRequest.class))).thenReturn(user);
String url = AdminLinkClaPage.url();
mockMvc.perform(get(url)).andExpect(status().is3xxRedirection());
}
use of io.pivotal.cla.data.User in project pivotal-cla by pivotalsoftware.
the class AuthenticationTests method authenticateUser.
@Test
public void authenticateUser() throws Exception {
User user = WithSigningUserFactory.create();
when(mockClaRepository.findByNameAndPrimaryTrue(cla.getName())).thenReturn(cla);
when(mockGitHub.getCurrentUser(any(CurrentUserRequest.class))).thenReturn(user);
SignClaPage claPage = SignClaPage.go(driver, cla.getName());
claPage.assertAt();
ArgumentCaptor<CurrentUserRequest> userCaptor = ArgumentCaptor.forClass(CurrentUserRequest.class);
verify(mockGitHub).getCurrentUser(userCaptor.capture());
CurrentUserRequest userRequest = userCaptor.getValue();
OAuthAccessTokenParams oauthParams = userRequest.getOauthParams();
assertThat(userRequest.isRequestAdminAccess()).isFalse();
assertThat(oauthParams.getCallbackUrl()).isEqualTo("https://localhost/login/oauth2/github");
assertThat(oauthParams.getCode()).isEqualTo("abc");
}
Aggregations