Search in sources :

Example 11 with DefaultGoPluginApiResponse

use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.

the class AuthorizationExtensionTest method shouldTalkToPlugin_To_GetAuthorizationServerUrl.

@Test
public void shouldTalkToPlugin_To_GetAuthorizationServerUrl() throws JSONException {
    String requestBody = "{\n" + "  \"auth_configs\": [\n" + "    {\n" + "      \"id\": \"github\",\n" + "      \"configuration\": {\n" + "        \"url\": \"some-url\"\n" + "      }\n" + "    }\n" + "  ],\n" + "  \"authorization_server_callback_url\": \"http://go.site.url/go/plugin/plugin-id/authenticate\"\n" + "}";
    String responseBody = "{\"authorization_server_url\":\"url_to_authorization_server\"}";
    SecurityAuthConfig authConfig = new SecurityAuthConfig("github", "cd.go.github", ConfigurationPropertyMother.create("url", false, "some-url"));
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
    String authorizationServerRedirectUrl = authorizationExtension.getAuthorizationServerUrl(PLUGIN_ID, Collections.singletonList(authConfig), "http://go.site.url");
    assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_AUTHORIZATION_SERVER_URL, requestBody);
    assertThat(authorizationServerRedirectUrl, is("url_to_authorization_server"));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.Test)

Example 12 with DefaultGoPluginApiResponse

use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.

the class NotificationExtensionTestForV3 method shouldNotifyPluginSettingsChange.

@Test
public void shouldNotifyPluginSettingsChange() throws Exception {
    String supportedVersion = "3.0";
    Map<String, String> settings = Collections.singletonMap("foo", "bar");
    ArgumentCaptor<GoPluginApiRequest> requestArgumentCaptor = ArgumentCaptor.forClass(GoPluginApiRequest.class);
    when(pluginManager.resolveExtensionVersion("pluginId", NOTIFICATION_EXTENSION, Arrays.asList("1.0", "2.0", "3.0"))).thenReturn(supportedVersion);
    when(pluginManager.isPluginOfType(NOTIFICATION_EXTENSION, "pluginId")).thenReturn(true);
    when(pluginManager.submitTo(eq("pluginId"), eq(NOTIFICATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, ""));
    NotificationExtension extension = new NotificationExtension(pluginManager);
    extension.notifyPluginSettingsChange("pluginId", settings);
    assertRequest(requestArgumentCaptor.getValue(), NOTIFICATION_EXTENSION, supportedVersion, REQUEST_NOTIFY_PLUGIN_SETTINGS_CHANGE, "{\"foo\":\"bar\"}");
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.Test)

Example 13 with DefaultGoPluginApiResponse

use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.

the class PluginControllerTest method shouldRedirectToSpecifiedLocationOn302.

@Test
public void shouldRedirectToSpecifiedLocationOn302() throws Exception {
    when(pluginManager.isPluginOfType(any(String.class), any(String.class))).thenReturn(true);
    DefaultGoPluginApiResponse apiResponse = new DefaultGoPluginApiResponse(302);
    String redirectLocation = "/go/plugin/interact/plugin.id/request.name";
    apiResponse.responseHeaders().put("Location", redirectLocation);
    when(pluginManager.submitTo(eq(PLUGIN_ID), any(GoPluginApiRequest.class))).thenReturn(apiResponse);
    when(servletRequest.getParameterMap()).thenReturn(new HashMap<>());
    when(servletRequest.getHeaderNames()).thenReturn(getMockEnumeration(new ArrayList<>()));
    pluginController.handlePluginInteractRequest(PLUGIN_ID, REQUEST_NAME, servletRequest, servletResponse);
    verify(servletResponse, times(1)).sendRedirect(anyString());
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.Test)

Example 14 with DefaultGoPluginApiResponse

use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.

the class PluginControllerTest method shouldRenderPluginResponseWithSpecifiedContentTypeOn200.

@Test
public void shouldRenderPluginResponseWithSpecifiedContentTypeOn200() throws Exception {
    when(pluginManager.isPluginOfType(any(String.class), any(String.class))).thenReturn(true);
    DefaultGoPluginApiResponse apiResponse = new DefaultGoPluginApiResponse(200);
    String contentType = "image/png";
    apiResponse.responseHeaders().put("Content-Type", contentType);
    String responseBody = "response-body";
    apiResponse.setResponseBody(responseBody);
    when(pluginManager.submitTo(eq(PLUGIN_ID), any(GoPluginApiRequest.class))).thenReturn(apiResponse);
    when(servletRequest.getParameterMap()).thenReturn(new HashMap<>());
    when(servletRequest.getHeaderNames()).thenReturn(getMockEnumeration(new ArrayList<>()));
    pluginController.handlePluginInteractRequest(PLUGIN_ID, REQUEST_NAME, servletRequest, servletResponse);
    assertThat(contentTypeArgument.getValue(), is(contentType));
    verify(writer).write(responseBody);
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.Test)

Example 15 with DefaultGoPluginApiResponse

use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.

the class PluginControllerTest method shouldRenderPluginResponseWithDefaultContentTypeOn200.

@Test
public void shouldRenderPluginResponseWithDefaultContentTypeOn200() throws Exception {
    when(pluginManager.isPluginOfType(any(String.class), any(String.class))).thenReturn(true);
    DefaultGoPluginApiResponse apiResponse = new DefaultGoPluginApiResponse(200);
    String responseBody = "response-body";
    apiResponse.setResponseBody(responseBody);
    when(pluginManager.submitTo(eq(PLUGIN_ID), requestArgumentCaptor.capture())).thenReturn(apiResponse);
    when(servletRequest.getParameterMap()).thenReturn(new HashMap<>());
    when(servletRequest.getHeaderNames()).thenReturn(getMockEnumeration(new ArrayList<>()));
    pluginController.handlePluginInteractRequest(PLUGIN_ID, REQUEST_NAME, servletRequest, servletResponse);
    assertThat(contentTypeArgument.getValue(), is(PluginController.CONTENT_TYPE_HTML));
    verify(writer).write(responseBody);
    assertRequest(requestArgumentCaptor.getValue(), REQUEST_NAME, new HashMap<>(), new HashMap<>());
}
Also used : DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.Test)

Aggregations

DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)30 Test (org.junit.Test)30 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)10 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)6 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)6 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)4 User (com.thoughtworks.go.plugin.access.authorization.models.User)3 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)2 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)2 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)2 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)2 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 PluginSettingsJsonMessageHandler2_0 (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsJsonMessageHandler2_0)1 AnalyticsData (com.thoughtworks.go.plugin.domain.analytics.AnalyticsData)1 AnalyticsPluginInfo (com.thoughtworks.go.plugin.domain.analytics.AnalyticsPluginInfo)1 SupportedAnalytics (com.thoughtworks.go.plugin.domain.analytics.SupportedAnalytics)1 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)1 Matchers.anyString (org.mockito.Matchers.anyString)1