-
-
Notifications
You must be signed in to change notification settings - Fork 8k
/
CookieTest.cs
95 lines (83 loc) · 3.32 KB
/
CookieTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using NUnit.Framework;
using OpenQA.Selenium.Internal;
namespace OpenQA.Selenium
{
[TestFixture]
public class CookieTest
{
[Test]
public void CanCreateAWellFormedCookie()
{
new ReturnedCookie("Fish", "cod", "", "", DateTime.Now, false, false);
}
[Test]
public void ShouldThrowAnExceptionWhenSemiColonExistsInTheCookieAttribute()
{
Assert.That(() => new ReturnedCookie("hi;hi", "value", null, null, DateTime.Now, false, false), Throws.InstanceOf<ArgumentException>());
}
[Test]
public void ShouldThrowAnExceptionWhenTheNameIsNull()
{
Assert.That(() => new ReturnedCookie(null, "value", null, null, DateTime.Now, false, false), Throws.InstanceOf<ArgumentException>());
}
[Test]
public void ShouldThrowAnExceptionWhenSameSiteIsWrong()
{
Assert.That(() => new ReturnedCookie("name", "value", "" , "/", DateTime.Now, true, true, "Wrong"), Throws.InstanceOf<ArgumentException>());
}
[Test]
public void ShouldThrowAnExceptionWhenSameSiteIsNoneButNotSecure()
{
Assert.That(() => new ReturnedCookie("name", "value", "", "/", DateTime.Now, false, true, "None"), Throws.InstanceOf<ArgumentException>());
}
[Test]
public void CookiesShouldAllowOptionalParametersToBeSet()
{
DateTime expiry = DateTime.Now;
Cookie cookie = new Cookie ("name", "value", "test.com", "/", expiry, true, true, "None");
Assert.That(cookie.Domain, Is.EqualTo("test.com"));
Assert.That(cookie.Path, Is.EqualTo("/"));
Assert.That(cookie.IsHttpOnly, Is.True);
Assert.That(cookie.Secure, Is.True);
Assert.That(cookie.SameSite, Is.EqualTo("None"));
}
[Test]
public void CookiesShouldAllowSecureToBeSet()
{
Cookie cookie = new ReturnedCookie("name", "value", "", "/", DateTime.Now, true, false);
Assert.That(cookie.Secure, Is.True);
}
[Test]
public void SecureDefaultsToFalse()
{
Cookie cookie = new Cookie("name", "value");
Assert.That(cookie.Secure, Is.False);
}
[Test]
public void CookiesShouldAllowHttpOnlyToBeSet()
{
Cookie cookie = new ReturnedCookie("name", "value", "", "/", DateTime.Now, false, true);
Assert.That(cookie.IsHttpOnly, Is.True);
}
[Test]
public void HttpOnlyDefaultsToFalse()
{
Cookie cookie = new Cookie("name", "value");
Assert.That(cookie.IsHttpOnly, Is.False);
}
//------------------------------------------------------------------
// Tests below here are not included in the Java test suite
//------------------------------------------------------------------
[Test]
public void ShouldThrowAnExceptionWhenTheValueIsNull()
{
Assert.That(() => new ReturnedCookie("name", null, null, null, DateTime.Now, false, false), Throws.InstanceOf<ArgumentNullException>());
}
[Test]
public void ShouldAllowExpiryToBeNull()
{
Cookie cookie = new ReturnedCookie("name", "value", "", "/", null, false, false);
}
}
}