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

It is impossible to reject malformed optional form fields with anyParams #1125

Open
at-nap opened this issue Sep 20, 2016 · 0 comments
Open

Comments

@at-nap
Copy link

at-nap commented Sep 20, 2016

When using anyParams, it is impossible to reject malformed optional form fields; it unconditionally falls back to the query param, which is missing but optional, and therefor valid.

I.e:

  // Passes as expected
  "anyParam directive" should "reject malformed optional query parameters" in {
    Post("/?foo=bar", FormData(Seq.empty)) ~> anyParams('foo.as[Option[Int]]) {
      foo => complete(s"foo: $foo")
    } ~> check {
      rejections.head shouldBe a [MalformedQueryParamRejection]
    }
  }

  // Fails!
  it should "reject malformed optional form fields" in {
    Post("/", FormData(Seq("foo" -> "bar"))) ~> anyParams('foo.as[Option[Int]]) {
      foo => complete(s"foo: $foo")
    } ~> check {
      rejections.head shouldBe a [MalformedFormFieldRejection]
    }
  }

The second test fails:

...
[info] - should reject malformed optional form fields *** FAILED *** (8 milliseconds)
[info]   Request was not rejected, response was HttpResponse(200 OK,HttpEntity(text/plain; charset=UTF-8,foo: None),List(),HTTP/1.1)
...

This behaviour is unexpected. It seems anyParams ought to fall back to query params only on missing form fields. (Or anyParams ought to be renamed any*Valid*Params, if you get my drift.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant