use of org.eclipse.jetty.server.Request in project gocd by gocd.
the class DeploymentContextWriterTest method shouldSkipRedirectWhenSiteUrlIsNotConfigured.
@Test
public void shouldSkipRedirectWhenSiteUrlIsNotConfigured() throws URISyntaxException {
final ServerConfigService serverConfigService = mock(ServerConfigService.class);
when(serverConfigService.hasAnyUrlConfigured()).thenReturn(false);
Request req = new Request(mock(HttpChannel.class), mock(HttpInput.class));
req.setUri(new HttpURI("/go/admin?tab=oAuth"));
req.setServerName("url");
req.setServerPort(8153);
// req.setProtocol("http");
DeploymentContextWriter writer = new DeploymentContextWriter() {
@Override
protected BaseUrlProvider getBaseUrlProvider(HttpServletRequest req) {
return serverConfigService;
}
};
writer.writeSecureSiteUrl(req);
assertThat(req.getAttribute("secure_site"), is(nullValue()));
assertThat(req.getAttribute("force_ssl"), is(nullValue()));
}
use of org.eclipse.jetty.server.Request in project gocd by gocd.
the class GoVelocityViewTest method shouldSetAssetsPathVariableWhenRailsNewWithCompressedJavascriptsIsUsed.
@Test
public void shouldSetAssetsPathVariableWhenRailsNewWithCompressedJavascriptsIsUsed() throws Exception {
SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
when(systemEnvironment.useCompressedJs()).thenReturn(true);
when(railsAssetsService.getAssetPath("application.js")).thenReturn("assets/application-digest.js");
when(railsAssetsService.getAssetPath("application.css")).thenReturn("assets/application-digest.css");
when(railsAssetsService.getAssetPath("vm/application.css")).thenReturn("assets/vm/application-digest.css");
when(railsAssetsService.getAssetPath("css/application.css")).thenReturn("assets/css/application-digest.css");
when(railsAssetsService.getAssetPath("g9/stage_bar_cancelled_icon.png")).thenReturn("assets/g9/stage_bar_cancelled_icon.png");
when(railsAssetsService.getAssetPath("spinner.gif")).thenReturn("assets/spinner.gif");
when(railsAssetsService.getAssetPath("cruise.ico")).thenReturn("assets/cruise.ico");
GoVelocityView view = spy(new GoVelocityView(systemEnvironment));
doReturn(railsAssetsService).when(view).getRailsAssetsService();
doReturn(versionInfoService).when(view).getVersionInfoService();
doReturn(pluginInfoFinder).when(view).getPluginInfoFinder();
Request servletRequest = mock(Request.class);
when(servletRequest.getSession()).thenReturn(mock(HttpSession.class));
view.exposeHelpers(velocityContext, servletRequest);
assertThat(velocityContext.get(GoVelocityView.CONCATENATED_JAVASCRIPT_FILE_PATH), is("assets/application-digest.js"));
assertThat(velocityContext.get(GoVelocityView.CONCATENATED_APPLICATION_CSS_FILE_PATH), is("assets/application-digest.css"));
assertThat(velocityContext.get(GoVelocityView.CONCATENATED_VM_APPLICATION_CSS_FILE_PATH), is("assets/vm/application-digest.css"));
assertThat(velocityContext.get(GoVelocityView.CONCATENATED_CSS_APPLICATION_CSS_FILE_PATH), is("assets/css/application-digest.css"));
assertThat(velocityContext.get(GoVelocityView.CONCATENATED_STAGE_BAR_CANCELLED_ICON_FILE_PATH), is("assets/g9/stage_bar_cancelled_icon.png"));
assertThat(velocityContext.get(GoVelocityView.CONCATENATED_SPINNER_ICON_FILE_PATH), is("assets/spinner.gif"));
assertThat(velocityContext.get(GoVelocityView.CONCATENATED_CRUISE_ICON_FILE_PATH), is("assets/cruise.ico"));
assertThat(velocityContext.get(GoVelocityView.PATH_RESOLVER), is(railsAssetsService));
}
use of org.eclipse.jetty.server.Request in project airlift by airlift.
the class TestDelimitedRequestLog method testTraceTokenHeader.
@Test
public void testTraceTokenHeader() throws Exception {
Request request = mock(Request.class);
Response response = mock(Response.class);
TraceTokenManager tokenManager = new TraceTokenManager();
InMemoryEventClient eventClient = new InMemoryEventClient();
DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, 256, Long.MAX_VALUE, tokenManager, eventClient, new SystemCurrentTimeMillisProvider(), false);
String token = "test-trace-token";
when(request.getHeader(TRACETOKEN_HEADER)).thenReturn(token);
// log a request without a token set by tokenManager
logger.log(request, response);
// create and set a new token with tokenManager
tokenManager.createAndRegisterNewRequestToken();
logger.log(request, response);
// clear the token HTTP header
when(request.getHeader(TRACETOKEN_HEADER)).thenReturn(null);
logger.log(request, response);
logger.stop();
List<Object> events = eventClient.getEvents();
assertEquals(events.size(), 3);
// first two events should have the token set from the header
for (int i = 0; i < 2; i++) {
assertEquals(((HttpRequestEvent) events.get(i)).getTraceToken(), token);
}
// last event should have the token set by the tokenManager
assertEquals(((HttpRequestEvent) events.get(2)).getTraceToken(), tokenManager.getCurrentRequestToken());
}
use of org.eclipse.jetty.server.Request in project airlift by airlift.
the class TestDelimitedRequestLog method testXForwardedForSkipPrivateAddresses.
@Test
public void testXForwardedForSkipPrivateAddresses() throws Exception {
Request request = mock(Request.class);
Response response = mock(Response.class);
String clientIp = "1.1.1.1";
when(request.getRemoteAddr()).thenReturn("9.9.9.9");
when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of(clientIp, "192.168.1.2, 172.16.0.1", "169.254.1.2, 127.1.2.3", "10.1.2.3")));
InMemoryEventClient eventClient = new InMemoryEventClient();
DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, 256, Long.MAX_VALUE, null, eventClient, false);
logger.log(request, response);
logger.stop();
List<Object> events = eventClient.getEvents();
assertEquals(events.size(), 1);
HttpRequestEvent event = (HttpRequestEvent) events.get(0);
assertEquals(event.getClientAddress(), clientIp);
}
use of org.eclipse.jetty.server.Request in project airlift by airlift.
the class TestDelimitedRequestLog method testNoXForwardedFor.
@Test
public void testNoXForwardedFor() throws Exception {
Request request = mock(Request.class);
Response response = mock(Response.class);
String clientIp = "1.1.1.1";
when(request.getRemoteAddr()).thenReturn(clientIp);
InMemoryEventClient eventClient = new InMemoryEventClient();
DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, 256, Long.MAX_VALUE, null, eventClient, false);
logger.log(request, response);
logger.stop();
List<Object> events = eventClient.getEvents();
assertEquals(events.size(), 1);
HttpRequestEvent event = (HttpRequestEvent) events.get(0);
assertEquals(event.getClientAddress(), clientIp);
}
Aggregations