Skip to content

Commit

Permalink
Fixing cookie delete bug for related domains in IE
Browse files Browse the repository at this point in the history
Also fixed up .NET cookie tests.
  • Loading branch information
jimevans committed Jul 7, 2015
1 parent 90e5c49 commit 7e6dcc1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
30 changes: 14 additions & 16 deletions cpp/iedriver/CookieManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,23 +246,21 @@ bool CookieManager::RecurseCookieDomain(const std::string& url,
const std::string& path,
const bool is_httponly) {
bool deleted = this->DeleteCookie(url, name, domain, path, is_httponly);
if (!deleted) {
size_t dot_index = domain.find_first_of('.');
if (dot_index == 0) {
return this->RecurseCookieDomain(url,
name,
domain.substr(1),
path,
is_httponly);
} else if (dot_index != std::string::npos) {
return this->RecurseCookieDomain(url,
name,
domain.substr(dot_index),
path,
is_httponly);
}
deleted = this->DeleteCookie(url, name, "", path, is_httponly);
size_t dot_index = domain.find_first_of('.');
if (dot_index == 0) {
return this->RecurseCookieDomain(url,
name,
domain.substr(1),
path,
is_httponly);
} else if (dot_index != std::string::npos) {
return this->RecurseCookieDomain(url,
name,
domain.substr(dot_index),
path,
is_httponly);
}
deleted = this->DeleteCookie(url, name, "", path, is_httponly);
return deleted;
}

Expand Down
6 changes: 5 additions & 1 deletion cpp/iedriverserver/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ available via the project downloads page. Changes in "revision" field indicate
private releases checked into the prebuilts directory of the source tree, but
not made generally available on the downloads page.

v2.46.0.5
v2.46.0.7
=========
* Fixed cookie delete bug for related domains.

v2.46.0.6
=========
* Corrected cookie add/delete logic with respect to HTTP-only cookies.

Expand Down
Binary file modified cpp/iedriverserver/IEDriverServer.rc
Binary file not shown.
Binary file modified cpp/prebuilt/Win32/Release/IEDriverServer.exe
Binary file not shown.
Binary file modified cpp/prebuilt/x64/Release/IEDriverServer.exe
Binary file not shown.
12 changes: 10 additions & 2 deletions dotnet/test/common/CookieImplementationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,22 @@ public void ShouldNotGetCookieOnDifferentDomain()
}

[Test]
[Ignore("Cannot run without creating subdomains in test environment")]
public void ShouldBeAbleToAddToADomainWhichIsRelatedToTheCurrentDomain()
{
if (!CheckIsOnValidHostNameForCookieTests())
{
return;
}

// Cookies cannot be set on domain names with less than 2 dots, so
// localhost is out. If we are in that boat, bail the test.
string hostName = EnvironmentManager.Instance.UrlBuilder.HostName;
string[] hostNameParts = hostName.Split(new char[] { '.' });
if (hostNameParts.Length < 3)
{
Assert.Ignore("Skipping test: Cookies can only be set on fully-qualified domain names.");
}

AssertCookieIsNotPresentWithName("name");

Regex replaceRegex = new Regex(".*?\\.");
Expand Down Expand Up @@ -277,7 +285,7 @@ public void ShouldBeAbleToIncludeLeadingPeriodInDomainName()

// Replace the first part of the name with a period
Regex replaceRegex = new Regex(".*?\\.");
string shorter = replaceRegex.Replace(this.hostname, ".");
string shorter = replaceRegex.Replace(this.hostname, ".", 1);
Cookie cookie = new Cookie("name", "value", shorter, "/", DateTime.Now.AddSeconds(100000));

driver.Manage().Cookies.AddCookie(cookie);
Expand Down

0 comments on commit 7e6dcc1

Please sign in to comment.