예제 #1
0
        public void CookieWithNonExistingKey()
        {
            var cookie = WebCookie.FromString("foo", loose: true);

            Assert.AreEqual("", cookie.Key);
            Assert.AreEqual("foo", cookie.Value);
            Assert.AreEqual(null, cookie.Path);
            Assert.IsFalse(cookie.Expires.HasValue);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);
        }
예제 #2
0
        public void CookieWithWeirdFormat()
        {
            var cookie = WebCookie.FromString("=foo=bar", loose: true);

            Assert.AreEqual("foo", cookie.Key);
            Assert.AreEqual("bar", cookie.Value);
            Assert.AreEqual(null, cookie.Path);
            Assert.IsFalse(cookie.Expires.HasValue);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);
        }
예제 #3
0
        public void CookieWithQuotesSpacesInTheValue()
        {
            var cookie = WebCookie.FromString("a=\"one two three\"");

            Assert.AreEqual("a", cookie.Key);
            Assert.AreEqual("\"one two three\"", cookie.Value);
            Assert.AreEqual(null, cookie.Path);
            Assert.IsFalse(cookie.Expires.HasValue);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);
        }
예제 #4
0
        public void CookieWithNonAsciiInValue()
        {
            var cookie = WebCookie.FromString("farbe=weiß");

            Assert.AreEqual("farbe", cookie.Key);
            Assert.AreEqual("weiß", cookie.Value);
            Assert.AreEqual(null, cookie.Path);
            Assert.IsFalse(cookie.Expires.HasValue);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);
        }
예제 #5
0
        public void GoogleGaps()
        {
            var cookie = WebCookie.FromString("GAPS=1:A1aaaaAaAAa1aaAaAaaAAAaaa1a11a:aaaAaAaAa-aaaA1-;Path=/;Expires=Thu, 17-Apr-2014 02:12:29 GMT;Secure;HttpOnly");

            Assert.AreEqual("GAPS", cookie.Key);
            Assert.AreEqual("1:A1aaaaAaAAa1aaAaAaaAAAaaa1a11a:aaaAaAaAa-aaaA1-", cookie.Value);
            Assert.AreEqual("/", cookie.Path);
            Assert.AreEqual(new DateTime(2014, 4, 17), cookie.Expires.Value.Date);
            Assert.IsTrue(cookie.IsSecure);
            Assert.IsTrue(cookie.IsHttpOnly);
        }
예제 #6
0
        public void CookieWithManyEqualSigns()
        {
            var cookie = WebCookie.FromString("queryPref=b=c&d=e; Path=/f=g; Expires=Thu, 17 Apr 2014 02:12:29 GMT; HttpOnly");

            Assert.AreEqual("queryPref", cookie.Key);
            Assert.AreEqual("b=c&d=e", cookie.Value);
            Assert.AreEqual("/f=g", cookie.Path);
            Assert.AreEqual(new DateTime(2014, 4, 17), cookie.Expires.Value.Date);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsTrue(cookie.IsHttpOnly);
        }
예제 #7
0
        public void ExpiringCookie()
        {
            var cookie = WebCookie.FromString("a=bcd; Expires=Tue, 18 Oct 2011 07:05:03 GMT");

            Assert.AreEqual("a", cookie.Key);
            Assert.AreEqual("bcd", cookie.Value);
            Assert.IsTrue(cookie.Validate());
            Assert.AreEqual(null, cookie.Path);
            Assert.AreEqual(null, cookie.Domain);
            Assert.AreEqual(new DateTime(2011, 10, 18), cookie.Expires.Value.Date);
            Assert.AreEqual(0, cookie.Extensions.Count());
        }
예제 #8
0
        public void SimpleCookie()
        {
            var cookie = WebCookie.FromString("a=bcd");

            Assert.AreEqual("a", cookie.Key);
            Assert.AreEqual("bcd", cookie.Value);
            Assert.IsTrue(cookie.Validate());
            Assert.AreEqual(null, cookie.Path);
            Assert.AreEqual(null, cookie.Domain);
            Assert.IsFalse(cookie.Expires.HasValue);
            Assert.AreEqual(0, cookie.Extensions.Count());
        }
