Search in sources :

Example 1 with ServerConfig

use of com.yahoo.jdisc.http.ServerConfig in project vespa by vespa-engine.

the class FilterBindingsProviderTest method requireThatConfigWithUnknownReferenceFails.

@Test
public void requireThatConfigWithUnknownReferenceFails() {
    // Set up config.
    configBuilder.filter(new ServerConfig.Filter.Builder().id("someFilter").binding("http://*/*"));
    // Set up registry.
    final FilterChainRepository filterChainRepository = new FilterChainRepository(new ChainsConfig(new ChainsConfig.Builder()), new ComponentRegistry<>(), new ComponentRegistry<>(), new ComponentRegistry<>(), new ComponentRegistry<>());
    try {
        new FilterBindingsProvider(new ComponentId("foo"), new ServerConfig(configBuilder), filterChainRepository, new ComponentRegistry<>());
        fail("Config with unknown filter reference should not be accepted");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString("Invalid config"));
    }
}
Also used : ServerConfig(com.yahoo.jdisc.http.ServerConfig) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) SecurityResponseFilter(com.yahoo.jdisc.http.filter.SecurityResponseFilter) ChainsConfig(com.yahoo.container.core.ChainsConfig) FilterChainRepository(com.yahoo.container.http.filter.FilterChainRepository) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 2 with ServerConfig

use of com.yahoo.jdisc.http.ServerConfig in project vespa by vespa-engine.

the class FilterBindingsTest method bindings_are_added_to_config_for_all_http_servers_with_jetty.

@Test
public void bindings_are_added_to_config_for_all_http_servers_with_jetty() throws Exception {
    final Element xml = parse("<jdisc version='1.0' jetty='true'>", "  <http>", "    <filtering>", "      <request-chain id='my-request-chain'>", "        <binding>" + MY_CHAIN_BINDING + "</binding>", "      </request-chain>", "    </filtering>", "    <server id='server1' port='8000' />", "    <server id='server2' port='9000' />", "  </http>", "</jdisc>");
    buildContainerCluster(xml);
    {
        final ServerConfig config = root.getConfig(ServerConfig.class, "jdisc/http/jdisc-jetty/server1");
        assertThat(config.filter().size(), is(1));
        assertThat(config.filter(0).id(), is("my-request-chain"));
        assertThat(config.filter(0).binding(), is(MY_CHAIN_BINDING));
    }
    {
        final ServerConfig config = root.getConfig(ServerConfig.class, "jdisc/http/jdisc-jetty/server2");
        assertThat(config.filter().size(), is(1));
        assertThat(config.filter(0).id(), is("my-request-chain"));
        assertThat(config.filter(0).binding(), is(MY_CHAIN_BINDING));
    }
}
Also used : HttpServerConfig(com.yahoo.container.jdisc.config.HttpServerConfig) ServerConfig(com.yahoo.jdisc.http.ServerConfig) Element(org.w3c.dom.Element) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 3 with ServerConfig

use of com.yahoo.jdisc.http.ServerConfig in project vespa by vespa-engine.

the class FilterBindingsProviderTest method requireThatCorrectlyConfiguredFiltersAreIncluded.

@Test
public void requireThatCorrectlyConfiguredFiltersAreIncluded() {
    final String requestFilter1Id = "requestFilter1";
    final String requestFilter2Id = "requestFilter2";
    final String requestFilter3Id = "requestFilter3";
    final String responseFilter1Id = "responseFilter1";
    final String responseFilter2Id = "responseFilter2";
    final String responseFilter3Id = "responseFilter3";
    // Set up config.
    configBuilder.filter(new ServerConfig.Filter.Builder().id(requestFilter1Id).binding("http://*/a"));
    configBuilder.filter(new ServerConfig.Filter.Builder().id(requestFilter2Id).binding("http://*/b"));
    configBuilder.filter(new ServerConfig.Filter.Builder().id(responseFilter1Id).binding("http://*/c"));
    configBuilder.filter(new ServerConfig.Filter.Builder().id(responseFilter3Id).binding("http://*/d"));
    // Set up registry.
    final ComponentRegistry<RequestFilter> availableRequestFilters = new ComponentRegistry<>();
    final RequestFilter requestFilter1Instance = mock(RequestFilter.class);
    final RequestFilter requestFilter2Instance = mock(RequestFilter.class);
    final RequestFilter requestFilter3Instance = mock(RequestFilter.class);
    availableRequestFilters.register(ComponentId.fromString(requestFilter1Id), requestFilter1Instance);
    availableRequestFilters.register(ComponentId.fromString(requestFilter2Id), requestFilter2Instance);
    availableRequestFilters.register(ComponentId.fromString(requestFilter3Id), requestFilter3Instance);
    final ComponentRegistry<ResponseFilter> availableResponseFilters = new ComponentRegistry<>();
    final ResponseFilter responseFilter1Instance = mock(ResponseFilter.class);
    final ResponseFilter responseFilter2Instance = mock(ResponseFilter.class);
    final ResponseFilter responseFilter3Instance = mock(ResponseFilter.class);
    availableResponseFilters.register(ComponentId.fromString(responseFilter1Id), responseFilter1Instance);
    availableResponseFilters.register(ComponentId.fromString(responseFilter2Id), responseFilter2Instance);
    availableResponseFilters.register(ComponentId.fromString(responseFilter3Id), responseFilter3Instance);
    final FilterChainRepository filterChainRepository = new FilterChainRepository(new ChainsConfig(new ChainsConfig.Builder()), availableRequestFilters, availableResponseFilters, new ComponentRegistry<SecurityRequestFilter>(), new ComponentRegistry<SecurityResponseFilter>());
    // Set up the provider that we aim to test.
    final FilterBindingsProvider provider = new FilterBindingsProvider(new ComponentId("foo"), new ServerConfig(configBuilder), filterChainRepository, new ComponentRegistry<SecurityRequestFilter>());
    // Execute.
    final FilterBindings filterBindings = provider.get();
    // Verify.
    assertThat(filterBindings, is(not(nullValue())));
    assertThat(filterBindings.getRequestFilters(), containsFilters(requestFilter1Instance, requestFilter2Instance));
    assertThat(filterBindings.getRequestFilters(), not(containsFilters(requestFilter3Instance)));
    assertThat(filterBindings.getResponseFilters(), containsFilters(responseFilter1Instance, responseFilter3Instance));
    assertThat(filterBindings.getResponseFilters(), not(containsFilters(responseFilter2Instance)));
}
Also used : SecurityResponseFilter(com.yahoo.jdisc.http.filter.SecurityResponseFilter) ChainsConfig(com.yahoo.container.core.ChainsConfig) FilterBindings(com.yahoo.jdisc.http.server.FilterBindings) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServerConfig(com.yahoo.jdisc.http.ServerConfig) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) SecurityResponseFilter(com.yahoo.jdisc.http.filter.SecurityResponseFilter) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) SecurityResponseFilter(com.yahoo.jdisc.http.filter.SecurityResponseFilter) FilterChainRepository(com.yahoo.container.http.filter.FilterChainRepository) ComponentId(com.yahoo.component.ComponentId) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) Test(org.junit.Test)

