Search in sources :

Example 1 with GoApiResponse

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));
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) Test(org.junit.Test)

Example 2 with GoApiResponse

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);
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) User(com.thoughtworks.go.plugin.access.authentication.models.User) PreAuthenticatedAuthenticationToken(org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationToken) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple) Test(org.junit.Test)

Example 3 with GoApiResponse

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");
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) AuthorizationMessageConverterV1(com.thoughtworks.go.plugin.access.authorization.AuthorizationMessageConverterV1) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) GoApiRequest(com.thoughtworks.go.plugin.api.request.GoApiRequest) PluginRoleService(com.thoughtworks.go.server.service.PluginRoleService) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 4 with GoApiResponse

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);
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 5 with GoApiResponse

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));
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Aggregations

GoApiResponse (com.thoughtworks.go.plugin.api.response.GoApiResponse)16 Test (org.junit.Test)16 DefaultGoApiRequest (com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest)6 NullPlugin (com.thoughtworks.go.domain.NullPlugin)3 HashMap (java.util.HashMap)3 Plugin (com.thoughtworks.go.domain.Plugin)2 User (com.thoughtworks.go.plugin.access.authentication.models.User)1 AuthorizationMessageConverterV1 (com.thoughtworks.go.plugin.access.authorization.AuthorizationMessageConverterV1)1 GoApiRequest (com.thoughtworks.go.plugin.api.request.GoApiRequest)1 ElasticAgentMetadata (com.thoughtworks.go.server.domain.ElasticAgentMetadata)1 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)1 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)1 PluginRoleService (com.thoughtworks.go.server.service.PluginRoleService)1 Map (java.util.Map)1 PreAuthenticatedAuthenticationToken (org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationToken)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1