From 133a4a10c036c6fca597e96f696039ec63aca175 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 8 Mar 2019 14:42:32 -0600 Subject: [PATCH] Issue #3444 - Adding testcase for HttpFields.add(PreEncoded|HttpField) Signed-off-by: Joakim Erdfelt --- .../eclipse/jetty/http/HttpFieldsTest.java | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java index 3ec1b84c454..dc6f4a9e6ec 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java @@ -18,15 +18,6 @@ package org.eclipse.jetty.http; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.nio.ByteBuffer; import java.util.Collections; import java.util.Enumeration; @@ -40,6 +31,15 @@ import org.eclipse.jetty.util.BufferUtil; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class HttpFieldsTest { @Test @@ -299,6 +299,28 @@ public class HttpFieldsTest assertEquals(false, e.hasMoreElements()); } + @Test + public void testAddPreEncodedField() + { + final PreEncodedHttpField X_XSS_PROTECTION_FIELD = new PreEncodedHttpField("X-XSS-Protection", "1; mode=block"); + + HttpFields fields = new HttpFields(); + fields.add(X_XSS_PROTECTION_FIELD); + + assertThat("Fields output", fields.toString(), containsString("X-XSS-Protection: 1; mode=block")); + } + + @Test + public void testAddFinalHttpField() + { + final HttpField X_XSS_PROTECTION_FIELD = new HttpField("X-XSS-Protection", "1; mode=block"); + + HttpFields fields = new HttpFields(); + fields.add(X_XSS_PROTECTION_FIELD); + + assertThat("Fields output", fields.toString(), containsString("X-XSS-Protection: 1; mode=block")); + } + @Test public void testGetValues() throws Exception {