Search in sources :

Example 6 with Http

use of com.yahoo.vespa.model.container.http.Http in project vespa by vespa-engine.

the class AccessControlTest method properties_are_set_from_xml.

@Test
public void properties_are_set_from_xml() throws Exception {
    Element clusterElem = DomBuilderTest.parse("  <http>", "    <filtering>", "      <access-control domain='my-domain'>", "        <application>my-app</application>", "        <vespa-domain>custom-vespa-domain</vespa-domain>", "      </access-control>", "    </filtering>", "  </http>");
    Http http = new HttpBuilder().build(root, clusterElem);
    root.freezeModelTopology();
    AccessControl accessControl = http.getAccessControl().get();
    assertEquals("Wrong domain.", "my-domain", accessControl.domain);
    assertEquals("Wrong application.", "my-app", accessControl.applicationId);
    assertEquals("Wrong vespa-domain.", "custom-vespa-domain", accessControl.vespaDomain.get());
}
Also used : Element(org.w3c.dom.Element) HttpBuilder(com.yahoo.vespa.model.container.http.xml.HttpBuilder) Http(com.yahoo.vespa.model.container.http.Http) AccessControl(com.yahoo.vespa.model.container.http.AccessControl) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 7 with Http

use of com.yahoo.vespa.model.container.http.Http in project vespa by vespa-engine.

the class AccessControlTest method access_control_filter_chain_has_all_servlet_bindings.

@Test
public void access_control_filter_chain_has_all_servlet_bindings() throws Exception {
    final String servletPath = "servlet/path";
    final String restApiPath = "api/v0";
    final Set<String> requiredBindings = ImmutableSet.of(servletPath, restApiPath);
    Element clusterElem = DomBuilderTest.parse("<jdisc version='1.0'>", "  <servlet id='foo' class='bar' bundle='baz'>", "    <path>" + servletPath + "</path>", "  </servlet>", "  <rest-api jersey2='true' path='" + restApiPath + "' />", "  <http>", "    <filtering>", "      <access-control domain='foo' />", "    </filtering>", "  </http>", "</jdisc>");
    Http http = getHttp(clusterElem);
    Set<String> missingRequiredBindings = requiredBindings.stream().filter(requiredBinding -> !containsBinding(http.getBindings(), requiredBinding)).collect(Collectors.toSet());
    assertTrue("Access control chain was not bound to: " + CollectionUtil.mkString(missingRequiredBindings, ", "), missingRequiredBindings.isEmpty());
}
Also used : StateHandler(com.yahoo.container.jdisc.state.StateHandler) ImmutableSet(com.google.common.collect.ImmutableSet) TestUtil(com.yahoo.config.model.test.TestUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) HttpBuilder(com.yahoo.vespa.model.container.http.xml.HttpBuilder) Collection(java.util.Collection) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Jersey2Servlet(com.yahoo.vespa.model.container.jersey.Jersey2Servlet) TestUtil.joinLines(com.yahoo.config.model.test.TestUtil.joinLines) HashSet(java.util.HashSet) Binding(com.yahoo.vespa.model.container.http.Http.Binding) ContainerCluster(com.yahoo.vespa.model.container.ContainerCluster) Element(org.w3c.dom.Element) Assert.assertFalse(org.junit.Assert.assertFalse) SAXException(org.xml.sax.SAXException) CollectionUtil(com.yahoo.collections.CollectionUtil) AccessControl(com.yahoo.vespa.model.container.http.AccessControl) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest) Http(com.yahoo.vespa.model.container.http.Http) Assert.assertEquals(org.junit.Assert.assertEquals) Element(org.w3c.dom.Element) Http(com.yahoo.vespa.model.container.http.Http) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 8 with Http

use of com.yahoo.vespa.model.container.http.Http in project vespa by vespa-engine.

the class AccessControlTest method handler_can_be_excluded_by_excluding_one_of_its_bindings.

@Test
public void handler_can_be_excluded_by_excluding_one_of_its_bindings() throws Exception {
    final String notExcludedBinding = "http://*/custom-handler/*";
    final String excludedBinding = "http://*/excluded/*";
    Element clusterElem = DomBuilderTest.parse("<jdisc version='1.0'>", httpWithExcludedBinding(excludedBinding), "  <handler id='custom.Handler'>", "    <binding>" + notExcludedBinding + "</binding>", "    <binding>" + excludedBinding + "</binding>", "  </handler>", "</jdisc>");
    Http http = getHttp(clusterElem);
    assertFalse("Excluded binding was not removed.", containsBinding(http.getBindings(), excludedBinding));
    assertFalse("Not all bindings of an excluded handler were removed.", containsBinding(http.getBindings(), notExcludedBinding));
}
Also used : Element(org.w3c.dom.Element) Http(com.yahoo.vespa.model.container.http.Http) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 9 with Http

use of com.yahoo.vespa.model.container.http.Http in project vespa by vespa-engine.

the class AccessControlTest method read_and_write_can_be_overridden.

@Test
public void read_and_write_can_be_overridden() throws Exception {
    Element clusterElem = DomBuilderTest.parse("  <http>", "    <filtering>", "      <access-control domain='foo' read='true' write='false'/>", "    </filtering>", "  </http>");
    Http http = new HttpBuilder().build(root, clusterElem);
    root.freezeModelTopology();
    assertTrue("Given read value not honoured.", http.getAccessControl().get().readEnabled);
    assertFalse("Given write value not honoured.", http.getAccessControl().get().writeEnabled);
}
Also used : Element(org.w3c.dom.Element) HttpBuilder(com.yahoo.vespa.model.container.http.xml.HttpBuilder) Http(com.yahoo.vespa.model.container.http.Http) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 10 with Http

use of com.yahoo.vespa.model.container.http.Http in project vespa by vespa-engine.

the class AccessControlTest method getHttp.

private Http getHttp(Element clusterElem) throws SAXException, IOException {
    createModel(root, clusterElem);
    ContainerCluster cluster = (ContainerCluster) root.getChildren().get("jdisc");
    Http http = cluster.getHttp();
    assertNotNull(http);
    return http;
}
Also used : ContainerCluster(com.yahoo.vespa.model.container.ContainerCluster) Http(com.yahoo.vespa.model.container.http.Http)

Aggregations

Http (com.yahoo.vespa.model.container.http.Http)11 Element (org.w3c.dom.Element)10 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)9 Test (org.junit.Test)9 HttpBuilder (com.yahoo.vespa.model.container.http.xml.HttpBuilder)6 AccessControl (com.yahoo.vespa.model.container.http.AccessControl)4 ContainerCluster (com.yahoo.vespa.model.container.ContainerCluster)3 Binding (com.yahoo.vespa.model.container.http.Http.Binding)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 CollectionUtil (com.yahoo.collections.CollectionUtil)2 TestUtil (com.yahoo.config.model.test.TestUtil)2 TestUtil.joinLines (com.yahoo.config.model.test.TestUtil.joinLines)2 StateHandler (com.yahoo.container.jdisc.state.StateHandler)2 Jersey2Servlet (com.yahoo.vespa.model.container.jersey.Jersey2Servlet)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Assert.assertEquals (org.junit.Assert.assertEquals)2