Search in sources :

Example 1 with ServerConfigService

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"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConfigService(com.thoughtworks.go.server.service.ServerConfigService) HttpInput(org.eclipse.jetty.server.HttpInput) Request(org.eclipse.jetty.server.Request) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpChannel(org.eclipse.jetty.server.HttpChannel) HttpURI(org.eclipse.jetty.http.HttpURI) Test(org.junit.Test)

Example 2 with ServerConfigService

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()));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConfigService(com.thoughtworks.go.server.service.ServerConfigService) HttpInput(org.eclipse.jetty.server.HttpInput) Request(org.eclipse.jetty.server.Request) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpChannel(org.eclipse.jetty.server.HttpChannel) HttpURI(org.eclipse.jetty.http.HttpURI) Test(org.junit.Test)

Example 3 with ServerConfigService

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()));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConfigService(com.thoughtworks.go.server.service.ServerConfigService) HttpInput(org.eclipse.jetty.server.HttpInput) Request(org.eclipse.jetty.server.Request) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpChannel(org.eclipse.jetty.server.HttpChannel) HttpURI(org.eclipse.jetty.http.HttpURI) Test(org.junit.Test)

Aggregations

ServerConfigService (com.thoughtworks.go.server.service.ServerConfigService)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpURI (org.eclipse.jetty.http.HttpURI)3 HttpChannel (org.eclipse.jetty.server.HttpChannel)3 HttpInput (org.eclipse.jetty.server.HttpInput)3 Request (org.eclipse.jetty.server.Request)3 Test (org.junit.Test)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3