aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/container/http/StrictFilteringTest.java
blob: effbb4d6fe1e3e7ca742688c43949e179fc30cbe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.http;

import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.jdisc.http.ServerConfig;
import com.yahoo.vespa.model.container.xml.ContainerModelBuilder;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author bjorncs
 */
public class StrictFilteringTest extends DomBuilderTest {

    @Test
    void strict_filtering_enabled_if_specified_in_services() {
        Element xml = parse(
                "<container version='1.0'>",
                "  <http>",
                "    <filtering strict-mode='true'>",
                "      <request-chain id='request-chain-with-binding'>",
                "        <filter id='my-filter' class='MyFilter'/>",
                "        <binding>http://*/my-chain-binding</binding>",
                "      </request-chain>",
                "    </filtering>",
                "    <server id='server1' port='8000' />",
                "  </http>",
                "</container>");
        assertStrictFiltering(true, xml);
    }

    @Test
    void strict_filtering_enabled_by_default_if_filter_present() {
        Element xml = parse(
                "<container version='1.0'>",
                "  <http>",
                "    <filtering>",
                "      <request-chain id='request-chain'>",
                "        <filter id='my-filter' class='MyFilter'/>",
                "      </request-chain>",
                "    </filtering>",
                "    <server id='server1' port='8000' />",
                "  </http>",
                "</container>");
        assertStrictFiltering(true, xml);
    }

    @Test
    void strict_filtering_disabled_if_no_filter() {
        Element xml = parse(
                "<container version='1.0'>",
                "  <http>",
                "    <filtering>",
                "    </filtering>",
                "    <server id='server1' port='8000' />",
                "  </http>",
                "</container>");
        assertStrictFiltering(false, xml);
    }

    private void assertStrictFiltering(boolean expected, Element services) {
        buildContainerCluster(services);
        ServerConfig config = root.getConfig(ServerConfig.class, "container/http/jdisc-jetty/server1");
        assertEquals(expected, config.strictFiltering());
    }

    private void buildContainerCluster(Element containerElem) {
        new ContainerModelBuilder(true, ContainerModelBuilder.Networking.enable).build(DeployState.createTestState(), null, null, root, containerElem);
        root.freezeModelTopology();
    }
}