test(gateway-engine): Header suppression and permission tests
MODIFY
gateway/engine/core/src/main/java/io/apiman/gateway/engine/IConnectorConfig.java
gateway/engine/core/src/main/java/io/apiman/gateway/engine/IConnectorConfig.java
@@ -53,14 +53,18 @@ public interface IConnectorConfig {
void permitResponseHeader(String headerName);
/**
- * Unmodifiable request headers.
+ * <em>Unmodifiable</em> request headers.
+ *
+ * Use permit and suppress methods to mutate.
*
* @return the suppressed request headers
*/
Set<String> getSuppressedRequestHeaders();
/**
- * Unmodifiable response headers.
+ * <em>Unmodifiable</em> response headers.
+ *
+ * Use permit and suppress methods to mutate.
*
* @return the suppressed response headers
*/

MODIFY
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/AbstractConnectorConfig.java
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/AbstractConnectorConfig.java
@@ -34,21 +34,11 @@ import java.util.TreeSet;
*/
public abstract class AbstractConnectorConfig implements IConnectorConfig {
- Set<String> suppressedRequestHeaders;
- boolean modifiedDefaultRequestHeaders = false;
-
- Set<String> suppressedResponseHeaders;
- boolean modifiedDefaultResponseHeaders = false;
-
-// TODO: cache common request and response suppression maps. Some quick and dirty way of looking it up?
-// static LRUMap<String, Set<String>> cache = new LRUMap<String, Set<String>>(1000) {
-// private static final long serialVersionUID = -18620070710843930L;
-//
-// @Override
-// protected void handleRemovedElem(java.util.Map.Entry<String, Set<String>> eldest) {
-// // Don't need to do anything.
-// }
-// };
+ protected Set<String> suppressedRequestHeaders;
+ private boolean modifiedDefaultRequestHeaders = false;
+
+ protected Set<String> suppressedResponseHeaders;
+ private boolean modifiedDefaultResponseHeaders = false;
/**
* Suppressed request headers
@@ -63,7 +53,7 @@ public abstract class AbstractConnectorConfig implements IConnectorConfig {
}
/**
- * Construct no suppressed request nor response headers.
+ * No suppressed request nor response headers.
*/
public AbstractConnectorConfig() {
this.suppressedRequestHeaders = Collections.emptySet();

ADD
gateway/engine/core/src/test/java/io/apiman/gateway/engine/impl/AbstractConnectorConfigTest.java
+/*
+ * Copyright 2018 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.apiman.gateway.engine.impl;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Marc Savy {@literal <marc@rhymewithgravy.com>}
+ */
+@SuppressWarnings("nls")
+public class AbstractConnectorConfigTest {
+
+ static final Set<String> REQUEST = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+ static final Set<String> RESPONSE = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+
+ static {
+ REQUEST.add("Transfer-Encoding");
+ REQUEST.add("X-API-Key");
+ REQUEST.add("Host");
+
+ RESPONSE.add("Transfer-Encoding");
+ RESPONSE.add("Connection");
+ }
+
+ @Test
+ public void shouldContainInitialHeaders() {
+ AbstractConnectorConfig connector = new AbstractConnectorConfig(REQUEST, RESPONSE) {};
+ Assert.assertTrue(connector.getSuppressedResponseHeaders().containsAll(RESPONSE));
+ }
+
+ @Test
+ public void shouldEvaluateKeysCaseInsensitively() {
+ AbstractConnectorConfig connector = new AbstractConnectorConfig(REQUEST, RESPONSE) {};
+ Assert.assertTrue("Must compare case insensitively", connector.getSuppressedRequestHeaders().contains("x-api-key"));
+ }
+
+ @Test
+ public void addSuppressedRequestHeader() {
+ AbstractConnectorConfig connector = new AbstractConnectorConfig(REQUEST, RESPONSE) {};
+ connector.suppressRequestHeader("Seychelles");
+ Assert.assertTrue("Must contain suppressed header added by user", connector.getSuppressedRequestHeaders().contains("seychelles"));
+ }
+
+ @Test
+ public void permitRequestHeader() {
+ AbstractConnectorConfig connector = new AbstractConnectorConfig(REQUEST, RESPONSE) {};
+ connector.permitRequestHeader("Host");
+ Assert.assertFalse("Must unsuppress header", connector.getSuppressedRequestHeaders().contains("Host"));
+ }
+
+ @Test
+ public void addSuppressedResponseHeader() {
+ AbstractConnectorConfig connector = new AbstractConnectorConfig(REQUEST, RESPONSE) {};
+ connector.suppressResponseHeader("Aldabra");
+ Assert.assertTrue("Must contain suppressed header added by user", connector.getSuppressedResponseHeaders().contains("Aldabra"));
+ }
+
+ @Test
+ public void permitResponseHeader() {
+ AbstractConnectorConfig connector = new AbstractConnectorConfig(REQUEST, RESPONSE) {};
+ connector.permitResponseHeader("Host");
+ Assert.assertFalse("Must unsuppress header", connector.getSuppressedResponseHeaders().contains("Host"));
+ }
+
+}

MODIFY
test/policies/src/main/java/io/apiman/test/policies/PolicyTesterConnectorConfig.java
test/policies/src/main/java/io/apiman/test/policies/PolicyTesterConnectorConfig.java
@@ -21,6 +21,11 @@ import io.apiman.gateway.engine.impl.AbstractConnectorConfig;
import java.util.Set;
import java.util.TreeSet;
+/**
+ * Test connector config
+ *
+ * @author Marc Savy {@literal <marc@rhymewithgravy.com>}
+ */
@SuppressWarnings("nls")
public class PolicyTesterConnectorConfig extends AbstractConnectorConfig {
static final Set<String> REQUEST = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);

test(gateway-engine): Header suppression and permission tests

Signed-off-by: Marc Savy <marc@rhymewithgravy.com>