Skip to content

Commit 9134a03

Browse files
authored
Actions with require-whisk-auth annotation as boolean false are rejected by controller (#4989)
* Actions with require-whisk-auth annotation as boolean false are rejected by controller * Fix testcase
1 parent e061d08 commit 9134a03

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

core/controller/src/main/scala/org/apache/openwhisk/core/controller/WebActions.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,11 @@ trait WhiskWebActionsApi
784784
annotations
785785
.get(Annotations.RequireWhiskAuthAnnotation)
786786
.map {
787-
case JsString(auth) => checkAuthHeader(auth) // allowed if auth matches header
788-
case JsNumber(auth) => checkAuthHeader(auth.toString) // allowed if auth matches header
789-
case JsTrue | JsBoolean(true) => authenticatedUser.isDefined // allowed if user already authenticated
790-
case _ => false // not allowed, something is not right
787+
case JsString(auth) => checkAuthHeader(auth) // allowed if auth matches header
788+
case JsNumber(auth) => checkAuthHeader(auth.toString) // allowed if auth matches header
789+
case JsTrue | JsBoolean(true) => authenticatedUser.isDefined // allowed if user already authenticated
790+
case JsFalse | JsBoolean(false) => true // allowed if the require-whisk-auth is specified as false
791+
case _ => false // not allowed, something is not right
791792
}
792793
}
793794

tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskWebActionsTests.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ class WskWebActionsTests extends TestHelpers with WskTestHelpers with RestUtil w
147147
authorizedResponse.body.asString.parseJson.asJsObject.fields("__ow_user").convertTo[String] shouldBe namespace
148148
}
149149

150+
/**
151+
* Tests web action not requiring authentication.
152+
*/
153+
it should "create a web action not requiring authentication accessible via HTTPS" in withAssetCleaner(wskprops) {
154+
(wp, assetHelper) =>
155+
val name = "webaction"
156+
val file = Some(TestUtils.getTestActionFilename("echo.js"))
157+
val host = getServiceURL()
158+
val url = s"$host$testRoutePath/$namespace/default/$name.json"
159+
160+
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
161+
action.create(name, file, web = Some("true"), annotations = Map("require-whisk-auth" -> false.toJson))
162+
}
163+
164+
val unauthorizedResponse = RestAssured.given().config(sslconfig).get(url)
165+
unauthorizedResponse.statusCode shouldBe 200
166+
}
167+
150168
it should "ensure that CORS header is preserved for custom options" in withAssetCleaner(wskprops) {
151169
(wp, assetHelper) =>
152170
val name = "webaction"

0 commit comments

Comments
 (0)