This repository has been archived by the owner on Apr 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3, test: Unit tests for security template
- Loading branch information
1 parent
3f0999f
commit cb84bbb
Showing
7 changed files
with
717 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
api/src/main/scala/de/zalando/play/controllers/security.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package de.zalando.play.controllers | ||
|
||
/** | ||
* @author slasch | ||
* @since 05.03.2016. | ||
*/ | ||
class security { | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
compiler/src/test/resources/expected_results/security/basic.auth.api.yaml.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package basic.auth.api.yaml | ||
|
||
import play.api.mvc._ | ||
import Security.AuthenticatedBuilder | ||
import de.zalando.play.controllers.PlayBodyParsing | ||
|
||
|
||
trait BasicAuthApiYamlSecurity { | ||
|
||
def basicAuth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? | ||
|
||
val basicAuth_Checks = Seq(basicAuth_Extractor _) | ||
|
||
class basicAuth_Action(mimeType: String, unauthorizedContent: Any) extends AuthenticatedBuilder( | ||
req => { | ||
val individualChecks = basicAuth_Checks.map(_.apply(req)) | ||
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) | ||
}, | ||
onUnauthorized(mimeType, unauthorizedContent) | ||
) | ||
|
||
|
||
private def onUnauthorized[C](mimeType: String, content: C): RequestHeader => Result =_ => { | ||
implicit val writeable = PlayBodyParsing.anyToWritable[C](mimeType) | ||
Results.Unauthorized(content) | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
compiler/src/test/resources/expected_results/security/full.petstore.api.yaml.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package full.petstore.api.yaml | ||
|
||
import play.api.mvc._ | ||
import Security.AuthenticatedBuilder | ||
import de.zalando.play.controllers.PlayBodyParsing | ||
import de.zalando.play.controllers.ArrayWrapper | ||
import org.joda.time.DateTime | ||
|
||
|
||
trait FullPetstoreApiYamlSecurity { | ||
|
||
def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? | ||
|
||
val petstore_auth_Checks = Seq(petstore_auth_Extractor _) | ||
|
||
class petstore_auth_Action(mimeType: String, unauthorizedContent: Any) extends AuthenticatedBuilder( | ||
req => { | ||
val individualChecks = petstore_auth_Checks.map(_.apply(req)) | ||
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) | ||
}, | ||
onUnauthorized(mimeType, unauthorizedContent) | ||
) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? | ||
|
||
val petstore_auth_Checks = Seq(petstore_auth_Extractor _) | ||
|
||
class petstore_auth_Action(mimeType: String, unauthorizedContent: Any) extends AuthenticatedBuilder( | ||
req => { | ||
val individualChecks = petstore_auth_Checks.map(_.apply(req)) | ||
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) | ||
}, | ||
onUnauthorized(mimeType, unauthorizedContent) | ||
) | ||
|
||
|
||
def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? | ||
|
||
val petstore_auth_Checks = Seq(petstore_auth_Extractor _) | ||
|
||
class petstore_auth_Action(mimeType: String, unauthorizedContent: Any) extends AuthenticatedBuilder( | ||
req => { | ||
val individualChecks = petstore_auth_Checks.map(_.apply(req)) | ||
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) | ||
}, | ||
onUnauthorized(mimeType, unauthorizedContent) | ||
) | ||
|
||
|
||
|
||
|
||
|
||
|
||
def api_key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? | ||
def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? | ||
|
||
val api_key_petstore_auth_Checks = Seq(api_key_Extractor _, petstore_auth_Extractor _) | ||
|
||
class api_key_petstore_auth_Action(mimeType: String, unauthorizedContent: Any) extends AuthenticatedBuilder( | ||
req => { | ||
val individualChecks = api_key_petstore_auth_Checks.map(_.apply(req)) | ||
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) | ||
}, | ||
onUnauthorized(mimeType, unauthorizedContent) | ||
) | ||
|
||
|
||
def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? | ||
|
||
val petstore_auth_Checks = Seq(petstore_auth_Extractor _) | ||
|
||
class petstore_auth_Action(mimeType: String, unauthorizedContent: Any) extends AuthenticatedBuilder( | ||
req => { | ||
val individualChecks = petstore_auth_Checks.map(_.apply(req)) | ||
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) | ||
}, | ||
onUnauthorized(mimeType, unauthorizedContent) | ||
) | ||
|
||
|
||
def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? | ||
|
||
val petstore_auth_Checks = Seq(petstore_auth_Extractor _) | ||
|
||
class petstore_auth_Action(mimeType: String, unauthorizedContent: Any) extends AuthenticatedBuilder( | ||
req => { | ||
val individualChecks = petstore_auth_Checks.map(_.apply(req)) | ||
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) | ||
}, | ||
onUnauthorized(mimeType, unauthorizedContent) | ||
) | ||
|
||
|
||
def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? | ||
|
||
val petstore_auth_Checks = Seq(petstore_auth_Extractor _) | ||
|
||
class petstore_auth_Action(mimeType: String, unauthorizedContent: Any) extends AuthenticatedBuilder( | ||
req => { | ||
val individualChecks = petstore_auth_Checks.map(_.apply(req)) | ||
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) | ||
}, | ||
onUnauthorized(mimeType, unauthorizedContent) | ||
) | ||
|
||
|
||
|
||
private def onUnauthorized[C](mimeType: String, content: C): RequestHeader => Result =_ => { | ||
implicit val writeable = PlayBodyParsing.anyToWritable[C](mimeType) | ||
Results.Unauthorized(content) | ||
} | ||
} |
Oops, something went wrong.