Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parentheses for lambda param #10878

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ class CachedSpec extends PlaySpecification {
}
}

val dummyAction = Action { request: Request[_] =>
val dummyAction = Action { (request: Request[_]) =>
Results.Ok(Random.nextInt().toString)
}

val notFoundAction = Action { request: Request[_] =>
val notFoundAction = Action { (request: Request[_]) =>
Results.NotFound(Random.nextInt().toString)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ trait HeadActionSpec
}

val CustomAttr = TypedKey[String]("CustomAttr")
val attrAction = ActionBuilder.ignoringBody { rh: RequestHeader =>
val attrAction = ActionBuilder.ignoringBody { (rh: RequestHeader) =>
val attrComment = rh.attrs.get(CustomAttr)
val headers = Array.empty[(String, String)] ++
rh.attrs.get(CustomAttr).map("CustomAttr" -> _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ import scala.concurrent.Future
class SecuritySpec extends PlaySpecification {
"AuthenticatedBuilder" should {
"block unauthenticated requests" in withApplication { implicit app =>
status(TestAction(app) { req: Security.AuthenticatedRequest[_, String] =>
status(TestAction(app) { (req: Security.AuthenticatedRequest[_, String]) =>
Results.Ok(req.user)
}(FakeRequest())) must_== UNAUTHORIZED
}
"allow authenticated requests" in withApplication { implicit app =>
val result = TestAction(app) { req: Security.AuthenticatedRequest[_, String] =>
val result = TestAction(app) { (req: Security.AuthenticatedRequest[_, String]) =>
Results.Ok(req.user)
}(FakeRequest().withSession("username" -> "john"))
status(result) must_== OK
contentAsString(result) must_== "john"
}

"allow use as an ActionBuilder" in withApplication { implicit app =>
val result = Authenticated(app) { req: AuthenticatedDbRequest[_] =>
val result = Authenticated(app) { (req: AuthenticatedDbRequest[_]) =>
Results.Ok(s"${req.conn.name}:${req.user.name}")
}(FakeRequest().withSession("user" -> "Phil"))
status(result) must_== OK
Expand Down Expand Up @@ -68,7 +68,7 @@ class SecuritySpec extends PlaySpecification {
lazy val parser = app.injector.instanceOf[PlayBodyParsers].default
def invokeBlock[A](request: Request[A], block: (AuthenticatedDbRequest[A]) => Future[Result]) = {
val builder = AuthenticatedBuilder(req => getUserFromRequest(req), parser)(executionContext)
builder.authenticate(request, { authRequest: AuthenticatedRequest[A, User] =>
builder.authenticate(request, { (authRequest: AuthenticatedRequest[A, User]) =>
fakedb.withConnection { conn =>
block(new AuthenticatedDbRequest[A](authRequest.user, conn, request))
}
Expand Down Expand Up @@ -97,7 +97,7 @@ class AuthMessagesRequest[A](val user: User, messagesApi: MessagesApi, request:
extends MessagesRequest[A](request, messagesApi)

class UserAuthenticatedBuilder(parser: BodyParser[AnyContent])(implicit ec: ExecutionContext)
extends AuthenticatedBuilder[User]({ req: RequestHeader =>
extends AuthenticatedBuilder[User]({ (req: RequestHeader) =>
req.session.get("user").map(User)
}, parser) {
@Inject()
Expand All @@ -122,7 +122,7 @@ class AuthenticatedActionBuilder(
}

def invokeBlock[A](request: Request[A], block: ResultBlock[A]): Future[Result] = {
builder.authenticate(request, { authRequest: AuthenticatedRequest[A, User] =>
builder.authenticate(request, { (authRequest: AuthenticatedRequest[A, User]) =>
block(new AuthMessagesRequest[A](authRequest.user, messagesApi, request))
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AkkaHttpCustomServerProviderSpec
def requestWithMethod[A: AsResult](endpointRecipe: ServerEndpointRecipe, method: String, body: RequestBody)(
f: Either[Int, String] => A
): Fragment =
appFactory.withOkHttpEndpoints(Seq(endpointRecipe)) { okEndpoint: OkHttpEndpoint =>
appFactory.withOkHttpEndpoints(Seq(endpointRecipe)) { (okEndpoint: OkHttpEndpoint) =>
val response = okEndpoint.configuredCall("/")(_.method(method, body))
val param: Either[Int, String] = if (response.code == 200) Right(response.body.string) else Left(response.code)
f(param)
Expand All @@ -61,7 +61,7 @@ class AkkaHttpCustomServerProviderSpec
_ must beLeft(501)
)
"reject a long header value" in appFactory.withOkHttpEndpoints(Seq(AkkaHttp11Plaintext)) {
okEndpoint: OkHttpEndpoint =>
(okEndpoint: OkHttpEndpoint) =>
val response = okEndpoint.configuredCall("/")(
_.addHeader("X-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "abc")
)
Expand Down Expand Up @@ -104,7 +104,7 @@ class AkkaHttpCustomServerProviderSpec
})

"accept a long header value" in appFactory.withOkHttpEndpoints(Seq(customAkkaHttpEndpoint)) {
okEndpoint: OkHttpEndpoint =>
(okEndpoint: OkHttpEndpoint) =>
val response = okEndpoint.configuredCall("/")(
_.addHeader("X-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "abc")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class FlashCookieSpec
*/
implicit class CookieEndpointBaker(val appFactory: ApplicationFactory) {
def withAllCookieEndpoints[A: AsResult](block: CookieEndpoint => A): Fragment = {
appFactory.withAllOkHttpEndpoints { okEndpoint: OkHttpEndpoint =>
appFactory.withAllOkHttpEndpoints { (okEndpoint: OkHttpEndpoint) =>
block(new CookieEndpoint {
import JavaConverters._
def call(path: String, cookies: List[okhttp3.Cookie]): (okhttp3.Response, List[okhttp3.Cookie]) = {
Expand Down Expand Up @@ -96,7 +96,7 @@ class FlashCookieSpec

"the flash cookie" should {
"be set for first request and removed on next request" in withFlashCookieApp().withAllCookieEndpoints {
fcep: CookieEndpoint =>
(fcep: CookieEndpoint) =>
// Make a request that returns a flash cookie
val (response1, cookies1) = fcep.call("/flash", Nil)
response1.code must equalTo(SEE_OTHER)
Expand All @@ -120,7 +120,7 @@ class FlashCookieSpec
}

"allow the setting of additional cookies when cleaned up" in withFlashCookieApp().withAllCookieEndpoints {
fcep: CookieEndpoint =>
(fcep: CookieEndpoint) =>
// Get a flash cookie
val (response1, cookies1) = fcep.call("/flash", Nil)
response1.code must equalTo(SEE_OTHER)
Expand All @@ -143,23 +143,23 @@ class FlashCookieSpec

"honor the configuration for play.http.flash.sameSite" in {
"by not sending SameSite when configured to null" in withFlashCookieApp(Map("play.http.flash.sameSite" -> null))
.withAllCookieEndpoints { fcep: CookieEndpoint =>
.withAllCookieEndpoints { (fcep: CookieEndpoint) =>
val (response, cookies) = fcep.call("/flash", Nil)
response.code must equalTo(SEE_OTHER)
response.header(SET_COOKIE) must not contain ("SameSite")
}

"by sending SameSite=Lax when configured with 'lax'" in withFlashCookieApp(
Map("play.http.flash.sameSite" -> "lax")
).withAllCookieEndpoints { fcep: CookieEndpoint =>
).withAllCookieEndpoints { (fcep: CookieEndpoint) =>
val (response, cookies) = fcep.call("/flash", Nil)
response.code must equalTo(SEE_OTHER)
response.header(SET_COOKIE) must contain("SameSite=Lax")
}

"by sending SameSite=Strict when configured with 'strict'" in withFlashCookieApp(
Map("play.http.flash.sameSite" -> "lax")
).withAllCookieEndpoints { fcep: CookieEndpoint =>
).withAllCookieEndpoints { (fcep: CookieEndpoint) =>
val (response, cookies) = fcep.call("/flash", Nil)
response.code must equalTo(SEE_OTHER)
response.header(SET_COOKIE) must contain("SameSite=Lax")
Expand All @@ -168,15 +168,15 @@ class FlashCookieSpec

"honor configuration for flash.secure" in {
"by making cookies secure when set to true" in withFlashCookieApp(Map("play.http.flash.secure" -> true))
.withAllCookieEndpoints { fcep: CookieEndpoint =>
.withAllCookieEndpoints { (fcep: CookieEndpoint) =>
val (response, cookies) = fcep.call("/flash", Nil)
response.code must equalTo(SEE_OTHER)
val cookie = cookies.find(_.name == flashCookieBaker.COOKIE_NAME)
cookie must beSome.which(_.secure)
}

"by not making cookies secure when set to false" in withFlashCookieApp(Map("play.http.flash.secure" -> false))
.withAllCookieEndpoints { fcep: CookieEndpoint =>
.withAllCookieEndpoints { (fcep: CookieEndpoint) =>
val (response, cookies) = fcep.call("/flash", Nil)
response.code must equalTo(SEE_OTHER)
val cookie = cookies.find(_.name == flashCookieBaker.COOKIE_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class FormFieldOrderSpec
val contentType = "application/x-www-form-urlencoded"

val fakeAppFactory: ApplicationFactory = withAction { actionBuilder =>
actionBuilder { request: Request[AnyContent] =>
actionBuilder { (request: Request[AnyContent]) =>
// Check precondition. This needs to be an x-www-form-urlencoded request body
request.contentType must beSome(contentType)
// The following just ingests the request body and converts it to a sequence of strings of the form name=value
val pairs: Seq[String] = {
request.body.asFormUrlEncoded.map { params: Map[String, Seq[String]] =>
request.body.asFormUrlEncoded.map { (params: Map[String, Seq[String]]) =>
{
for ((key: String, value: Seq[String]) <- params) yield key + "=" + value.mkString
}.toSeq
Expand All @@ -38,7 +38,7 @@ class FormFieldOrderSpec
}
}

"preserve form field order" in fakeAppFactory.withAllOkHttpEndpoints { okep: OkHttpEndpoint =>
"preserve form field order" in fakeAppFactory.withAllOkHttpEndpoints { (okep: OkHttpEndpoint) =>
val request = new okhttp3.Request.Builder()
.url(okep.endpoint.pathUrl("/"))
.post(okhttp3.RequestBody.create(okhttp3.MediaType.parse(contentType), urlEncoded))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IdleTimeoutSpec extends PlaySpecification with EndpointIntegrationSpecific
"Play's idle timeout support" should {

def withServerAndConfig(extraConfig: Map[String, Any] = Map.empty): ApplicationFactory = {
withConfigAndRouter(extraConfig) { components: BuiltInComponents =>
withConfigAndRouter(extraConfig) { (components: BuiltInComponents) =>
Router.from {
case _ =>
EssentialAction { rh =>
Expand Down Expand Up @@ -79,7 +79,7 @@ class IdleTimeoutSpec extends PlaySpecification with EndpointIntegrationSpecific
"play.server.http.idleTimeout" -> null,
"play.server.https.idleTimeout" -> null
)
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { endpoint: ServerEndpoint =>
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { (endpoint: ServerEndpoint) =>
// We are interested to know that the server started correctly with "null"
// configurations. So there is no need to wait for a longer time.
val responses = doRequests(endpoint.port, trickle = 200L, secure = "https" == endpoint.scheme)
Expand All @@ -94,7 +94,7 @@ class IdleTimeoutSpec extends PlaySpecification with EndpointIntegrationSpecific
"play.server.http.idleTimeout" -> "infinite",
"play.server.https.idleTimeout" -> "infinite"
)
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { endpoint: ServerEndpoint =>
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { (endpoint: ServerEndpoint) =>
// We are interested to know that the server started correctly with "infinite"
// configurations. So there is no need to wait for a longer time.
val responses = doRequests(endpoint.port, trickle = 200L, secure = "https" == endpoint.scheme)
Expand All @@ -106,7 +106,7 @@ class IdleTimeoutSpec extends PlaySpecification with EndpointIntegrationSpecific

"support sub-second timeouts" in {
val extraConfig = timeouts(httpTimeout = 300.millis, httpsTimeout = 300.millis)
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { endpoint: ServerEndpoint =>
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { (endpoint: ServerEndpoint) =>
doRequests(endpoint.port, trickle = 400L, secure = "https" == endpoint.scheme) must throwA[IOException].like {
case e => (e must beAnInstanceOf[SocketException]).or(e.getCause must beAnInstanceOf[SocketException])
}
Expand All @@ -115,7 +115,7 @@ class IdleTimeoutSpec extends PlaySpecification with EndpointIntegrationSpecific

"support a separate timeout for https" in {
val extraConfig = timeouts(1.second, httpsTimeout = 400.millis)
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { endpoint: ServerEndpoint =>
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { (endpoint: ServerEndpoint) =>
if (endpoint.scheme == "http") {
val responses = doRequests(endpoint.port, trickle = 200L)
responses.length must_== 2
Expand All @@ -131,7 +131,7 @@ class IdleTimeoutSpec extends PlaySpecification with EndpointIntegrationSpecific

"support multi-second timeouts" in {
val extraConfig = timeouts(httpTimeout = 1500.millis, httpsTimeout = 1500.millis)
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { endpoint: ServerEndpoint =>
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { (endpoint: ServerEndpoint) =>
doRequests(endpoint.port, trickle = 2600L, secure = "https" == endpoint.scheme) must throwA[IOException].like {
case e => (e must beAnInstanceOf[SocketException]).or(e.getCause must beAnInstanceOf[SocketException])
}
Expand All @@ -140,7 +140,7 @@ class IdleTimeoutSpec extends PlaySpecification with EndpointIntegrationSpecific

"not timeout for slow requests with a sub-second timeout" in {
val extraConfig = timeouts(httpTimeout = 700.millis, httpsTimeout = 700.millis)
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { endpoint: ServerEndpoint =>
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { (endpoint: ServerEndpoint) =>
val responses = doRequests(endpoint.port, trickle = 400L, secure = "https" == endpoint.scheme)
responses.length must_== 2
responses(0).status must_== 200
Expand All @@ -150,7 +150,7 @@ class IdleTimeoutSpec extends PlaySpecification with EndpointIntegrationSpecific

"not timeout for slow requests with a multi-second timeout" in {
val extraConfig = timeouts(httpTimeout = 1500.millis, httpsTimeout = 1500.millis)
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { endpoint: ServerEndpoint =>
withServerAndConfig(extraConfig).withEndpoints(endpoints(extraConfig)) { (endpoint: ServerEndpoint) =>
val responses = doRequests(endpoint.port, trickle = 1000L, secure = "https" == endpoint.scheme)
responses.length must_== 2
responses(0).status must_== 200
Expand All @@ -161,7 +161,7 @@ class IdleTimeoutSpec extends PlaySpecification with EndpointIntegrationSpecific
"always be infinite when using akka-http HTTP/2" in {
// See https://github.com/akka/akka-http/pull/2776
val extraConfig = timeouts(httpTimeout = 100.millis, httpsTimeout = 100.millis) // will be ignored
withServerAndConfig(extraConfig).withEndpoints(akkaHttp2endpoints(extraConfig)) { endpoint: ServerEndpoint =>
withServerAndConfig(extraConfig).withEndpoints(akkaHttp2endpoints(extraConfig)) { (endpoint: ServerEndpoint) =>
val responses = doRequests(endpoint.port, trickle = 1500L, secure = "https" == endpoint.scheme)
responses.length must_== 2
responses(0).status must_== 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ class SecureFlagSpec

/** An ApplicationFactory with a single action that returns the request's `secure` flag. */
val secureFlagAppFactory: ApplicationFactory = withAction { actionBuilder =>
actionBuilder { request: Request[_] =>
actionBuilder { (request: Request[_]) =>
Results.Ok(request.secure.toString)
}
}

"Play https server" should {
"show that by default requests are secure only if the protocol is secure" in secureFlagAppFactory
.withAllOkHttpEndpoints { okep: OkHttpEndpoint =>
.withAllOkHttpEndpoints { (okep: OkHttpEndpoint) =>
val response = okep.call("/")
response.body.string must ===((okep.endpoint.scheme == "https").toString)
}
"show that requests are secure if X_FORWARDED_PROTO is https" in secureFlagAppFactory.withAllOkHttpEndpoints {
okep: OkHttpEndpoint =>
(okep: OkHttpEndpoint) =>
val request = okep
.requestBuilder("/")
.addHeader(X_FORWARDED_PROTO, "https")
Expand All @@ -42,7 +42,7 @@ class SecureFlagSpec
response.body.string must ===("true")
}
"show that requests are insecure if X_FORWARDED_PROTO is http" in secureFlagAppFactory.withAllOkHttpEndpoints {
okep: OkHttpEndpoint =>
(okep: OkHttpEndpoint) =>
val request = okep
.requestBuilder("/")
.addHeader(X_FORWARDED_PROTO, "http")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ class UriHandlingSpec
with OkHttpEndpointSupport
with ApplicationFactories {
private def makeRequest[T: AsResult](path: String)(block: (ServerEndpoint, okhttp3.Response) => T): Fragment =
withRouter { components: BuiltInComponents =>
withRouter { (components: BuiltInComponents) =>
import components.{ defaultActionBuilder => Action }
import sird.UrlContext
Router.from {
case sird.GET(p"/path") =>
Action { request: Request[_] =>
Action { (request: Request[_]) =>
Results.Ok(request.queryString)
}
case _ =>
Action { request: Request[_] =>
Action { (request: Request[_]) =>
Results.Ok(request.path + queryToString(request.queryString))
}
}
}.withAllOkHttpEndpoints { okEndpoint: OkHttpEndpoint =>
}.withAllOkHttpEndpoints { (okEndpoint: OkHttpEndpoint) =>
val response: okhttp3.Response = okEndpoint.call(path)
block(okEndpoint.endpoint, response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ trait ScalaWSSpec
Server.withRouterFromComponents() { c =>
{
case _ =>
c.defaultActionBuilder { req: Request[AnyContent] =>
c.defaultActionBuilder { (req: Request[AnyContent]) =>
Results.Ok(req.headers.keys.filter(_.equalsIgnoreCase("authorization")).mkString)
}
}
Expand Down Expand Up @@ -213,7 +213,7 @@ trait ScalaWSSpec
Server.withRouterFromComponents() { components =>
{
case _ =>
components.defaultActionBuilder(echo) { req: Request[Source[ByteString, _]] =>
components.defaultActionBuilder(echo) { (req: Request[Source[ByteString, _]]) =>
Ok.chunked(req.body)
}
}
Expand All @@ -236,7 +236,7 @@ trait ScalaWSSpec
Server.withRouterFromComponents() { c =>
{
case _ =>
c.defaultActionBuilder { req: Request[AnyContent] =>
c.defaultActionBuilder { (req: Request[AnyContent]) =>
val contentLength = req.headers.get(CONTENT_LENGTH)
val transferEncoding = req.headers.get(TRANSFER_ENCODING)
Ok(s"Content-Length: ${contentLength.getOrElse(-1)}; Transfer-Encoding: ${transferEncoding.getOrElse(-1)}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ trait ServerSpec extends Specification with BeforeAll {
withServer(
Server.forRouter(
JavaMode.DEV,
asJavaFunction { components: JBuiltInComponents =>
asJavaFunction { (components: JBuiltInComponents) =>
RoutingDsl
.fromComponents(components)
.GET("/something")
Expand Down