summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java
diff options
context:
space:
mode:
authorMorten Tokle <mortent@verizonmedia.com>2021-02-19 09:10:27 +0100
committerMorten Tokle <mortent@verizonmedia.com>2021-02-19 09:10:27 +0100
commit356332d05693f6109e4a5ece8a63a0190f1cdaa0 (patch)
tree65bcd79bd65ec035543e6c7be307fee227d03d02 /config-model/src/test/java
parent0be286e9026e96f8a1b032a2f2a08e943cf771ec (diff)
Configure filter correctly when no endpoints given
Diffstat (limited to 'config-model/src/test/java')
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/http/BlockFeedGlobalEndpointsFilterTest.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/http/BlockFeedGlobalEndpointsFilterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/http/BlockFeedGlobalEndpointsFilterTest.java
new file mode 100644
index 00000000000..deca2fda21c
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/http/BlockFeedGlobalEndpointsFilterTest.java
@@ -0,0 +1,43 @@
+// Copyright Verizon Media. 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.api.ContainerEndpoint;
+import com.yahoo.jdisc.http.filter.security.rule.RuleBasedFilterConfig;
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+public class BlockFeedGlobalEndpointsFilterTest {
+
+ @Test
+ public void setup_blocking_rule_when_endpoints_is_non_empty() {
+ var endpoints = Set.of(new ContainerEndpoint("default", List.of("foo", "bar")));
+ var filter = new BlockFeedGlobalEndpointsFilter(endpoints, true);
+ var config = getConfig(filter);
+ assertEquals(1, config.rule().size());
+ var rule = config.rule().get(0);
+ assertThat(rule.hostNames(), Matchers.containsInAnyOrder("foo", "bar"));
+ assertEquals(rule.action(), RuleBasedFilterConfig.Rule.Action.Enum.BLOCK);
+ }
+
+ @Test
+ public void does_not_setup_blocking_rule_when_endpoints_empty() {
+ var filter = new BlockFeedGlobalEndpointsFilter(Collections.emptySet(), true);
+ var config = getConfig(filter);
+ assertEquals(0, config.rule().size());
+ }
+
+ private RuleBasedFilterConfig getConfig(BlockFeedGlobalEndpointsFilter filter) {
+ var configBuilder = new RuleBasedFilterConfig.Builder();
+ filter.getConfig(configBuilder);
+ return configBuilder.build();
+ }
+}