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