diff options
Diffstat (limited to 'jdisc_http_service/src/test/java/com')
6 files changed, 14 insertions, 80 deletions
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/CookieTestCase.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/CookieTestCase.java index dab4f91f631..4c651f79666 100644 --- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/CookieTestCase.java +++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/CookieTestCase.java @@ -131,7 +131,6 @@ public class CookieTestCase { } @Test - @SuppressWarnings("deprecation") public void requireThatSetCookieCanBeDecoded() { final Cookie foo = new Cookie(); foo.setName("foo.name"); @@ -141,7 +140,6 @@ public class CookieTestCase { foo.setMaxAge(0, TimeUnit.SECONDS); foo.setSecure(true); foo.setHttpOnly(true); - foo.setVersion(1); assertDecodeSetCookie(foo, "foo.name=foo.value;Max-Age=0;Path=path;Domain=domain;Secure;HTTPOnly;"); final Cookie bar = new Cookie(); @@ -150,7 +148,6 @@ public class CookieTestCase { bar.setPath("path"); bar.setDomain("domain"); bar.setMaxAge(0, TimeUnit.SECONDS); - bar.setVersion(1); assertDecodeSetCookie(bar, "bar.name=bar.value;Max-Age=0;Path=path;Domain=domain;"); } @@ -193,11 +190,13 @@ public class CookieTestCase { } private static void assertEncodeCookie(String expectedResult, List<Cookie> cookies) { - assertThat(Cookie.toCookieHeader(cookies), equalTo(expectedResult)); + String actual = Cookie.toCookieHeader(cookies); + String expectedResult1 = expectedResult; + assertThat(actual, equalTo(expectedResult1)); } private static void assertEncodeSetCookie(List<String> expectedResult, List<Cookie> cookies) { - assertThat(Cookie.toSetCookieHeaderAll(cookies), containsInAnyOrder(expectedResult.toArray())); + assertThat(Cookie.toSetCookieHeaders(cookies), containsInAnyOrder(expectedResult.toArray())); } private static void assertDecodeCookie(List<Cookie> expected, String toDecode) { @@ -205,7 +204,7 @@ public class CookieTestCase { } private static void assertDecodeSetCookie(final Cookie expected, String toDecode) { - assertThat(Cookie.fromSetCookieHeader(toDecode), containsInAnyOrder(expected)); + assertThat(Cookie.fromSetCookieHeader(toDecode), equalTo(expected)); } private static Cookie newCookie(final String name) { diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/HttpResponseTestCase.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/HttpResponseTestCase.java index 027d50317b2..d727be020cb 100644 --- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/HttpResponseTestCase.java +++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/HttpResponseTestCase.java @@ -92,7 +92,7 @@ public class HttpResponseTestCase { response.encodeSetCookieHeader(cookies); final List<String> headers = response.headers().get(HttpHeaders.Names.SET_COOKIE); assertEquals(1, headers.size()); - assertEquals(Cookie.toSetCookieHeaderAll(cookies), headers); + assertEquals(Cookie.toSetCookieHeaders(cookies), headers); } @Test @@ -102,7 +102,7 @@ public class HttpResponseTestCase { response.encodeSetCookieHeader(cookies); final List<String> headers = response.headers().get(HttpHeaders.Names.SET_COOKIE); assertEquals(2, headers.size()); - assertEquals(Cookie.toSetCookieHeaderAll(Arrays.asList(new Cookie("foo", "bar"), new Cookie("baz", "cox"))), + assertEquals(Cookie.toSetCookieHeaders(Arrays.asList(new Cookie("foo", "bar"), new Cookie("baz", "cox"))), headers); } diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/filter/JDiscCookieWrapperTest.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/filter/JDiscCookieWrapperTest.java index 3439dc172ee..86ca424c90e 100644 --- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/filter/JDiscCookieWrapperTest.java +++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/filter/JDiscCookieWrapperTest.java @@ -7,7 +7,6 @@ import org.testng.annotations.Test; import java.util.concurrent.TimeUnit; -@SuppressWarnings("deprecation") public class JDiscCookieWrapperTest { @Test @@ -15,19 +14,15 @@ public class JDiscCookieWrapperTest { Cookie cookie = new Cookie("name", "value"); JDiscCookieWrapper wrapper = JDiscCookieWrapper.wrap(cookie); - wrapper.setComment("comment"); wrapper.setDomain("yahoo.com"); wrapper.setMaxAge(10); wrapper.setPath("/path"); - wrapper.setVersion(1); Assert.assertEquals(wrapper.getName(), cookie.getName()); Assert.assertEquals(wrapper.getValue(), cookie.getValue()); Assert.assertEquals(wrapper.getDomain(), cookie.getDomain()); - Assert.assertEquals(wrapper.getComment(), cookie.getComment()); Assert.assertEquals(wrapper.getMaxAge(), cookie.getMaxAge(TimeUnit.SECONDS)); Assert.assertEquals(wrapper.getPath(), cookie.getPath()); - Assert.assertEquals(wrapper.getVersion(), cookie.getVersion()); Assert.assertEquals(wrapper.getSecure(), cookie.isSecure()); } diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/AccessLogRequestLogTest.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/AccessLogRequestLogTest.java index 1048d7b6422..d5043f7b989 100644 --- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/AccessLogRequestLogTest.java +++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/AccessLogRequestLogTest.java @@ -15,11 +15,12 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.testng.Assert.assertTrue; /** - * @author bakksjo + * @author Oyvind Bakksjo + * @author bjorncs */ -@SuppressWarnings("deprecation") // AccessLogEntry.setURI/getURI are deprecated public class AccessLogRequestLogTest { @Test public void requireThatQueryWithUnquotedSpecialCharactersIsHandled() { @@ -30,7 +31,8 @@ public class AccessLogRequestLogTest { AccessLogRequestLog.populateAccessLogEntryFromHttpServletRequest(httpServletRequest, accessLogEntry); - assertThat(accessLogEntry.getURI(), is(not(nullValue()))); + assertThat(accessLogEntry.getRawPath(), is(not(nullValue()))); + assertTrue(accessLogEntry.getRawQuery().isPresent()); } @Test @@ -44,37 +46,12 @@ public class AccessLogRequestLogTest { AccessLogRequestLog.populateAccessLogEntryFromHttpServletRequest(httpServletRequest, accessLogEntry); - assertThat(accessLogEntry.getURI().toString(), is(path + '?' + query)); + assertThat(accessLogEntry.getRawPath(), is(path)); + assertThat(accessLogEntry.getRawQuery().get(), is(query)); } @Test - public void requireThatNoQueryPartIsHandledWhenRequestIsMalformed() { - final HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); - final String path = "/s>earch/"; - when(httpServletRequest.getRequestURI()).thenReturn(path); - final String query = null; - when(httpServletRequest.getQueryString()).thenReturn(query); - final AccessLogEntry accessLogEntry = new AccessLogEntry(); - - AccessLogRequestLog.populateAccessLogEntryFromHttpServletRequest(httpServletRequest, accessLogEntry); - - assertThat(accessLogEntry.getURI().toString(), is("/s%3Eearch/")); - - } - - @Test - public void invalid_percent_escape_patterns_in_query_string_are_escaped() { - HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); - when(httpServletRequest.getRequestURI()).thenReturn("/search/"); - when(httpServletRequest.getQueryString()).thenReturn("q=%%2"); - - AccessLogEntry accessLogEntry = new AccessLogEntry(); - AccessLogRequestLog.populateAccessLogEntryFromHttpServletRequest(httpServletRequest, accessLogEntry); - assertThat(accessLogEntry.getURI().toString(), is("/search/?q=%25%252")); - } - - @Test public void raw_path_and_query_are_set_from_request() { HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); String rawPath = "//search/"; diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java index eb18a3ee341..cf32801ce88 100644 --- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java +++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java @@ -17,9 +17,6 @@ import java.net.InetSocketAddress; import java.nio.channels.ServerSocketChannel; import java.util.Map; -import static com.yahoo.jdisc.http.ConnectorConfig.Ssl; -import static com.yahoo.jdisc.http.ConnectorConfig.Ssl.KeyStoreType.Enum.JKS; -import static com.yahoo.jdisc.http.ConnectorConfig.Ssl.KeyStoreType.Enum.PEM; import static org.hamcrest.CoreMatchers.equalTo; /** @@ -27,30 +24,6 @@ import static org.hamcrest.CoreMatchers.equalTo; */ public class ConnectorFactoryTest { - @Test(expectedExceptions = IllegalArgumentException.class) - public void ssl_jks_config_is_validated() { - ConnectorConfig config = new ConnectorConfig( - new ConnectorConfig.Builder() - .ssl(new Ssl.Builder() - .enabled(true) - .keyStoreType(JKS) - .pemKeyStore( - new Ssl.PemKeyStore.Builder() - .keyPath("nonEmpty")))); - ConnectorFactory willThrowException = createConnectorFactory(config); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void ssl_pem_config_is_validated() { - ConnectorConfig config = new ConnectorConfig( - new ConnectorConfig.Builder() - .ssl(new Ssl.Builder() - .enabled(true) - .keyStoreType(PEM) - .keyStorePath("nonEmpty"))); - ConnectorFactory willThrowException = createConnectorFactory(config); - } - @Test public void requireThatNoPreBoundChannelWorks() throws Exception { Server server = new Server(); diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpRequestFactoryTest.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpRequestFactoryTest.java index a15bf4c117a..6a2e35b617c 100644 --- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpRequestFactoryTest.java +++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpRequestFactoryTest.java @@ -492,16 +492,6 @@ public class HttpRequestFactoryTest { } @Test - public final void test() { - String noise = "query=a" + "\\" + "^{|}&other=madeit"; - HttpServletRequest servletRequest = new MockRequest( - "http://yahoo.com/search?" + noise); - HttpRequest request = HttpRequestFactory.newJDiscRequest( - new MockContainer(), servletRequest); - assertThat(request.getUri().getQuery(), equalTo(noise)); - } - - @Test public final void testIllegalQuery() { try { HttpRequestFactory.newJDiscRequest( |