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

Play Testing API does not handle absent body for POST request #8632

Closed
techmoksha opened this issue Sep 24, 2018 · 2 comments
Closed

Play Testing API does not handle absent body for POST request #8632

techmoksha opened this issue Sep 24, 2018 · 2 comments

Comments

@techmoksha
Copy link
Contributor

techmoksha commented Sep 24, 2018

Play Version (2.5.x / etc)

Play 2.6.13 (play-test_2.12-2.6.13)

API

Scala

Operating System

Mac OS 10.12.1

JDK

java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Expected Behavior

  1. POST requests using play-test API should support null/absent body.

Actual Behavior

  1. All details mentioned here

Reproducible Test Case

The post has the code snippet to reproduce the issue.

@mkurz
Copy link
Member

mkurz commented Oct 22, 2019

@techmoksha I tried hard, but I can not reproduce the exception using Play-Scala 2.6.13.
Can you provide us a reproducer that "works" (throws the exception)?

I used following test, because the example you give in the original discussion does compile...

package controllers

import org.scalatestplus.play._
import org.scalatestplus.play.guice._
import play.api.test.Helpers._
import play.api.test._

class HomeControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting {

  "HomeController POST" should {

    "not throw an exception with empty body" in {
      val request = FakeRequest(POST, "/uri").withHeaders("<myheader>" -> "headervalue")
      val result = Helpers.route(fakeApplication, request)
    }
  }
}

scyhhe added a commit to fgrutsch/playframework that referenced this issue Oct 22, 2019
scyhhe added a commit to fgrutsch/playframework that referenced this issue Oct 22, 2019
wsargent pushed a commit to wsargent/playframework that referenced this issue Oct 23, 2019
wsargent pushed a commit to wsargent/playframework that referenced this issue Oct 23, 2019
wsargent pushed a commit to wsargent/playframework that referenced this issue Oct 23, 2019
@mkurz
Copy link
Member

mkurz commented Oct 30, 2019

I had a look again because I was working on related code. However, I am still not able to reproduce this. The only place where jRoute is called is inside Java's route helper. And because this Java router helper method expects a RequestBuilder, we can be sure that this RequestBuilder always has a RequestBody set (just look how RequestBody is implemented, you will not be able to set null as body) (This RequestBody can in turn contain null but that does not matter here). So it's not possible to run into the NPE (also I was not able to do so).
So maybe the author did use jRoute directly and passed null explictly as body... However this is not how this should be used.

Because there is no reproducer I will close this.
Feel free to re-open if you know how to reproduce this.

@mkurz mkurz closed this as completed Oct 30, 2019
@mkurz mkurz removed this from the Play 2.x milestone Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants