diff --git a/server/src/test/java/org/apache/calcite/avatica/server/BasicAuthHttpServerTest.java b/server/src/test/java/org/apache/calcite/avatica/server/BasicAuthHttpServerTest.java index 69c5bf4b7..a88079dbc 100644 --- a/server/src/test/java/org/apache/calcite/avatica/server/BasicAuthHttpServerTest.java +++ b/server/src/test/java/org/apache/calcite/avatica/server/BasicAuthHttpServerTest.java @@ -26,11 +26,14 @@ import org.junit.BeforeClass; import org.junit.Test; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.Properties; import static org.hamcrest.core.StringContains.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; @@ -159,6 +162,15 @@ public class BasicAuthHttpServerTest extends HttpAuthBase { e.getMessage()); } } + + @Test + public void testServerVersionNotReturnedForUnauthorisedAccess() throws Exception { + URL httpServerUrl = new URL("http://localhost:" + server.getPort()); + HttpURLConnection conn = (HttpURLConnection) httpServerUrl.openConnection(); + conn.setRequestMethod("GET"); + assertEquals("Unauthorized response status code", 401, conn.getResponseCode()); + assertNull("Server information was not expected", conn.getHeaderField("server")); + } } // End BasicAuthHttpServerTest.java diff --git a/server/src/test/java/org/apache/calcite/avatica/server/DigestAuthHttpServerTest.java b/server/src/test/java/org/apache/calcite/avatica/server/DigestAuthHttpServerTest.java index 3a013bd32..7b911ccc5 100644 --- a/server/src/test/java/org/apache/calcite/avatica/server/DigestAuthHttpServerTest.java +++ b/server/src/test/java/org/apache/calcite/avatica/server/DigestAuthHttpServerTest.java @@ -26,11 +26,14 @@ import org.junit.BeforeClass; import org.junit.Test; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.Properties; import static org.hamcrest.core.StringContains.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; @@ -172,6 +175,14 @@ public class DigestAuthHttpServerTest extends HttpAuthBase { e.getMessage()); } } + @Test + public void testServerVersionNotReturnedForUnauthorisedAccess() throws Exception { + URL httpServerUrl = new URL("http://localhost:" + server.getPort()); + HttpURLConnection conn = (HttpURLConnection) httpServerUrl.openConnection(); + conn.setRequestMethod("GET"); + assertEquals("Unauthorized response status code", 401, conn.getResponseCode()); + assertNull("Server information was not expected", conn.getHeaderField("server")); + } } // End DigestAuthHttpServerTest.java diff --git a/server/src/test/java/org/apache/calcite/avatica/server/HttpServerCustomizerTest.java b/server/src/test/java/org/apache/calcite/avatica/server/HttpServerCustomizerTest.java index e0adbef79..9adea7929 100644 --- a/server/src/test/java/org/apache/calcite/avatica/server/HttpServerCustomizerTest.java +++ b/server/src/test/java/org/apache/calcite/avatica/server/HttpServerCustomizerTest.java @@ -26,10 +26,13 @@ import org.junit.Test; import org.junit.rules.ExpectedException; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import static org.junit.Assert.assertNull; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -83,6 +86,30 @@ public class HttpServerCustomizerTest { */ private static class UnsupportedServer { } + + @Test + public void testServerVersionNotReturnedForUnauthorisedAccess() throws Exception { + ServerCustomizer mockCustomizer1 = + (ServerCustomizer) mock(ServerCustomizer.class); + ServerCustomizer mockCustomizer2 = + (ServerCustomizer) mock(ServerCustomizer.class); + Service service = new LocalService(mockMeta); + HttpServer server = + HttpServer.Builder.newBuilder().withHandler(service, + Driver.Serialization.PROTOBUF) + .withServerCustomizers( + Arrays.asList(mockCustomizer1, mockCustomizer2), Server.class) + .withPort(0).build(); + try { + server.start(); + URL httpServerUrl = new URL("http://localhost:" + server.getPort()); + HttpURLConnection conn = (HttpURLConnection) httpServerUrl.openConnection(); + conn.setRequestMethod("GET"); + assertNull("Server information was not expected", conn.getHeaderField("server")); + } finally { + server.stop(); + } + } } // End HttpServerCustomizerTest.java