Search in sources :

Example 16 with User

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

the class AuthenticationTests method userUrlWithAdminUserThenAdminUrl.

@SuppressWarnings("unchecked")
@Test
public void userUrlWithAdminUserThenAdminUrl() throws Exception {
    User currentUser = WithAdminUserFactory.create();
    currentUser.setAdmin(false);
    when(mockClaRepository.findByNameAndPrimaryTrue(cla.getName())).thenReturn(cla);
    when(mockGitHub.getCurrentUser(any(CurrentUserRequest.class))).thenAnswer(new Answer<User>() {

        @Override
        public User answer(InvocationOnMock invocation) throws Throwable {
            CurrentUserRequest request = invocation.getArgumentAt(0, CurrentUserRequest.class);
            User currentUser = WithAdminUserFactory.create();
            currentUser.setAdmin(request.isRequestAdminAccess());
            return currentUser;
        }
    });
    when(mockIndividualSignatureRepository.findByEmailIn(anySet())).thenReturn(Collections.emptyList());
    SignClaPage signClaPage = SignClaPage.go(driver, cla.getName());
    signClaPage.assertAt();
    when(mockClaRepository.findAll()).thenReturn(Arrays.asList(cla));
    when(mockGitHub.findRepositoryNamesWithAdminPermission(anyString())).thenReturn(Arrays.asList("test/this"));
    AdminLinkClaPage admin = AdminLinkClaPage.to(driver);
    admin.assertAt();
    ArgumentCaptor<CurrentUserRequest> userCaptor = ArgumentCaptor.forClass(CurrentUserRequest.class);
    verify(mockGitHub, times(2)).getCurrentUser(userCaptor.capture());
    assertThat(userCaptor.getAllValues()).extracting(CurrentUserRequest::isRequestAdminAccess).containsOnly(false, true);
}
Also used : SignClaPage(io.pivotal.cla.webdriver.pages.SignClaPage) WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CurrentUserRequest(io.pivotal.cla.service.github.CurrentUserRequest) AdminLinkClaPage(io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage) Test(org.junit.Test)

Example 17 with User

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

the class AuthenticationTests method loginVerifiesSecretState.

@Test
public void loginVerifiesSecretState() throws Exception {
    User currentUser = WithAdminUserFactory.create();
    when(mockGitHub.getCurrentUser(any(CurrentUserRequest.class))).thenReturn(currentUser);
    MockHttpSession session = new MockHttpSession();
    String redirect = mockMvc.perform(get("/sign/pivotal").session(session)).andExpect(status().is3xxRedirection()).andReturn().getResponse().getRedirectedUrl();
    redirect = mockMvc.perform(get(redirect)).andReturn().getResponse().getRedirectedUrl();
    // change the expected secret state
    session.setAttribute("state", "INVALID");
    mockMvc.perform(get(redirect).session(session)).andExpect(status().isBadRequest());
}
Also used : WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) MockHttpSession(org.springframework.mock.web.MockHttpSession) CurrentUserRequest(io.pivotal.cla.service.github.CurrentUserRequest) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 18 with User

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

the class CclaControllerTests method signFormSigned.

@Test
public void signFormSigned() throws Exception {
    List<String> organizations = Arrays.asList(corporateSignature.getGitHubOrganization());
    User user = WithSigningUserFactory.create();
    when(mockGitHub.getOrganizations(user.getGitHubLogin())).thenReturn(organizations);
    when(mockClaRepository.findByNameAndPrimaryTrue(cla.getName())).thenReturn(cla);
    when(mockCorporateSignatureRepository.findSignature(cla.getName(), organizations, user.getEmails())).thenReturn(corporateSignature);
    SignCclaPage signPage = SignCclaPage.go(getDriver(), cla.getName());
    assertThat(signPage.isSigned()).isTrue();
}
Also used : WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) SignCclaPage(io.pivotal.cla.webdriver.pages.SignCclaPage) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 19 with User

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

the class ClaControllerTests method claPivotalCorporateSigned.

@Test
public void claPivotalCorporateSigned() throws Exception {
    List<String> organizations = Arrays.asList(corporateSignature.getGitHubOrganization());
    User user = WithSigningUserFactory.create();
    when(mockGitHub.getOrganizations(user.getGitHubLogin())).thenReturn(organizations);
    when(mockClaRepository.findByNameAndPrimaryTrue(cla.getName())).thenReturn(cla);
    when(mockCorporateSignatureRepository.findSignature(cla.getName(), organizations, user.getEmails())).thenReturn(corporateSignature);
    SignClaPage claPage = SignClaPage.go(driver, cla.getName());
    claPage.assertSigned();
}
Also used : SignClaPage(io.pivotal.cla.webdriver.pages.SignClaPage) WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) Test(org.junit.Test)

Example 20 with User

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

the class WithClaAuthorUserFactory method createSecurityContext.

@Override
public SecurityContext createSecurityContext(WithClaAuthorUser user) {
    User adminUser = create();
    UserAuthentication auth = new UserAuthentication(adminUser);
    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