Skip to content

Commit

Permalink
Merge pull request quarkusio#38466 from stianst/samesite
Browse files Browse the repository at this point in the history
Use proper case for SameSite cookie
  • Loading branch information
geoand authored Jan 30, 2024
2 parents 8d799c4 + a280efc commit 527cd0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,21 @@ public String toString(Object value) {
b.append(";HttpOnly");
if (cookie.getSameSite() != null) {
b.append(";SameSite=");
b.append(cookie.getSameSite());
appendCorrectCase(b, cookie.getSameSite());
}
return b.toString();
}

private static void appendCorrectCase(final StringBuilder sb, final Enum<?> e) {
boolean first = true;
for (char c : e.name().toCharArray()) {
if (first) {
sb.append(c);
first = false;
} else {
sb.append(Character.toLowerCase(c));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void testSameSite() {
.formParam("cookie", "greeting=\"hello\";SameSite=\"Lax\";")
.post("/cookies/set-cookie")
.then()
.cookie("greeting", detailedCookie().value("hello").sameSite("LAX"));
.cookie("greeting", detailedCookie().value("hello").sameSite("Lax"));
}

@Test
Expand All @@ -119,7 +119,7 @@ void testSameSiteWithoutColon() {
.formParam("cookie", "greeting=\"hello\";SameSite=\"None\"")
.post("/cookies/set-cookie")
.then()
.cookie("greeting", detailedCookie().value("hello").sameSite("NONE"));
.cookie("greeting", detailedCookie().value("hello").sameSite("None"));
}

@Test
Expand All @@ -130,7 +130,7 @@ void testSameSiteLowercase() {
.formParam("cookie", "greeting=\"hello\";samesite=\"Strict\"")
.post("/cookies/set-cookie")
.then()
.cookie("greeting", detailedCookie().value("hello").sameSite("STRICT"));
.cookie("greeting", detailedCookie().value("hello").sameSite("Strict"));
}

@Test
Expand Down

0 comments on commit 527cd0f

Please sign in to comment.