Skip to content

Commit

Permalink
[CALCITE-6280] Implemented review comment - Added the new method to f…
Browse files Browse the repository at this point in the history
…ew more Test classes.

Change-Id: I87ffd4decf520674f5791c2770533cf6d2dcf55f
  • Loading branch information
vaijosh committed Feb 26, 2024
1 parent ee21a7e commit bcfcfcf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,6 +86,30 @@ public class HttpServerCustomizerTest {
*/
private static class UnsupportedServer {
}

@Test
public void testServerVersionNotReturnedForUnauthorisedAccess() throws Exception {
ServerCustomizer<Server> mockCustomizer1 =
(ServerCustomizer<Server>) mock(ServerCustomizer.class);
ServerCustomizer<Server> mockCustomizer2 =
(ServerCustomizer<Server>) mock(ServerCustomizer.class);
Service service = new LocalService(mockMeta);
HttpServer server =
HttpServer.Builder.<Server>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

0 comments on commit bcfcfcf

Please sign in to comment.