Search in sources :

Example 11 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_correct_handler_bindings.

@Test
public void access_control_filter_chain_has_correct_handler_bindings() throws Exception {
    Element clusterElem = DomBuilderTest.parse("<jdisc version='1.0'>", "  <search/>", "  <document-api/>", "  <handler id='custom.Handler'>", "    <binding>http://*/custom-handler/*</binding>", "  </handler>", "  <http>", "    <filtering>", "      <access-control domain='foo' />", "    </filtering>", "  </http>", "</jdisc>");
    Http http = getHttp(clusterElem);
    Set<String> foundRequiredBindings = REQUIRED_HANDLER_BINDINGS.stream().filter(requiredBinding -> containsBinding(http.getBindings(), requiredBinding)).collect(Collectors.toSet());
    Set<String> missingRequiredBindings = new HashSet<>(REQUIRED_HANDLER_BINDINGS);
    missingRequiredBindings.removeAll(foundRequiredBindings);
    assertTrue("Access control chain was not bound to: " + CollectionUtil.mkString(missingRequiredBindings, ", "), missingRequiredBindings.isEmpty());
    FORBIDDEN_HANDLER_BINDINGS.forEach(forbiddenBinding -> http.getBindings().forEach(binding -> assertFalse("Access control chain was bound to: " + binding.binding, binding.binding.contains(forbiddenBinding))));
}
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) HashSet(java.util.HashSet) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

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