Example 4 with ServerConfig

use of com.yahoo.jdisc.http.ServerConfig in project vespa by vespa-engine.

the class FilterBindingsProviderTest method requireThatEmptyInputGivesEmptyOutput.

@Test
public void requireThatEmptyInputGivesEmptyOutput() {
    final FilterChainRepository filterChainRepository = new FilterChainRepository(new ChainsConfig(new ChainsConfig.Builder()), new ComponentRegistry<>(), new ComponentRegistry<>(), new ComponentRegistry<>(), new ComponentRegistry<>());
    final FilterBindingsProvider provider = new FilterBindingsProvider(new ComponentId("foo"), new ServerConfig(configBuilder), filterChainRepository, new ComponentRegistry<>());
    final FilterBindings filterBindings = provider.get();
    assertThat(filterBindings, is(not(nullValue())));
    assertThat(filterBindings.getRequestFilters().iterator().hasNext(), is(false));
    assertThat(filterBindings.getResponseFilters().iterator().hasNext(), is(false));
}
Also used : ServerConfig(com.yahoo.jdisc.http.ServerConfig) ChainsConfig(com.yahoo.container.core.ChainsConfig) FilterBindings(com.yahoo.jdisc.http.server.FilterBindings) FilterChainRepository(com.yahoo.container.http.filter.FilterChainRepository) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 5 with ServerConfig

use of com.yahoo.jdisc.http.ServerConfig in project vespa by vespa-engine.

the class FilterBindingsProviderTest method requireThatInstanceCanNotBeBothRequestAndResponseFilter.

@Test
public void requireThatInstanceCanNotBeBothRequestAndResponseFilter() {
    final String filterId = "filter";
    // Set up config.
    configBuilder.filter(new ServerConfig.Filter.Builder().id(filterId).binding("http://*/*"));
    // Set up registry.
    final DualRoleFilter filterInstance = mock(DualRoleFilter.class);
    final ComponentRegistry<RequestFilter> availableRequestFilters = new ComponentRegistry<>();
    availableRequestFilters.register(ComponentId.fromString(filterId), filterInstance);
    final FilterChainRepository filterChainRepository = new FilterChainRepository(new ChainsConfig(new ChainsConfig.Builder()), availableRequestFilters, new ComponentRegistry<>(), new ComponentRegistry<>(), new ComponentRegistry<>());
    try {
        new FilterBindingsProvider(new ComponentId("foo"), new ServerConfig(configBuilder), filterChainRepository, new ComponentRegistry<>());
        fail("Dual-role filter should not be accepted");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString("Invalid config"));
    }
}
Also used : ChainsConfig(com.yahoo.container.core.ChainsConfig) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServerConfig(com.yahoo.jdisc.http.ServerConfig) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) SecurityResponseFilter(com.yahoo.jdisc.http.filter.SecurityResponseFilter) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) FilterChainRepository(com.yahoo.container.http.filter.FilterChainRepository) ComponentId(com.yahoo.component.ComponentId) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) Test(org.junit.Test)

Aggregations

ServerConfig (com.yahoo.jdisc.http.ServerConfig)5 Test (org.junit.Test)5 ComponentId (com.yahoo.component.ComponentId)4 ChainsConfig (com.yahoo.container.core.ChainsConfig)4 FilterChainRepository (com.yahoo.container.http.filter.FilterChainRepository)4 RequestFilter (com.yahoo.jdisc.http.filter.RequestFilter)3 ResponseFilter (com.yahoo.jdisc.http.filter.ResponseFilter)3 SecurityRequestFilter (com.yahoo.jdisc.http.filter.SecurityRequestFilter)3 SecurityResponseFilter (com.yahoo.jdisc.http.filter.SecurityResponseFilter)3 ComponentRegistry (com.yahoo.component.provider.ComponentRegistry)2 FilterBindings (com.yahoo.jdisc.http.server.FilterBindings)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)1 HttpServerConfig (com.yahoo.container.jdisc.config.HttpServerConfig)1 Element (org.w3c.dom.Element)1