Skip to content

Commit

Permalink
Updating .NET cookie tests for localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jul 7, 2015
1 parent 4680a96 commit 728e038
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion dotnet/test/common/CookieImplementationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ public void ShouldBeAbleToSetDomainToTheCurrentDomain()
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.");
}

Uri url = new Uri(driver.Url);
String host = url.Host + ":" + url.Port.ToString();

Expand Down Expand Up @@ -353,6 +362,15 @@ public void ShouldIgnoreThePortNumberOfTheHostWhenSettingTheCookie()
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.");
}

Uri uri = new Uri(driver.Url);
string host = string.Format("{0}:{1}", uri.Host, uri.Port);
string cookieName = "name";
Expand Down Expand Up @@ -627,6 +645,15 @@ public void ShouldNotShowCookieAddedToDifferentPath()
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.");
}

driver.Url = macbethPage;
IOptions options = driver.Manage();
Cookie cookie = new Cookie("Lisa", "Simpson", EnvironmentManager.Instance.UrlBuilder.HostName, "/" + EnvironmentManager.Instance.UrlBuilder.Path + "IDoNotExist", null);
Expand Down Expand Up @@ -767,7 +794,13 @@ private bool IsValidHostNameForCookieTests(string hostname)
// Reenable this when we have a better solution per DanielWagnerHall.
// ChromeDriver2 has trouble with localhost. IE and Firefox don't.
// return !IsIpv4Address(hostname) && "localhost" != hostname;
return !IsIpv4Address(hostname) && ("localhost" != hostname && TestUtilities.IsChrome(driver));
bool isLocalHostOkay = true;
if ("localhost" == hostname && TestUtilities.IsChrome(driver))
{
isLocalHostOkay = false;
}

return !IsIpv4Address(hostname) && isLocalHostOkay;
}

private static bool IsIpv4Address(string addrString)
Expand Down

0 comments on commit 728e038

Please sign in to comment.