You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by vv...@apache.org on 2018/09/28 09:23:50 UTC

[incubator-openwhisk] branch master updated: Enable testing with bearer token authentication (#4034)

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

vvraskin 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 84f633f  Enable testing with bearer token authentication (#4034)
84f633f is described below

commit 84f633fd9f8a44c1a0978f47d43aa0ba3ca06001
Author: Martin Henke <ma...@web.de>
AuthorDate: Fri Sep 28 11:23:20 2018 +0200

    Enable testing with bearer token authentication (#4034)
    
    This is an optional authentication method which is used to test non basic authentication SPIs
---
 tests/src/test/scala/common/WskOperations.scala          |  3 ++-
 tests/src/test/scala/common/rest/WskRestOperations.scala | 13 ++++++++-----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/tests/src/test/scala/common/WskOperations.scala b/tests/src/test/scala/common/WskOperations.scala
index bd089d0..9b012c7 100644
--- a/tests/src/test/scala/common/WskOperations.scala
+++ b/tests/src/test/scala/common/WskOperations.scala
@@ -40,7 +40,8 @@ case class WskProps(
   namespace: String = "_",
   apiversion: String = "v1",
   apihost: String = WhiskProperties.getEdgeHost,
-  token: String = "") {
+  token: String = "",
+  basicAuth: Boolean = true) {
   def overrides = Seq("-i", "--apihost", apihost, "--apiversion", apiversion)
   def writeFile(propsfile: File) = {
     val propsStr = s"""NAMESPACE=$namespace
diff --git a/tests/src/test/scala/common/rest/WskRestOperations.scala b/tests/src/test/scala/common/rest/WskRestOperations.scala
index 85742cc..94023d7 100644
--- a/tests/src/test/scala/common/rest/WskRestOperations.scala
+++ b/tests/src/test/scala/common/rest/WskRestOperations.scala
@@ -40,11 +40,10 @@ import akka.http.scaladsl.model.StatusCodes.OK
 import akka.http.scaladsl.model.HttpRequest
 import akka.http.scaladsl.model.HttpMethod
 import akka.http.scaladsl.model.HttpResponse
-import akka.http.scaladsl.model.headers.Authorization
+import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials, HttpCredentials, OAuth2BearerToken}
 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, Query}
 import akka.http.scaladsl.model.HttpMethods.DELETE
@@ -1176,7 +1175,7 @@ trait RunRestCmd extends Matchers with ScalaFutures with SwaggerValidator {
                     params: Map[String, String] = Map.empty,
                     body: Option[String] = None)(implicit wp: WskProps): HttpResponse = {
 
-    val creds = getBasicHttpCredentials(wp)
+    val creds = getHttpCredentials(wp)
 
     // startsWith(http) includes https
     val hostWithScheme = if (wp.apihost.startsWith("http")) {
@@ -1202,12 +1201,16 @@ trait RunRestCmd extends Matchers with ScalaFutures with SwaggerValidator {
     response
   }
 
-  private def getBasicHttpCredentials(wp: WskProps): BasicHttpCredentials = {
+  private def getHttpCredentials(wp: WskProps): HttpCredentials = {
     if (wp.authKey.contains(":")) {
       val authKey = wp.authKey.split(":")
       new BasicHttpCredentials(authKey(0), authKey(1))
     } else {
-      new BasicHttpCredentials(wp.authKey, wp.authKey)
+      if (wp.basicAuth) {
+        new BasicHttpCredentials(wp.authKey, wp.authKey)
+      } else {
+        new OAuth2BearerToken(wp.authKey)
+      }
     }
   }