You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2017/10/26 02:50:07 UTC

[GitHub] houshengbo closed pull request #2898: Use proper host for Wsk REST tests

houshengbo closed pull request #2898: Use proper host for Wsk REST tests
URL: https://github.com/apache/incubator-openwhisk/pull/2898
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/tests/src/test/resources/application.conf b/tests/src/test/resources/application.conf
index 873d2231e5..03b3e0df5b 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 c6dbca39bf..155fa06a4c 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,


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services