use of org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationToken in project gocd by gocd.
the class AuthenticationRequestProcessorTest method shouldAuthenticateUser.
@Test
public void shouldAuthenticateUser() {
String responseBody = "expected-response-body";
User user = new User("username", "display name", "test@test.com");
when(jsonMessageHandler.responseMessageForAuthenticateUser(responseBody)).thenReturn(user);
AuthenticationRequestProcessor processorSpy = spy(processor);
doReturn(securityContext).when(processorSpy).getSecurityContext();
GoApiResponse response = processorSpy.process(pluginDescriptor, getGoPluginApiRequest("1.0", responseBody));
assertThat(response.responseCode(), is(200));
verify(userService).addUserIfDoesNotExist(new com.thoughtworks.go.domain.User("username", "", ""));
GoUserPrinciple goUserPrincipal = processorSpy.getGoUserPrincipal(user);
assertThat(goUserPrincipal.getUsername(), is("username"));
assertThat(goUserPrincipal.getDisplayName(), is("display name"));
verifyGrantAuthorities(goUserPrincipal.getAuthorities());
PreAuthenticatedAuthenticationToken authenticationToken = processorSpy.getAuthenticationToken(goUserPrincipal);
assertThat(authenticationToken.getPrincipal(), is(goUserPrincipal));
verifyGrantAuthorities(authenticationToken.getAuthorities());
verify(securityContext).setAuthentication(authenticationToken);
}
Aggregations