You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ho...@apache.org on 2017/10/26 02:50:06 UTC

[incubator-openwhisk] branch master updated: Use proper host for Wsk REST tests (#2898)

This is an automated email from the ASF dual-hosted git repository.

houshengbo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 7befdb8  Use proper host for Wsk REST tests (#2898)
7befdb8 is described below

commit 7befdb84e026bb7cd99896c6e8e1e3b9c59a31bd
Author: James Dubee <jw...@us.ibm.com>
AuthorDate: Wed Oct 25 22:50:03 2017 -0400

    Use proper host for Wsk REST tests (#2898)
    
    * Use proper host for rest tests
    
    * Don't configure SSL for each request
    
    * Use getApiHostForAction instead of getEdgeHost
    
    * Suppress SSL warnings
    
    * Refactoring
    
    * Disable hostname verification
---
 tests/src/test/resources/application.conf      |  1 +
 tests/src/test/scala/common/rest/WskRest.scala | 40 ++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/tests/src/test/resources/application.conf b/tests/src/test/resources/application.conf
index 873d223..03b3e0d 100644
--- a/tests/src/test/resources/application.conf
+++ b/tests/src/test/resources/application.conf
@@ -1,3 +1,4 @@
+akka.ssl-config.hostnameVerifierClass = common.rest.AcceptAllHostNameVerifier
 
 whisk.spi {
   SimpleSpi = whisk.spi.SimpleSpiImpl
diff --git a/tests/src/test/scala/common/rest/WskRest.scala b/tests/src/test/scala/common/rest/WskRest.scala
index c6dbca3..155fa06 100644
--- a/tests/src/test/scala/common/rest/WskRest.scala
+++ b/tests/src/test/scala/common/rest/WskRest.scala
@@ -21,6 +21,7 @@ import java.io.File
 import java.time.Clock
 import java.time.Instant
 import java.util.Base64
+import java.security.cert.X509Certificate
 
 import org.apache.commons.io.FileUtils
 import org.scalatest.Matchers
@@ -54,15 +55,14 @@ import akka.http.scaladsl.model.headers.Authorization
 import akka.http.scaladsl.model.HttpEntity
 import akka.http.scaladsl.model.ContentTypes
 import akka.http.scaladsl.Http
-
 import akka.http.scaladsl.model.headers.BasicHttpCredentials
 import akka.http.scaladsl.model.Uri
 import akka.http.scaladsl.model.Uri.Path
-
 import akka.http.scaladsl.model.HttpMethods.DELETE
 import akka.http.scaladsl.model.HttpMethods.GET
 import akka.http.scaladsl.model.HttpMethods.POST
 import akka.http.scaladsl.model.HttpMethods.PUT
+import akka.http.scaladsl.HttpsConnectionContext
 
 import akka.stream.ActorMaterializer
 
@@ -91,6 +91,28 @@ import common.WskProps
 import whisk.core.entity.ByteSize
 import whisk.utils.retry
 
+import javax.net.ssl.{HostnameVerifier, KeyManager, SSLContext, SSLSession, X509TrustManager}
+
+import com.typesafe.sslconfig.akka.AkkaSSLConfig
+
+class AcceptAllHostNameVerifier extends HostnameVerifier {
+  def verify(s: String, sslSession: SSLSession) = true
+}
+
+object SSL {
+  lazy val nonValidatingContext: SSLContext = {
+    class IgnoreX509TrustManager extends X509TrustManager {
+      def checkClientTrusted(chain: Array[X509Certificate], authType: String) = ()
+      def checkServerTrusted(chain: Array[X509Certificate], authType: String) = ()
+      def getAcceptedIssuers = Array[X509Certificate]()
+    }
+
+    val context = SSLContext.getInstance("TLS")
+    context.init(Array[KeyManager](), Array(new IgnoreX509TrustManager), null)
+    context
+  }
+}
+
 class WskRest() extends RunWskRestCmd with BaseWsk {
   override implicit val action = new WskRestAction
   override implicit val trigger = new WskRestTrigger
@@ -937,7 +959,7 @@ class WskRestApi extends RunWskRestCmd with BaseApi {
     val r = action match {
       case Some(action) => {
         val (ns, actionName) = this.getNamespaceEntityName(action)
-        val actionUrl = s"https://${WhiskProperties.getBaseControllerHost()}$basePath/web/$ns/default/$actionName.http"
+        val actionUrl = s"${WhiskProperties.getApiHostForAction}/$basePath/web/$ns/default/$actionName.http"
         val actionAuthKey = this.getAuthKey(wp)
         val testaction = Some(
           ApiAction(name = actionName, namespace = ns, backendUrl = actionUrl, authkey = actionAuthKey))
@@ -1106,7 +1128,7 @@ class WskRestApi extends RunWskRestCmd with BaseApi {
 
   def getApi(basepathOrApiName: String, params: Map[String, String] = Map(), expectedExitCode: Int = OK.intValue)(
     implicit wp: WskProps): RestResult = {
-    val whiskUrl = Uri(s"http://${WhiskProperties.getBaseControllerHost()}:9001")
+    val whiskUrl = Uri(WhiskProperties.getApiHostForAction)
     val path = Path(s"/api/${wp.authKey.split(":")(0)}$basepathOrApiName/path")
     val resp = requestEntity(GET, path, params, whiskUrl = whiskUrl)
     val result = new RestResult(resp.status, getRespData(resp))
@@ -1118,9 +1140,14 @@ class RunWskRestCmd() extends FlatSpec with RunWskCmd with Matchers with ScalaFu
 
   implicit val config = PatienceConfig(100 seconds, 15 milliseconds)
   implicit val materializer = ActorMaterializer()
-  val whiskRestUrl = Uri(s"http://${WhiskProperties.getBaseControllerAddress()}")
+  val whiskRestUrl = Uri(WhiskProperties.getApiHostForAction)
   val basePath = Path("/api/v1")
 
+  val sslConfig = AkkaSSLConfig().mapSettings { s =>
+    s.withLoose(s.loose.withAcceptAnyCertificate(true).withDisableHostnameVerification(true))
+  }
+  val connectionContext = new HttpsConnectionContext(SSL.nonValidatingContext, Some(sslConfig))
+
   def validateStatusCode(expectedExitCode: Int, statusCode: Int) = {
     if ((expectedExitCode != DONTCARE_EXIT) && (expectedExitCode != ANY_ERROR_EXIT))
       if (statusCode != expectedExitCode)
@@ -1145,7 +1172,8 @@ class RunWskRestCmd() extends FlatSpec with RunWskCmd with Matchers with ScalaFu
       HttpEntity(ContentTypes.`application/json`, b)
     } getOrElse HttpEntity(ContentTypes.`application/json`, "")
     val request = HttpRequest(method, uri, List(Authorization(creds)), entity = entity)
-    Http().singleRequest(request)
+
+    Http().singleRequest(request, connectionContext)
   }
 
   def requestEntity(method: HttpMethod,

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].