use of com.thoughtworks.go.server.service.ServerConfigService in project gocd by gocd.
the class DeploymentContextWriterTest method shouldSetSecureSiteURLWhenSiteUrlIsConfigured.
@Test
public void shouldSetSecureSiteURLWhenSiteUrlIsConfigured() throws URISyntaxException {
final ServerConfigService serverConfigService = mock(ServerConfigService.class);
when(serverConfigService.hasAnyUrlConfigured()).thenReturn(true);
when(serverConfigService.siteUrlFor("http://url/go/admin?tab=oAuth", true)).thenReturn("https://url/go/admin?tab=oAuth");
Request request = new Request(mock(HttpChannel.class), mock(HttpInput.class));
request.setUri(new HttpURI("/go/admin?tab=oAuth"));
request.setServerName("url");
DeploymentContextWriter writer = new DeploymentContextWriter() {
@Override
protected BaseUrlProvider getBaseUrlProvider(HttpServletRequest req) {
return serverConfigService;
}
};
writer.writeSecureSiteUrl(request);
assertThat(request.getAttribute("secure_site"), is("https://url/go/admin?tab=oAuth"));
assertThat(request.getAttribute("force_ssl"), is("true"));
}
use of com.thoughtworks.go.server.service.ServerConfigService 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 com.thoughtworks.go.server.service.ServerConfigService in project gocd by gocd.
the class DeploymentContextWriterTest method shouldSetShouldRedirectToFalseWhenSecureSiteURLIsNotSetAndSiteUrlIsNonHTTPS.
@Test
public void shouldSetShouldRedirectToFalseWhenSecureSiteURLIsNotSetAndSiteUrlIsNonHTTPS() throws URISyntaxException {
final ServerConfigService serverConfigService = mock(ServerConfigService.class);
when(serverConfigService.hasAnyUrlConfigured()).thenReturn(true);
when(serverConfigService.siteUrlFor("http://url:8153/go/admin?tab=oAuth", true)).thenReturn("http://url:8153/go/admin?tab=oAuth");
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()));
}
Aggregations