Skip to content

Commit

Permalink
Fix MockCookie Partitioned support
Browse files Browse the repository at this point in the history
  • Loading branch information
bclozel committed Jun 7, 2024
1 parent 9cfd455 commit e8c122c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -104,7 +104,12 @@ public String getSameSite() {
* @see <a href="https://datatracker.ietf.org/doc/html/draft-cutler-httpbis-partitioned-cookies#section-2.1">The Partitioned attribute spec</a>
*/
public void setPartitioned(boolean partitioned) {
setAttribute("Partitioned", "");
if (partitioned) {
setAttribute("Partitioned", "");
}
else {
setAttribute("Partitioned", null);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void constructCookie() {
assertThat(cookie.getMaxAge()).isEqualTo(-1);
assertThat(cookie.getPath()).isNull();
assertThat(cookie.isHttpOnly()).isFalse();
assertThat(cookie.isPartitioned()).isFalse();
assertThat(cookie.getSecure()).isFalse();
assertThat(cookie.getSameSite()).isNull();
}
Expand Down Expand Up @@ -207,9 +208,11 @@ void setInvalidAttributeExpiresShouldThrow() {
@Test
void setPartitioned() {
MockCookie cookie = new MockCookie("SESSION", "123");
cookie.setAttribute("Partitioned", "");

assertThat(cookie.isPartitioned()).isFalse();
cookie.setPartitioned(true);
assertThat(cookie.isPartitioned()).isTrue();
cookie.setPartitioned(false);
assertThat(cookie.isPartitioned()).isFalse();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -104,7 +104,12 @@ public String getSameSite() {
* @see <a href="https://datatracker.ietf.org/doc/html/draft-cutler-httpbis-partitioned-cookies#section-2.1">The Partitioned attribute spec</a>
*/
public void setPartitioned(boolean partitioned) {
setAttribute("Partitioned", "");
if (partitioned) {
setAttribute("Partitioned", "");
}
else {
setAttribute("Partitioned", null);
}
}

/**
Expand Down Expand Up @@ -197,6 +202,7 @@ public String toString() {
.append("Comment", getComment())
.append("Secure", getSecure())
.append("HttpOnly", isHttpOnly())
.append("Partitioned", isPartitioned())
.append(SAME_SITE, getSameSite())
.append("Max-Age", getMaxAge())
.append(EXPIRES, getAttribute(EXPIRES))
Expand Down

0 comments on commit e8c122c

Please sign in to comment.