Skip to content

Commit 728e038

Browse files
committed
Updating .NET cookie tests for localhost
1 parent 4680a96 commit 728e038

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

dotnet/test/common/CookieImplementationTest.cs

+34-1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,15 @@ public void ShouldBeAbleToSetDomainToTheCurrentDomain()
293293
return;
294294
}
295295

296+
// Cookies cannot be set on domain names with less than 2 dots, so
297+
// localhost is out. If we are in that boat, bail the test.
298+
string hostName = EnvironmentManager.Instance.UrlBuilder.HostName;
299+
string[] hostNameParts = hostName.Split(new char[] { '.' });
300+
if (hostNameParts.Length < 3)
301+
{
302+
Assert.Ignore("Skipping test: Cookies can only be set on fully-qualified domain names.");
303+
}
304+
296305
Uri url = new Uri(driver.Url);
297306
String host = url.Host + ":" + url.Port.ToString();
298307

@@ -353,6 +362,15 @@ public void ShouldIgnoreThePortNumberOfTheHostWhenSettingTheCookie()
353362
return;
354363
}
355364

365+
// Cookies cannot be set on domain names with less than 2 dots, so
366+
// localhost is out. If we are in that boat, bail the test.
367+
string hostName = EnvironmentManager.Instance.UrlBuilder.HostName;
368+
string[] hostNameParts = hostName.Split(new char[] { '.' });
369+
if (hostNameParts.Length < 3)
370+
{
371+
Assert.Ignore("Skipping test: Cookies can only be set on fully-qualified domain names.");
372+
}
373+
356374
Uri uri = new Uri(driver.Url);
357375
string host = string.Format("{0}:{1}", uri.Host, uri.Port);
358376
string cookieName = "name";
@@ -627,6 +645,15 @@ public void ShouldNotShowCookieAddedToDifferentPath()
627645
return;
628646
}
629647

648+
// Cookies cannot be set on domain names with less than 2 dots, so
649+
// localhost is out. If we are in that boat, bail the test.
650+
string hostName = EnvironmentManager.Instance.UrlBuilder.HostName;
651+
string[] hostNameParts = hostName.Split(new char[] { '.' });
652+
if (hostNameParts.Length < 3)
653+
{
654+
Assert.Ignore("Skipping test: Cookies can only be set on fully-qualified domain names.");
655+
}
656+
630657
driver.Url = macbethPage;
631658
IOptions options = driver.Manage();
632659
Cookie cookie = new Cookie("Lisa", "Simpson", EnvironmentManager.Instance.UrlBuilder.HostName, "/" + EnvironmentManager.Instance.UrlBuilder.Path + "IDoNotExist", null);
@@ -767,7 +794,13 @@ private bool IsValidHostNameForCookieTests(string hostname)
767794
// Reenable this when we have a better solution per DanielWagnerHall.
768795
// ChromeDriver2 has trouble with localhost. IE and Firefox don't.
769796
// return !IsIpv4Address(hostname) && "localhost" != hostname;
770-
return !IsIpv4Address(hostname) && ("localhost" != hostname && TestUtilities.IsChrome(driver));
797+
bool isLocalHostOkay = true;
798+
if ("localhost" == hostname && TestUtilities.IsChrome(driver))
799+
{
800+
isLocalHostOkay = false;
801+
}
802+
803+
return !IsIpv4Address(hostname) && isLocalHostOkay;
771804
}
772805

773806
private static bool IsIpv4Address(string addrString)

0 commit comments

Comments
 (0)