Search in sources :

Example 1 with AdminLinkClaPage

use of io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage in project pivotal-cla by pivotalsoftware.

the class AuthenticationTests method savedRequestUsed.

@Test
public void savedRequestUsed() throws Exception {
    User user = WithAdminUserFactory.create();
    when(mockGitHub.getCurrentUser(any(CurrentUserRequest.class))).thenReturn(user);
    when(mockClaRepository.findAll()).thenReturn(Arrays.asList(cla));
    AdminLinkClaPage page = AdminLinkClaPage.to(getDriver());
    page.assertAt();
}
Also used : WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) CurrentUserRequest(io.pivotal.cla.service.github.CurrentUserRequest) AdminLinkClaPage(io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage) Test(org.junit.Test)

Example 2 with AdminLinkClaPage

use of io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage in project pivotal-cla by pivotalsoftware.

the class AuthenticationTests method authenticateAdmin.

@Test
public void authenticateAdmin() throws Exception {
    User user = WithAdminUserFactory.create();
    when(mockGitHub.getCurrentUser(any(CurrentUserRequest.class))).thenReturn(user);
    AdminLinkClaPage admin = AdminLinkClaPage.to(driver);
    admin.assertAt();
    ArgumentCaptor<CurrentUserRequest> userCaptor = ArgumentCaptor.forClass(CurrentUserRequest.class);
    verify(mockGitHub).getCurrentUser(userCaptor.capture());
    CurrentUserRequest userRequest = userCaptor.getValue();
    OAuthAccessTokenParams oauthParams = userRequest.getOauthParams();
    assertThat(userRequest.isRequestAdminAccess()).isTrue();
    assertThat(oauthParams.getCallbackUrl()).isEqualTo("https://localhost/login/oauth2/github");
    assertThat(oauthParams.getCode()).isEqualTo("abc");
}
Also used : WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) CurrentUserRequest(io.pivotal.cla.service.github.CurrentUserRequest) AdminLinkClaPage(io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage) OAuthAccessTokenParams(io.pivotal.cla.service.github.OAuthAccessTokenParams) Test(org.junit.Test)

Example 3 with AdminLinkClaPage

use of io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage in project pivotal-cla by pivotalsoftware.

the class AdminHomeTests method claAuthorUserManageLinkVisible.

@Test
@WithClaAuthorUser
public void claAuthorUserManageLinkVisible() {
    AdminLinkClaPage page = AdminLinkClaPage.to(getDriver());
    page.assertManageLink(true);
}
Also used : AdminLinkClaPage(io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage) Test(org.junit.Test) WithClaAuthorUser(io.pivotal.cla.security.WithClaAuthorUser)

Example 4 with AdminLinkClaPage

use of io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage in project pivotal-cla by pivotalsoftware.

the class AdminHomeTests method adminUserManageLinkNotVisible.

@Test
public void adminUserManageLinkNotVisible() {
    AdminLinkClaPage page = AdminLinkClaPage.to(getDriver());
    page.assertManageLink(false);
}
Also used : AdminLinkClaPage(io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage) Test(org.junit.Test)

Example 5 with AdminLinkClaPage

use of io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage in project pivotal-cla by pivotalsoftware.

the class AdminLinkClaTests method linkClaRepositories.

