diff --git a/http-core/src/test/scala/org/apache/pekko/http/javadsl/model/headers/HttpCookieSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/javadsl/model/headers/HttpCookieSpec.scala index 0c28962e0f..02726e75b2 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/javadsl/model/headers/HttpCookieSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/javadsl/model/headers/HttpCookieSpec.scala @@ -46,6 +46,16 @@ class HttpCookieSpec extends AnyFreeSpec with Matchers { Optional.of(SameSite.Lax)).getSameSite must be(Optional.of(SameSite.Lax)) } } + "reject invalid arguments" - { + "non-token cookie name" in { + val error = the[IllegalArgumentException] thrownBy HttpCookie.create(" ", "dark") + error.getMessage must include("not allowed in cookie name") + } + "semicolon in a cookie value" in { + val error = the[IllegalArgumentException] thrownBy HttpCookie.create("theme", ";") + error.getMessage must include("not allowed in cookie content") + } + } "SameSite conversation to Scala" - { "convert Strict" in { SameSite.Strict.asScala() must be(sh.SameSite.Strict) diff --git a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/headers/HeaderSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/headers/HeaderSpec.scala index c013666281..6a1781f739 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/headers/HeaderSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/model/headers/HeaderSpec.scala @@ -328,6 +328,23 @@ class HeaderSpec extends AnyFreeSpec with Matchers { } } } + "HttpCookie factories should" - { + "retain an ordinary name and value" in { + val cookie = HttpCookie("theme", "dark") + cookie.name shouldEqual "theme" + cookie.value shouldEqual "dark" + } + + "reject a non-token cookie name" in { + val error = the[IllegalArgumentException] thrownBy HttpCookie(" ", "dark") + error.getMessage should include("not allowed in cookie name") + } + + "reject a semicolon in a cookie value" in { + val error = the[IllegalArgumentException] thrownBy HttpCookie("theme", ";") + error.getMessage should include("not allowed in cookie content") + } + } "RawHeader should" - { "check for valid arguments" - { "successful parse run" in {