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