use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.
the class AuthenticationRequestProcessorTest method shouldHandleEmptyRequestBody.
@Test
public void shouldHandleEmptyRequestBody() {
GoApiResponse response = processor.process(pluginDescriptor, getGoPluginApiRequest("1.0", "{}"));
assertThat(response.responseCode(), is(500));
}
use of com.thoughtworks.go.plugin.api.response.GoApiResponse 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);
}
use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.
the class AuthorizationRequestProcessorTest method shouldProcessInvalidateCacheRequest.
@Test
public void shouldProcessInvalidateCacheRequest() throws Exception {
PluginRoleService pluginRoleService = mock(PluginRoleService.class);
when(authorizationExtension.getMessageConverter(AuthorizationMessageConverterV1.VERSION)).thenReturn(new AuthorizationMessageConverterV1());
GoApiRequest request = new DefaultGoApiRequest(INVALIDATE_CACHE_REQUEST.requestName(), "1.0", null);
AuthorizationRequestProcessor authorizationRequestProcessor = new AuthorizationRequestProcessor(registry, null, authorizationExtension, pluginRoleService);
GoApiResponse response = authorizationRequestProcessor.process(pluginDescriptor, request);
assertThat(response.responseCode(), is(200));
verify(pluginRoleService).invalidateRolesFor("cd.go.authorization.github");
}
use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.
the class ElasticAgentRequestProcessorTest method shouldProcessListAgentRequest.
@Test
public void shouldProcessListAgentRequest() throws Exception {
LinkedMultiValueMap<String, ElasticAgentMetadata> allAgents = new LinkedMultiValueMap<>();
ElasticAgentMetadata agent = new ElasticAgentMetadata("foo", "bar", "docker", AgentRuntimeStatus.Building, AgentConfigStatus.Disabled);
allAgents.put("docker", Arrays.asList(agent));
when(agentService.allElasticAgents()).thenReturn(allAgents);
GoApiResponse response = processor.process(pluginDescriptor, new DefaultGoApiRequest(REQUEST_SERVER_LIST_AGENTS, "1.0", pluginIdentifier));
JSONAssert.assertEquals("[{\"agent_id\":\"bar\",\"agent_state\":\"Building\",\"build_state\":\"Building\",\"config_state\":\"Disabled\"}]", response.responseBody(), true);
}
use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.
the class PluginSettingsRequestProcessorTest method shouldHandleIncorrectAPIVersion.
@Test
public void shouldHandleIncorrectAPIVersion() {
GoApiResponse response = processor.process(pluginDescriptor, new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.1", null));
assertThat(response.responseCode(), is(400));
}
Aggregations