Skip to content

test: cover typed response cookie factory validation - #1676

Open
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:test/typed-response-cookie-factory-validation
Open

He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:test/typed-response-cookie-factory-validation

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 26, 2026

Copy link
Copy Markdown
Member

Motivation

The public Scala and Java response HttpCookie factories enforce the shared name and value grammar. Both construction APIs should have direct tests.

Modification

Add local typed constructor tests for ordinary name and value retention and for rejection at the name and value grammar boundaries.

Result

Both public response factories have direct coverage. Production behavior is unchanged.

Tests

  • JDK 17 with Scala 2.13.18 and 3.3.9: three focused tests passed on each version using the exact changed spec with existing compiled supporting classes.
  • Scoped Scalafmt and git diff --check passed. No wire traffic or full CI before opening.

References

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small comments on the tests, none blocking.

One observation outside this diff: HttpCookiePair.validate only checks nameChars.matchesAll(name), which looks like it is vacuously true for an empty string. If so, HttpCookie("", "dark") is accepted and renders Set-Cookie: =dark, although RFC 6265 requires cookie-name to be a token of at least one character. I have not run this to confirm. It is pre-existing and would belong in a separate PR, but the new "reject a non-token cookie name" test only tries " ", so it does not cover that boundary.

Motivation:
The Scala and Java response cookie factories share validation of names
and values, but the rejection causes need direct coverage in both DSLs.

Modification:
Keep response cookie validation in the Scala header spec and add the
Java rejection cases to the Java HttpCookie spec. Assert distinct name
and content error fragments without duplicating the Java factory's
existing successful construction case.

Result:
Both DSLs check that each invalid argument reaches its intended
validation, without changing production behavior.

References:
RFC 6265 Section 4.1.1.
@He-Pin
He-Pin force-pushed the test/typed-response-cookie-factory-validation branch from 3b8d427 to a68457f Compare November 26, 2026 23:57
@He-Pin
He-Pin requested a review from pjfanning November 26, 2026 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants