|
@@ -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") {
|
|
@@ -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()
|
|
|
}
|
|
@@ -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)
|
|
|
+ }
|
|
|
}
|
|
|
}
|