Skip to content
This repository has been archived by the owner on Apr 10, 2019. It is now read-only.

Commit

Permalink
#3, test: Fixed outdated expected results
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaschmidt committed Mar 7, 2016
1 parent ddb1928 commit f70ace4
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,27 @@ package basic.auth.api.yaml

import play.api.mvc._
import Security.AuthenticatedBuilder
import de.zalando.play.controllers.PlayBodyParsing
import de.zalando.play.controllers.{PlayBodyParsing, SwaggerSecurityExtractors}
import SwaggerSecurityExtractors._

trait SecurityExtractors {
def basicAuth_Extractor[User >: Any](header: RequestHeader): Option[User] = ???

def basicAuth_Extractor[User >: Any](header: RequestHeader): Option[User] =
basicAuth(header) { (username: String, password: String) =>
???
}
implicit val unauthorizedContentWriter = ???
def unauthorizedContent(req: RequestHeader) = Results.Unauthorized(???)
}


trait BasicAuthApiYamlSecurity extends SecurityExtractors {
val unauthorizedContent = ???
val mimeType: String = ???


object getSecureAction extends AuthenticatedBuilder(
req => {
val secureChecks = Seq(basicAuth_Extractor _)
val individualChecks = secureChecks.map(_.apply(req))
val individualChecks: Seq[Option[_]] = secureChecks.map(_.apply(req))
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten))
},
onUnauthorized(mimeType, unauthorizedContent)
)
}, unauthorizedContent)


private def onUnauthorized[C](mimeType: String, content: C): RequestHeader => Result =_ => {
implicit val writeable = PlayBodyParsing.anyToWritable[C](mimeType)
Results.Unauthorized(content)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,88 +2,75 @@ package full.petstore.api.yaml

import play.api.mvc._
import Security.AuthenticatedBuilder
import de.zalando.play.controllers.PlayBodyParsing
import de.zalando.play.controllers.{PlayBodyParsing, SwaggerSecurityExtractors}
import SwaggerSecurityExtractors._
import de.zalando.play.controllers.ArrayWrapper
import org.joda.time.DateTime

trait SecurityExtractors {
def api_key_Extractor[User >: Any](header: RequestHeader): Option[User] = ???
def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ???

def api_key_Extractor[User >: Any](header: RequestHeader): Option[User] =
headerApiKey("api_key")(header) { (apiKey: String) =>
???
}
def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] =
oAuth(header) { _ =>
???
}
implicit val unauthorizedContentWriter = ???
def unauthorizedContent(req: RequestHeader) = Results.Unauthorized(???)
}


trait FullPetstoreApiYamlSecurity extends SecurityExtractors {
val unauthorizedContent = ???
val mimeType: String = ???


object findPetsByTagsSecureAction extends AuthenticatedBuilder(
req => {
val secureChecks = Seq(petstore_auth_Extractor _)
val individualChecks = secureChecks.map(_.apply(req))
val individualChecks: Seq[Option[_]] = secureChecks.map(_.apply(req))
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten))
},
onUnauthorized(mimeType, unauthorizedContent)
)
}, unauthorizedContent)

object updatePetSecureAction extends AuthenticatedBuilder(
req => {
val secureChecks = Seq(petstore_auth_Extractor _)
val individualChecks = secureChecks.map(_.apply(req))
val individualChecks: Seq[Option[_]] = secureChecks.map(_.apply(req))
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten))
},
onUnauthorized(mimeType, unauthorizedContent)
)
}, unauthorizedContent)

object addPetSecureAction extends AuthenticatedBuilder(
req => {
val secureChecks = Seq(petstore_auth_Extractor _)
val individualChecks = secureChecks.map(_.apply(req))
val individualChecks: Seq[Option[_]] = secureChecks.map(_.apply(req))
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten))
},
onUnauthorized(mimeType, unauthorizedContent)
)
}, unauthorizedContent)

object getPetByIdSecureAction extends AuthenticatedBuilder(
req => {
val secureChecks = Seq(api_key_Extractor _, petstore_auth_Extractor _)
val individualChecks = secureChecks.map(_.apply(req))
val individualChecks: Seq[Option[_]] = secureChecks.map(_.apply(req))
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten))
},
onUnauthorized(mimeType, unauthorizedContent)
)
}, unauthorizedContent)

object updatePetWithFormSecureAction extends AuthenticatedBuilder(
req => {
val secureChecks = Seq(petstore_auth_Extractor _)
val individualChecks = secureChecks.map(_.apply(req))
val individualChecks: Seq[Option[_]] = secureChecks.map(_.apply(req))
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten))
},
onUnauthorized(mimeType, unauthorizedContent)
)
}, unauthorizedContent)

object deletePetSecureAction extends AuthenticatedBuilder(
req => {
val secureChecks = Seq(petstore_auth_Extractor _)
val individualChecks = secureChecks.map(_.apply(req))
val individualChecks: Seq[Option[_]] = secureChecks.map(_.apply(req))
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten))
},
onUnauthorized(mimeType, unauthorizedContent)
)
}, unauthorizedContent)

object findPetsByStatusSecureAction extends AuthenticatedBuilder(
req => {
val secureChecks = Seq(petstore_auth_Extractor _)
val individualChecks = secureChecks.map(_.apply(req))
val individualChecks: Seq[Option[_]] = secureChecks.map(_.apply(req))
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten))
},
onUnauthorized(mimeType, unauthorizedContent)
)
}, unauthorizedContent)


private def onUnauthorized[C](mimeType: String, content: C): RequestHeader => Result =_ => {
implicit val writeable = PlayBodyParsing.anyToWritable[C](mimeType)
Results.Unauthorized(content)
}
}

Loading

0 comments on commit f70ace4

Please sign in to comment.