Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] handle getNamedCookie and deleteNamedCookie for empty strings #15092

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ public void addCookie(Cookie cookie) {

@Override
public void deleteCookieNamed(String name) {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Cookie name cannot be empty");
}
execute(DriverCommand.DELETE_COOKIE(name));
}

Expand Down Expand Up @@ -927,6 +930,9 @@ public Set<Cookie> getCookies() {

@Override
public Cookie getCookieNamed(String name) {
if (name == null || name.isBlank()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To fix the underlying issue, we need to add the endpoint "/session/sessionId/cookie/name" and use that to get the cookie

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see defineCommand(GET_COOKIE, get(cookie + "/:name")); in java/src/org/openqa/selenium/remote/codec/AbstractHttpCommandCodec.java

throw new IllegalArgumentException("Cookie name cannot be empty");
}
Set<Cookie> allCookies = getCookies();
for (Cookie cookie : allCookies) {
if (cookie.getName().equals(name)) {
Expand Down
13 changes: 13 additions & 0 deletions java/test/org/openqa/selenium/CookieImplementationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.openqa.selenium.testing.drivers.Browser.ALL;
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
Expand Down Expand Up @@ -503,6 +504,18 @@ public void testDeleteNotExistedCookie() {
driver.manage().deleteCookieNamed(key);
}

@Test
public void testDeleteEmptyNamedCookie() {
assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(""));
assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(" "));
}

@Test
public void testGetEmptyNamedCookie() {
assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(""));
assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(" "));
}

@Test
@Ignore(value = ALL, reason = "Non W3C conformant")
public void testShouldDeleteOneOfTheCookiesWithTheSameName() {
Expand Down