Skip to content

Commit

Permalink
LIVY-358. [Follow-up] Add unit test to verify header size configurati…
Browse files Browse the repository at this point in the history
…ons (apache#331)

* Add unit test to verify large header size configuration

Change-Id: I6c231f9fc9773d1ea40313661b7c49ccfaa44796

* Style fix

Change-Id: I24e617f95fd3e45a674a6b5a691428f0fdabcd89

* Style fix

Change-Id: I91e71979499da8ebba41223b6fe41862de168d03

* Revert the changes

Change-Id: Id7bbd1b2378867c8534b900bc7ba9b1234a9b985

* Add configurations to livy.conf.template

Change-Id: I84d428869bc5cc22aa7f00c6c603ea4a6b052964
  • Loading branch information
jerryshao authored and zjffdu committed May 18, 2017
1 parent 59af39d commit 2abb8a3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

package com.cloudera.livy.client.http

import java.io.IOException
import java.net.URLEncoder
import java.nio.charset.StandardCharsets.UTF_8
import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}

import org.apache.http.client.utils.URIBuilder
import org.eclipse.jetty.security._
import org.eclipse.jetty.security.authentication.BasicAuthenticator
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}
import org.eclipse.jetty.util.security._
import org.scalatest.{BeforeAndAfterAll, FunSpecLike}
import org.scalatest.Matchers._
import org.scalatra.servlet.ScalatraListener

import com.cloudera.livy.LivyBaseUnitTestSuite
import com.cloudera.livy.{LivyBaseUnitTestSuite, LivyConf}
import com.cloudera.livy.server.WebServer

class LivyConnectionSpec extends FunSpecLike with BeforeAndAfterAll with LivyBaseUnitTestSuite {
describe("LivyConnection") {
Expand Down Expand Up @@ -60,31 +60,29 @@ class LivyConnectionSpec extends FunSpecLike with BeforeAndAfterAll with LivyBas
csh
}

def staticServlet(): HttpServlet = new HttpServlet {
override def doGet(req: HttpServletRequest, resp: HttpServletResponse): Unit = {
resp.getWriter.print("true")
}
}

def test(password: String): Unit = {
def test(password: String, livyConf: LivyConf = new LivyConf()): Unit = {
val username = "user name"

val server = new Server(0)
val context = new ServletContextHandler(ServletContextHandler.SESSIONS)
context.setSecurityHandler(basicAuth(username, password, "realm"))
context.setContextPath("/")
context.addServlet(new ServletHolder(staticServlet()), "/")
server.setHandler(context)
val server = new WebServer(livyConf, "0.0.0.0", 0)
server.context.setSecurityHandler(basicAuth(username, password, "realm"))
server.context.setResourceBase("src/main/com/cloudera/livy/server")
server.context.setInitParameter(ScalatraListener.LifeCycleKey,
classOf[HttpClientTestBootstrap].getCanonicalName)
server.context.addEventListener(new ScalatraListener)
server.start()

val utf8Name = UTF_8.name()
val uri = new URIBuilder(server.getURI())
val uri = new URIBuilder()
.setScheme(server.protocol)
.setHost(server.host)
.setPort(server.port)
.setUserInfo(URLEncoder.encode(username, utf8Name), URLEncoder.encode(password, utf8Name))
.build()
info(uri.toString)
val conn = new LivyConnection(uri, new HttpConf(null))
try {
conn.get(classOf[Boolean], "/") shouldBe true
conn.get(classOf[Object], "/") should not be (null)

} finally {
conn.close()
}
Expand All @@ -100,5 +98,22 @@ class LivyConnectionSpec extends FunSpecLike with BeforeAndAfterAll with LivyBas
it("should support HTTP auth with empty password") {
test("")
}

it("should be failed with large header size") {
val livyConf = new LivyConf()
.set(LivyConf.REQUEST_HEADER_SIZE, 1024)
.set(LivyConf.RESPONSE_HEADER_SIZE, 1024)
val pwd = "test-password" * 100
val exception = intercept[IOException](test(pwd, livyConf))
exception.getMessage.contains("Request Entity Too Large") should be(true)
}

it("should be succeeded with configured header size") {
val livyConf = new LivyConf()
.set(LivyConf.REQUEST_HEADER_SIZE, 2048)
.set(LivyConf.RESPONSE_HEADER_SIZE, 2048)
val pwd = "test-password" * 100
test(pwd, livyConf)
}
}
}
4 changes: 4 additions & 0 deletions conf/livy.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
# What spark deploy mode Livy sessions should use.
# livy.spark.deploy-mode =

# Configure Livy server http request and response header size.
# livy.server.request-header.size = 131072
# livy.server.response-header.size = 131072

# Enabled to check whether timeout Livy sessions should be stopped.
# livy.server.session.timeout-check = true

Expand Down

0 comments on commit 2abb8a3

Please sign in to comment.