@Test
@SuppressWarnings("unchecked")
public void linkClaRepositories() throws Exception {
    AccessToken token = new AccessToken(AccessToken.CLA_ACCESS_TOKEN_ID, "linkClaValidationRepositories_access_token_abc123");
    when(mockTokenRepo.findOne(AccessToken.CLA_ACCESS_TOKEN_ID)).thenReturn(token);
    when(mockGitHub.getContributingUrls(anyList())).thenReturn(new ContributingUrlsResponse());
    User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    AdminLinkClaPage link = AdminLinkClaPage.to(getDriver());
    link = link.link("test/this", cla.getName(), AdminLinkClaPage.class);
    link.assertRepositories().hasNoErrors();
    link.assertClaName().hasNoErrors();
    ArgumentCaptor<CreatePullRequestHookRequest> requestCaptor = ArgumentCaptor.forClass(CreatePullRequestHookRequest.class);
    verify(mockGitHub).createPullRequestHooks(requestCaptor.capture());
    CreatePullRequestHookRequest request = requestCaptor.getValue();
    assertThat(request.getAccessToken()).isEqualTo(user.getAccessToken());
    assertThat(request.getRepositoryIds()).containsOnly("test/this");
    assertThat(request.getGitHubEventUrl()).isEqualTo("http://localhost/github/hooks/pull_request/" + cla.getName());
    assertThat(request.getSecret()).isEqualTo(token.getToken());
    assertThat(driver.getPageSource()).doesNotContain(token.getToken());
    ArgumentCaptor<AccessToken> tokenCaptor = ArgumentCaptor.forClass(AccessToken.class);
    verify(mockTokenRepo).save(tokenCaptor.capture());
    AccessToken savedToken = tokenCaptor.getValue();
    assertThat(savedToken.getId()).isEqualTo("test/this");
    assertThat(savedToken.getToken()).isEqualTo(user.getAccessToken());
    PullRequestStatus expectedStatus = new PullRequestStatus();
    expectedStatus.setAccessToken("access-token-123");
    expectedStatus.setGitHubUsername("username");
    expectedStatus.setPullRequestId(1);
    expectedStatus.setRepoId("repo");
    expectedStatus.setSha("12345678");
    expectedStatus.setUrl("https://cla.pivotal.io/sign/pivotal");
    when(mockGitHub.createUpdatePullRequestStatuses(any())).thenReturn(Arrays.asList(expectedStatus));
    link = link.migrate();
    ArgumentCaptor<PullRequestStatus> statusCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
    verify(mockGitHub).save(statusCaptor.capture());
    PullRequestStatus status = statusCaptor.getValue();
    assertThat(status.getAccessToken()).isEqualTo(expectedStatus.getAccessToken());
    assertThat(status.getGitHubUsername()).isEqualTo(expectedStatus.getGitHubUsername());
    assertThat(status.getPullRequestId()).isEqualTo(expectedStatus.getPullRequestId());
    assertThat(status.getRepoId()).isEqualTo(expectedStatus.getRepoId());
    assertThat(status.getSha()).isEqualTo(expectedStatus.getSha());
    assertThat(status.getSuccess()).isFalse();
    assertThat(status.getUrl()).isEqualTo(expectedStatus.getUrl());
}
Also used : WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) WithAdminUser(io.pivotal.cla.security.WithAdminUser) CreatePullRequestHookRequest(io.pivotal.cla.service.github.CreatePullRequestHookRequest) AccessToken(io.pivotal.cla.data.AccessToken) ContributingUrlsResponse(io.pivotal.cla.service.github.ContributingUrlsResponse) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) AdminLinkClaPage(io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage) Test(org.junit.Test)

Aggregations

AdminLinkClaPage (io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage)12 Test (org.junit.Test)12 User (io.pivotal.cla.data.User)4 WithSigningUser (io.pivotal.cla.security.WithSigningUser)4 CurrentUserRequest (io.pivotal.cla.service.github.CurrentUserRequest)3 SignClaPage (io.pivotal.cla.webdriver.pages.SignClaPage)2 AccessToken (io.pivotal.cla.data.AccessToken)1 WithAdminUser (io.pivotal.cla.security.WithAdminUser)1 WithClaAuthorUser (io.pivotal.cla.security.WithClaAuthorUser)1 ContributingUrlsResponse (io.pivotal.cla.service.github.ContributingUrlsResponse)1 CreatePullRequestHookRequest (io.pivotal.cla.service.github.CreatePullRequestHookRequest)1 OAuthAccessTokenParams (io.pivotal.cla.service.github.OAuthAccessTokenParams)1 PullRequestStatus (io.pivotal.cla.service.github.PullRequestStatus)1 HomePage (io.pivotal.cla.webdriver.pages.HomePage)1 SignIclaPage (io.pivotal.cla.webdriver.pages.SignIclaPage)1 GitHubLoginPage (io.pivotal.cla.webdriver.pages.github.GitHubLoginPage)1 GitHubPullRequestPage (io.pivotal.cla.webdriver.pages.github.GitHubPullRequestPage)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1