예제 #9
0
        public void HttpOnlyCookieWithValue()
        {
            var cookie = WebCookie.FromString("a=b; HttpOnly=xyxz");

            Assert.AreEqual("a", cookie.Key);
            Assert.AreEqual("b", cookie.Value);
            Assert.AreEqual(null, cookie.Path);
            Assert.AreEqual(null, cookie.Domain);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsTrue(cookie.IsHttpOnly);
            Assert.IsFalse(cookie.Expires.HasValue);
            Assert.AreEqual(0, cookie.Extensions.Count());
        }
예제 #10
0
        public void CookieWithTrailingSemicolons()
        {
            var cookie = WebCookie.FromString("a=b;;;;");

            Assert.AreEqual("a", cookie.Key);
            Assert.AreEqual("b", cookie.Value);
            Assert.AreEqual(null, cookie.Path);
            Assert.AreEqual(null, cookie.Domain);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);
            Assert.IsFalse(cookie.Expires.HasValue);
            Assert.AreEqual(0, cookie.Extensions.Count());
        }
예제 #11
0
        public void CookieWithInvalidExpirationDate()
        {
            var cookie = WebCookie.FromString("a=b; Expires=xyzzy");

            Assert.AreEqual("a", cookie.Key);
            Assert.AreEqual("b", cookie.Value);
            Assert.AreEqual(null, cookie.Path);
            Assert.AreEqual(null, cookie.Domain);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);
            Assert.IsFalse(cookie.Expires.HasValue);
            Assert.AreEqual(0, cookie.Extensions.Count());
        }
예제 #12
0
        public void ExpiringCookieWithPath()
        {
            var cookie = WebCookie.FromString("a=\"xyzzy!\"; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Path=/aBc");

            Assert.AreEqual("a", cookie.Key);
            Assert.AreEqual("\"xyzzy!\"", cookie.Value);
            Assert.AreEqual("/aBc", cookie.Path);
            Assert.AreEqual(null, cookie.Domain);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);
            Assert.AreEqual(new DateTime(2011, 10, 18), cookie.Expires.Value.Date);
            Assert.AreEqual(0, cookie.Extensions.Count());
        }
예제 #13
0
        public void CookieWitUppercaseDomain()
        {
            var cookie = WebCookie.FromString("a=b; domain=EXAMPLE.COM");

            Assert.AreEqual("a", cookie.Key);
            Assert.AreEqual("b", cookie.Value);
            Assert.AreEqual(null, cookie.Path);
            Assert.AreEqual("example.com", cookie.Domain);
            Assert.IsFalse(cookie.MaxAge.HasValue);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);
            Assert.IsFalse(cookie.Expires.HasValue);
            Assert.AreEqual(0, cookie.Extensions.Count());
        }
예제 #14
0
        public void CookieWithNegativeMaxAge()
        {
            var cookie = WebCookie.FromString("a=b; Max-Age=-1");

            Assert.AreEqual("a", cookie.Key);
            Assert.AreEqual("b", cookie.Value);
            Assert.AreEqual(null, cookie.Path);
            Assert.AreEqual(null, cookie.Domain);
            Assert.AreEqual(-1, cookie.MaxAge.Value);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);
            Assert.IsFalse(cookie.Expires.HasValue);
            Assert.AreEqual(0, cookie.Extensions.Count());
        }
예제 #15
0
        public void CompleteCookie()
        {
            var cookie = WebCookie.FromString("abc=\"xyzzy!\"; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Path=/aBc; Domain=example.com; Secure; HTTPOnly; Max-Age=1234; Foo=Bar; Baz");

            Assert.AreEqual("abc", cookie.Key);
            Assert.AreEqual("\"xyzzy!\"", cookie.Value);
            Assert.AreEqual("/aBc", cookie.Path);
            Assert.AreEqual("example.com", cookie.Domain);
            Assert.IsTrue(cookie.IsSecure);
            Assert.IsTrue(cookie.IsHttpOnly);
            Assert.AreEqual(1234, cookie.MaxAge.Value);
            Assert.AreEqual(new DateTime(2011, 10, 18), cookie.Expires.Value.Date);
            Assert.AreEqual("Foo=Bar", cookie.Extensions.Skip(0).First());
            Assert.AreEqual("Baz", cookie.Extensions.Skip(1).First());
        }