Search in sources :

Example 11 with User

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;
}
Also used : User(io.pivotal.cla.data.User)

Example 12 with 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;
}
Also used : User(io.pivotal.cla.data.User)

Example 13 with 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);
}
Also used : User(io.pivotal.cla.data.User)

Example 14 with User

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());
}
Also used : WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) CurrentUserRequest(io.pivotal.cla.service.github.CurrentUserRequest) WithSigningUser(io.pivotal.cla.security.WithSigningUser) Test(org.junit.Test)

Example 15 with User

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");
}
Also used : SignClaPage(io.pivotal.cla.webdriver.pages.SignClaPage) WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) CurrentUserRequest(io.pivotal.cla.service.github.CurrentUserRequest) OAuthAccessTokenParams(io.pivotal.cla.service.github.OAuthAccessTokenParams) 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