public string DecodeJson(Cookie cookie)
        {
            var json = cookie.Value;
            var value = HttpUtility.UrlDecode(json);

            return _encryptor.Decrypt(value);
        }
Exemple #2
0
        public void get_value()
        {
            var cookie = new Cookie("foo").Add(new CookieState("a", "1")).Add(new CookieState("b", "2"));

            cookie.GetValue("a").ShouldEqual("1");
            cookie.GetValue("b").ShouldEqual("2");
        }
Exemple #3
0
        public void to_string_expires()
        {
            var cookie = new Cookie("something");
            cookie.Expires = DateTime.Today.AddHours(10);

            cookie.ToString().ShouldContain("expires=" + cookie.Expires.Value.ToString("r", CultureInfo.InvariantCulture));
        }
Exemple #4
0
        public void Erase()
        {
            var cookie = new Cookie(_cookieName, "BLANK")
            {
                Expires = _time.UtcNow().AddYears(-1)
            };

            _writer.AppendCookie(cookie);
        }
Exemple #5
0
        public void can_set_value_for_single_value_cookies()
        {
            var cookie = new Cookie("a", "2");
            cookie.Value.ShouldEqual("2");

            cookie.Value = "3";

            cookie.Value.ShouldEqual("3");

            cookie.States.Single().Value.ShouldEqual("3");
        }
Exemple #6
0
        public void matches()
        {
            var cookie = new Cookie();
            cookie.Matches("a").ShouldBeFalse();

            cookie.Add(new CookieState("something"));

            cookie.Matches("a").ShouldBeFalse();
            cookie.Matches("something").ShouldBeTrue();

            cookie.Add(new CookieState("Else"));
            cookie.Matches("something").ShouldBeTrue();
            cookie.Matches("else").ShouldBeTrue();
            cookie.Matches("a").ShouldBeFalse();
        }
        public AntiForgeryData SetCookieToken(string path, string domain)
        {
            var applicationPath = _fubuApplicationFiles.RootPath;
            AntiForgeryData token = GetCookieToken();
            string name = _tokenProvider.GetTokenName(applicationPath);
            string cookieValue = _serializer.Serialize(token);

            var newCookie = new Cookie(name, HttpUtility.UrlEncode(cookieValue)) {HttpOnly = true, Domain = domain};
            if (!string.IsNullOrEmpty(path))
            {
                newCookie.Path = path;
            }
            _outputWriter.AppendCookie(newCookie);

            return token;
        }
        public Cookie CreateCookie(ISystemTime clock)
        {
            var cookie = new Cookie(_settings.Name)
            {
                HttpOnly = _settings.HttpOnly,
                Secure = _settings.Secure,
                Domain = _settings.Domain
            };

            if(_settings.Path.IsNotEmpty())
            {
                cookie.Path = _settings.Path;
            }

            cookie.Expires = _settings.ExpirationFor(clock.UtcNow());

            return cookie;
        }
Exemple #9
0
        public static Cookie ToCookie(string headerValue)
        {
            if (headerValue.IsEmpty()) return null;

            var cookie = new Cookie();

            var segments = SplitValues(headerValue).Select(x => new Segment(x.Trim()));
            segments.Each(segment => {
                string canonicalKey = segment.Key.ToLowerInvariant();

                if (_setters.Has(canonicalKey))
                {
                    _setters[canonicalKey](cookie, segment.Value);
                }
                else
                {
                    var state = CookieState.For(segment);
                    cookie.Add(state);
                }
            });

            return cookie;
        }
Exemple #10
0
 public void value_with_no_states()
 {
     var cookie = new Cookie("foo");
     cookie.Value.ShouldBeNull();
 }
Exemple #11
0
 public void value_with_more_than_one_state()
 {
     var cookie = new Cookie("a").Add(new CookieState("a1", "1"));
     cookie.Value.ShouldBeNull();
 }
Exemple #12
0
 public void value_with_only_one_state_with_only_one_value()
 {
     var cookie = new Cookie("a", "2");
     cookie.Value.ShouldEqual("2");
 }
Exemple #13
0
 public void AppendCookie(Cookie cookie)
 {
     LastCookie = cookie;
 }
 public void Update(Cookie cookie)
 {
     _writer.AppendCookie(cookie);
 }