diff --git a/common/src/java/org/apache/hive/http/HttpServer.java b/common/src/java/org/apache/hive/http/HttpServer.java index 9ceaf3f..0eb5fa9 100644 --- a/common/src/java/org/apache/hive/http/HttpServer.java +++ b/common/src/java/org/apache/hive/http/HttpServer.java @@ -130,9 +130,10 @@ public HttpServer build() throws IOException { return new HttpServer(this); } - public Builder setConf(HiveConf conf) { + public Builder setConf(HiveConf origConf) { + this.conf = new HiveConf(origConf); + origConf.stripHiddenConfigurations(conf); setContextAttribute(CONF_CONTEXT_ATTRIBUTE, conf); - this.conf = conf; return this; } diff --git a/service/src/java/org/apache/hive/service/server/HiveServer2.java b/service/src/java/org/apache/hive/service/server/HiveServer2.java index 14e1e0d..0ecaa76 100644 --- a/service/src/java/org/apache/hive/service/server/HiveServer2.java +++ b/service/src/java/org/apache/hive/service/server/HiveServer2.java @@ -145,14 +145,19 @@ public void run() { } // Setup web UI try { - if (hiveConf.getBoolVar(ConfVars.HIVE_IN_TEST)) { - LOG.info("Web UI is disabled since in test mode"); - } else { - int webUIPort = + int webUIPort = hiveConf.getIntVar(ConfVars.HIVE_SERVER2_WEBUI_PORT); + // We disable web UI in tests unless the test is explicitly setting a + // unique web ui port so that we don't mess up ptests. + boolean uiDisabledInTest = hiveConf.getBoolVar(ConfVars.HIVE_IN_TEST) && + (webUIPort == Integer.valueOf(ConfVars.HIVE_SERVER2_WEBUI_PORT.getDefaultValue())); + if (uiDisabledInTest) { + LOG.info("Web UI is disabled in test mode since webui port was not specified"); + } else { if (webUIPort <= 0) { LOG.info("Web UI is disabled since port is set to " + webUIPort); } else { + LOG.info("Starting Web UI on port "+ webUIPort); HttpServer.Builder builder = new HttpServer.Builder("hiveserver2"); builder.setPort(webUIPort).setConf(hiveConf); builder.setHost(hiveConf.getVar(ConfVars.HIVE_SERVER2_WEBUI_BIND_HOST)); diff --git a/service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java b/service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java index c06ea26..451c259 100644 --- a/service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java +++ b/service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java @@ -25,22 +25,38 @@ import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; +import org.apache.hadoop.hive.metastore.MetaStoreUtils; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + /** * TestHS2HttpServer -- executes tests of HiveServer2 HTTP Server */ public class TestHS2HttpServer { private static HiveServer2 hiveServer2 = null; + private static HiveConf hiveConf = null; + private static String metastorePasswd = "61ecbc41cdae3e6b32712a06c73606fa"; //random md5 + private static Integer webUIPort = null; @BeforeClass public static void beforeTests() throws Exception { - HiveConf hiveConf = new HiveConf(); - hiveConf.setBoolVar(ConfVars.HIVE_IN_TEST, false); + webUIPort = MetaStoreUtils.findFreePort(); + hiveConf = new HiveConf(); + hiveConf.set(ConfVars.METASTOREPWD.varname, metastorePasswd); + hiveConf.set(ConfVars.HIVE_SERVER2_WEBUI_PORT.varname, webUIPort.toString()); hiveServer2 = new HiveServer2(); hiveServer2.init(hiveConf); hiveServer2.start(); @@ -48,9 +64,8 @@ public static void beforeTests() throws Exception { } @Test - public void testStackServket() throws Exception { - String baseURL = "http://localhost:" - + ConfVars.HIVE_SERVER2_WEBUI_PORT.getDefaultValue() + "/stacks"; + public void testStackServlet() throws Exception { + String baseURL = "http://localhost:" + webUIPort + "/stacks"; URL url = new URL(baseURL); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); @@ -66,6 +81,45 @@ public void testStackServket() throws Exception { Assert.assertTrue(contents); } + + @Test + public void testConfStrippedFromWebUI() throws Exception { + + String pwdValFound = null; + String pwdKeyFound = null; + CloseableHttpClient httpclient = null; + try { + httpclient = HttpClients.createDefault(); + HttpGet httpGet = new HttpGet("http://localhost:"+webUIPort+"/conf"); + CloseableHttpResponse response1 = httpclient.execute(httpGet); + + try { + HttpEntity entity1 = response1.getEntity(); + BufferedReader br = new BufferedReader(new InputStreamReader(entity1.getContent())); + String line; + while ((line = br.readLine())!= null) { + if (line.contains(metastorePasswd)){ + pwdValFound = line; + } + if (line.contains(ConfVars.METASTOREPWD.varname)){ + pwdKeyFound = line; + } + } + EntityUtils.consume(entity1); + } finally { + response1.close(); + } + } finally { + if (httpclient != null){ + httpclient.close(); + } + } + + assertNotNull(pwdKeyFound); + assertNull(pwdValFound); + } + + @AfterClass public static void afterTests() throws Exception { hiveServer2.stop();