From 7ad0f354d66952db76d1b9d0dc327f1226b65ef7 Mon Sep 17 00:00:00 2001 From: "He-Pin(kerr)" Date: Fri, 27 Nov 2026 04:45:03 +0800 Subject: [PATCH] test: cover typed Cookie factory value validation Motivation: The request Cookie factories enforce the model grammar, but direct Scala and Java construction did not have matching test coverage. Modification: Add factory tests that accept a valid application value and reject a disallowed delimiter using the public model APIs. Result: Both frontends have direct checks for the shared Cookie contract. Production behavior is unchanged. References: RFC 6265 Sections 4.1.1 and 4.2.1; Netty 4.2 ClientCookieEncoderTest. --- .../http/scaladsl/model/headers/HeaderSpec.scala | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 a096930ae..c01366628 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 @@ -22,6 +22,20 @@ import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should.Matchers class HeaderSpec extends AnyFreeSpec with Matchers { + "Cookie factories should" - { + import pekko.http.javadsl.model.headers.{ Cookie => JavaCookie } + + "accept a plain cookie value" in { + Cookie("theme", "dark").cookies.head.value shouldEqual "dark" + JavaCookie.create("theme", "dark").getCookies.iterator().next().value() shouldEqual "dark" + } + + "reject a semicolon in a cookie value" in { + an[IllegalArgumentException] should be thrownBy Cookie("theme", ";") + an[IllegalArgumentException] should be thrownBy JavaCookie.create("theme", ";") + } + } + "Sec-WebSocket-Accept should" - { "produce the RFC 6455 handshake example" in { `Sec-WebSocket-Accept`.forKey(`Sec-WebSocket-Key`("dGhlIHNhbXBsZSBub25jZQ==")).key shouldEqual