Ejemplo n.º 1
0
        public void ParseCookies_with_unquoted_values2()
        {
            List <DreamCookie> result = DreamCookie.ParseCookieHeader("__utma=134392366.2030730348.1275932450.1276553042.1276556836.19; __utmz=134392366.1276207881.9.3.utmcsr=developer.mindtouch.com|utmccn=(referral)|utmcmd=referral|utmcct=/User:arnec/bugs; _mkto_trk=id:954-WGP-507&token:_mch-mindtouch.com-1270756717014-83706; WRUID=0; __kti=1274382964652,http%3A%2F%2Fwww.mindtouch.com%2F,; __ktv=2f4-f02d-634b-51e2128b724d7c2; __qca=P0-2102347259-1274460371553; PHPSESSID=307e779182909ab37932b4dffe77c40a; __utmc=134392366; __kts=1274382964673,http%3A%2F%2Fwww.mindtouch.com%2F,; __ktt=631f-d0a2-648e-e0b128b724d7c2; authtoken=\"1_634121336269193470_4254e33b49bc1ee0a72c5716200e296b\"; __utmb=134392366.6.10.1276556836");

            Assert.AreEqual(13, result.Count);
            Assert.AreEqual("__utma", result[0].Name);
            Assert.AreEqual("134392366.2030730348.1275932450.1276553042.1276556836.19", result[0].Value);
            Assert.AreEqual("__utmz", result[1].Name);
            Assert.AreEqual("134392366.1276207881.9.3.utmcsr=developer.mindtouch.com|utmccn=(referral)|utmcmd=referral|utmcct=/User:arnec/bugs", result[1].Value);
            Assert.AreEqual("_mkto_trk", result[2].Name);
            Assert.AreEqual("id:954-WGP-507&token:_mch-mindtouch.com-1270756717014-83706", result[2].Value);
            Assert.AreEqual("WRUID", result[3].Name);
            Assert.AreEqual("0", result[3].Value);
            Assert.AreEqual("__kti", result[4].Name);
            Assert.AreEqual("1274382964652,http%3A%2F%2Fwww.mindtouch.com%2F,", result[4].Value);
            Assert.AreEqual("__ktv", result[5].Name);
            Assert.AreEqual("2f4-f02d-634b-51e2128b724d7c2", result[5].Value);
            Assert.AreEqual("__qca", result[6].Name);
            Assert.AreEqual("P0-2102347259-1274460371553", result[6].Value);
            Assert.AreEqual("PHPSESSID", result[7].Name);
            Assert.AreEqual("307e779182909ab37932b4dffe77c40a", result[7].Value);
            Assert.AreEqual("__utmc", result[8].Name);
            Assert.AreEqual("134392366", result[8].Value);
            Assert.AreEqual("__kts", result[9].Name);
            Assert.AreEqual("1274382964673,http%3A%2F%2Fwww.mindtouch.com%2F,", result[9].Value);
            Assert.AreEqual("__ktt", result[10].Name);
            Assert.AreEqual("631f-d0a2-648e-e0b128b724d7c2", result[10].Value);
            Assert.AreEqual("authtoken", result[11].Name);
            Assert.AreEqual("1_634121336269193470_4254e33b49bc1ee0a72c5716200e296b", result[11].Value);
            Assert.AreEqual("__utmb", result[12].Name);
            Assert.AreEqual("134392366.6.10.1276556836", result[12].Value);
        }
        //--- Constructors ---

        /// <summary>
        /// Create a new subscription set.
        /// </summary>
        /// <param name="owner">Owner uri.</param>
        /// <param name="version">Version serial number.</param>
        /// <param name="cookie">Pub sub location access cookie.</param>
        /// <param name="childSubscriptions">Subscriptions.</param>
        public PubSubSubscriptionSet(XUri owner, long version, DreamCookie cookie, params PubSubSubscription[] childSubscriptions)
        {
            Owner   = owner;
            Version = version;
            Dictionary <string, PubSubSubscription> subs = new Dictionary <string, PubSubSubscription>();

            foreach (PubSubSubscription sub in childSubscriptions)
            {
                foreach (XUri channel in sub.Channels)
                {
                    if (channel.Scheme == "pubsub")
                    {
                        // pubsub scheme is for PubSubService internal use only, so it should never be aggregated
                        continue;
                    }
                    XUri[] resources = (sub.Resources == null || sub.Resources.Length == 0) ? new XUri[] { null } : sub.Resources;
                    foreach (XUri resource in resources)
                    {
                        PubSubSubscription combo;
                        string             key = channel + ":" + resource;
                        subs.TryGetValue(key, out combo);
                        subs[key] = PubSubSubscription.MergeForChannelAndResource(channel, resource, this, cookie, sub, combo);
                    }
                }
            }
            Subscriptions = new PubSubSubscription[subs.Count];
            subs.Values.CopyTo(Subscriptions, 0);
            MaxFailures = MAX_FAILURES;
        }
Ejemplo n.º 3
0
        protected virtual Yield PutConfig(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            XDoc config = request.ToDocument();

            if (config.Name != "config")
            {
                throw new DreamBadRequestException("bad document type");
            }
            if (IsStarted)
            {
                throw new DreamBadRequestException("service must be stopped first");
            }
            _timerFactory = TaskTimerFactory.Create(this);

            // configure service container
            var lifetimeScope = _env.CreateServiceLifetimeScope(this, (c, b) => PreInitializeLifetimeScope(c, b, config));

            // call container-less start (which contains shared start logic)
            yield return(Coroutine.Invoke(Start, request.ToDocument(), new Result()));

            // call start with container for sub-classes that want to resolve instances at service start
            yield return(Coroutine.Invoke(Start, config, lifetimeScope, new Result()));

            response.Return(DreamMessage.Ok(new XDoc("service-info")
                                            .Start("private-key")
                                            .Add(DreamCookie.NewSetCookie("service-key", PrivateAccessKey, Self.Uri).AsSetCookieDocument)
                                            .End()
                                            .Start("internal-key")
                                            .Add(DreamCookie.NewSetCookie("service-key", InternalAccessKey, Self.Uri).AsSetCookieDocument)
                                            .End()
                                            ));
        }
Ejemplo n.º 4
0
        public void Render_SetCookie_header_for_domainname_does_start_with_dot()
        {
            string header = DreamCookie.NewSetCookie("foo", "bar", new XUri("http://foo.com/x/y/z")).ToSetCookieHeader();

            Assert.IsTrue(header.Contains("Path=/x/y/z"), "path is bad: " + header);
            Assert.IsTrue(header.Contains("Domain=.foo.com"), "domain is bad: " + header);
        }
Ejemplo n.º 5
0
        public void Render_SetCookie_header_for_localhost_does_not_start_with_dot()
        {
            string header = DreamCookie.NewSetCookie("foo", "bar", new XUri("http://localhost/x/y/z")).ToSetCookieHeader();

            Assert.IsTrue(header.Contains("Path=/x/y/z"), "path is bad: " + header);
            Assert.IsFalse(header.Contains("Domain"), "domain found: " + header);
        }
Ejemplo n.º 6
0
 public DreamMessage SyncDreamCookies(
     [Cookie] DreamCookie x,
     [Cookie] string y
     )
 {
     return(Response(new XDoc("r").Elem("x", x.Value).Elem("y", y)));
 }
Ejemplo n.º 7
0
        public void SetCookie_to_header_and_back()
        {
            DreamCookie cookie1 = DreamCookie.NewSetCookie(
                "foo",
                "bar",
                new XUri("http://abc.com/path"),
                DateTime.Now.AddDays(1),
                true,
                "blah blah",
                new XUri("http://comment.com/blah"));
            string             header  = cookie1.ToSetCookieHeader();
            List <DreamCookie> cookies = DreamCookie.ParseSetCookieHeader(header);

            Assert.AreEqual(1, cookies.Count);
            DreamCookie cookie2 = cookies[0];

            Assert.AreEqual(cookie1.Comment, cookie2.Comment);
            Assert.AreEqual(cookie1.CommentUri, cookie2.CommentUri);
            Assert.AreEqual(cookie1.Domain, cookie2.Domain);
            Assert.AreEqual(cookie1.Expires, cookie2.Expires);
            Assert.AreEqual(cookie1.Expired, cookie2.Expired);
            Assert.AreEqual(cookie1.Name, cookie2.Name);
            Assert.AreEqual(cookie1.Path, cookie2.Path);
            Assert.AreEqual(cookie1.Secure, cookie2.Secure);
            Assert.AreEqual(cookie1.Uri, cookie2.Uri);
            Assert.AreEqual(cookie1.Value, cookie2.Value);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Perform shutdown cleanup of a service instance.
        /// </summary>
        /// <remarks>
        /// Should not be manually invoked.
        /// </remarks>
        /// <param name="result">Synchronization handle for coroutine invocation.</param>
        /// <returns>Iterator used by <see cref="Coroutine"/> execution environment.</returns>
        protected virtual Yield Stop(Result result)
        {
            // ungrant owner and parent, otherwise they end up with thousands of grants
            DreamCookie cookie = DreamCookie.NewSetCookie("service-key", string.Empty, Self.Uri, DateTime.UtcNow);

            // ignore if these operations fail since we're shutting down anyway
            yield return(Env.At("@grants").Post(DreamMessage.Ok(cookie.AsSetCookieDocument), new Result <DreamMessage>(TimeSpan.MaxValue)).CatchAndLog(_log));

            if (Owner != null)
            {
                yield return(Owner.At("@grants").Post(DreamMessage.Ok(cookie.AsSetCookieDocument), new Result <DreamMessage>(TimeSpan.MaxValue)).CatchAndLog(_log));
            }
            _log.Debug("Stop");

            // reset fields
            _self    = null;
            _owner   = null;
            _storage = null;
            _config  = XDoc.Empty;
            _apikey  = null;
            _cookies.Clear();
            _license = null;
            _env.DisposeServiceContainer(this);

            // we're done
            result.Return();
        }
Ejemplo n.º 9
0
 public override DreamAccess DetermineAccess(DreamContext context, DreamMessage request)
 {
     if (context.Feature.Signature.StartsWith("subscribers/"))
     {
         string id = context.GetParam("id", null);
         PubSubSubscriptionSet set = _dispatcher[id];
         if (set != null)
         {
             string accessKey = context.GetParam("access-key", null);
             if (string.IsNullOrEmpty(accessKey))
             {
                 DreamCookie cookie = DreamCookie.GetCookie(request.Cookies, "access-key");
                 if (cookie != null)
                 {
                     accessKey = cookie.Value;
                 }
             }
             if (StringUtil.EqualsInvariant(set.AccessKey, accessKey))
             {
                 return(DreamAccess.Private);
             }
             _log.DebugFormat("no matching access-key in query or cookie for location '{0}'", id);
         }
         else
         {
             _log.DebugFormat("no subscription set for location '{0}'", id);
         }
     }
     return(base.DetermineAccess(context, request));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Add a header.
 /// </summary>
 /// <param name="name">Header name.</param>
 /// <param name="value">Header value.</param>
 /// <returns>Current instance.</returns>
 public DreamHeaders Add(string name, string value)
 {
     if (name == COOKIE)
     {
         Cookies.AddRange(DreamCookie.ParseCookieHeader(value));
     }
     else if (name == SET_COOKIE)
     {
         Cookies.AddRange(DreamCookie.ParseSetCookieHeader(value));
     }
     else
     {
         Entry entry;
         if (_headers.TryGetValue(name, out entry))
         {
             entry.Last.Next = new Entry(value);
         }
         else
         {
             // create a new entry
             _headers[name] = new Entry(value);
         }
     }
     return(this);
 }
Ejemplo n.º 11
0
        private DreamMessage BuildSetAuthTokenResponse(string authToken, XUri redirect)
        {
            DreamMessage responseMsg;

            if (redirect == null)
            {
                responseMsg = DreamMessage.Ok(MimeType.TEXT_UTF8, authToken);
            }
            else
            {
                responseMsg = DreamMessage.Redirect(redirect);
            }
            // set expiration time, if one is provided
            DateTime expires = DateTime.MinValue; // Default to no expiration attribute (session cookie)
            TimeSpan authCookieExpirationTime = DekiContext.Current.Instance.AuthCookieExpirationTime;

            if (authCookieExpirationTime.TotalSeconds > 0)
            {
                expires = DateTime.UtcNow.Add(authCookieExpirationTime);
            }

            // add 'Set-Cookie' header
            responseMsg.Cookies.Add(DreamCookie.NewSetCookie(AUTHTOKEN_COOKIENAME, authToken, Self.Uri.AsPublicUri().WithoutPathQueryFragment(), expires));

            // add 'P3P' header for IE
            responseMsg.Headers["P3P"] = "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"";
            return(responseMsg);
        }
Ejemplo n.º 12
0
        public void Parse_cookie_without_path_or_domain()
        {
            List <DreamCookie> cookies = DreamCookie.ParseCookieHeader("foo=\"bar\"");

            Assert.IsNull(cookies[0].Path);
            Assert.IsNull(cookies[0].Domain);
        }
Ejemplo n.º 13
0
        //--- Constructors ---

        /// <summary>
        /// Create a new dispatcher.
        /// </summary>
        /// <param name="config">Configuration instance injected from pub sub service.</param>
        public Dispatcher(DispatcherConfig config)
        {
            _owner = config.ServiceUri.AsServerUri();
            _serviceKeySetCookie = config.ServiceAccessCookie;
            _combinedSet         = new PubSubSubscriptionSet(_owner, 0, _serviceKeySetCookie);
            _dispatchQueue       = new ProcessingQueue <DispatcherEvent>(DispatchFromQueue, 10);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Add a range of headers.
        /// </summary>
        /// <param name="headers">Key value pair collection</param>
        /// <returns>Current instance.</returns>
        public DreamHeaders AddRange(IEnumerable <KeyValuePair <string, string> > headers)
        {
            if (headers != null)
            {
                foreach (var header in headers)
                {
                    if (header.Key.EqualsInvariantIgnoreCase(COOKIE))
                    {
                        if (!string.IsNullOrEmpty(header.Value))
                        {
                            Cookies.AddRange(DreamCookie.ParseCookieHeader(header.Value));
                        }
                    }
                    else if (header.Key.EqualsInvariantIgnoreCase(SET_COOKIE))
                    {
                        if (!string.IsNullOrEmpty(header.Value))
                        {
                            Cookies.AddRange(DreamCookie.ParseSetCookieHeader(header.Value));
                        }
                    }
                    else if (header.Key.EqualsInvariantIgnoreCase(ETAG) || header.Key.EndsWithInvariantIgnoreCase(IF_NONE_MATCH))
                    {
                        // Note: Since ETAG may be quoted, strip quotes from ETAG and its counter-part If-None-Match
                        var value = header.Value;
                        if (!string.IsNullOrEmpty(value))
                        {
                            if ((value.StartsWith("\"") && value.EndsWith("\"")) || (value.StartsWith("'") && value.EndsWith("'")))
                            {
                                value = value.Substring(1, value.Length - 2);
                            }
                            _headers[header.Key] = new Entry(value);
                        }
                    }
                    else
                    {
                        // Note (arnec): assume that there are no multi-value values
                        Entry existing;

                        // find existing entry
                        if (_headers.TryGetValue(header.Key, out existing))
                        {
                            existing = existing.Last;
                        }

                        // add new entries
                        if (existing == null)
                        {
                            existing             = new Entry(header.Value);
                            _headers[header.Key] = existing;
                        }
                        else
                        {
                            existing.Next = new Entry(header.Value);
                        }
                    }
                }
            }
            return(this);
        }
Ejemplo n.º 15
0
        private Yield CreateService_Helper(string path, string sid, XDoc config, Result <Plug> result)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (sid == null)
            {
                throw new ArgumentNullException("sid");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // check if we have a licensekey for the requested SID
            string serviceLicense = TryGetServiceLicense(XUri.TryParse(sid) ?? XUri.Localhost);

            // add parameters to config document
            Plug plug = Self.AtPath(path);

            config.Root
            .Elem("path", plug.Uri.Path)
            .Elem("sid", sid)

            // add 'owner' and make sure we keep it in 'local://' format
            .Elem("uri.owner", Self.Uri.ToString())

            // add 'internal' access key
            .Add(DreamCookie.NewSetCookie("service-key", InternalAccessKey, Self.Uri).AsSetCookieDocument)

            // add optional 'service-license' token
            .Elem("service-license", serviceLicense);

            // inject parent apikey if apikey not defined
            if (config["apikey"].IsEmpty)
            {
                config.Root.Elem("apikey", _apikey);
            }
            // post to host to create service
            Result <DreamMessage> res;

            yield return(res = Env.At("services").Post(config, new Result <DreamMessage>(TimeSpan.MaxValue)));

            if (!res.Value.IsSuccessful)
            {
                if (res.Value.HasDocument)
                {
                    string message = res.Value.ToDocument()[".//message"].AsText.IfNullOrEmpty("unknown error");
                    throw new DreamResponseException(res.Value, string.Format("unable to initialize service ({0})", message));
                }
                else
                {
                    throw new DreamResponseException(res.Value, string.Format("unable to initialize service ({0})", res.Value.ToText()));
                }
            }
            result.Return(plug);
            yield break;
        }
Ejemplo n.º 16
0
 internal Yield PostGrant(DreamContext context, DreamMessage request, Result <DreamMessage> response)
 {
     lock (Cookies) {
         Cookies.Update(DreamCookie.ParseAllSetCookieNodes(request.ToDocument()), null);
     }
     response.Return(DreamMessage.Ok());
     yield break;
 }
Ejemplo n.º 17
0
        public void ParseCookies2()
        {
            List <DreamCookie> cookies = DreamCookie.ParseCookieHeader("Customer=\"WILE_E_COYOTE\"; $Path=\"/acme\"");

            Assert.AreEqual(1, cookies.Count, "failed to parse cookies");
            Assert.AreEqual("Customer", cookies[0].Name, "bad cookie name");
            Assert.AreEqual("WILE_E_COYOTE", cookies[0].Value, "bad cookie value");
            Assert.AreEqual("/acme", cookies[0].Path, "bad cookie path");
        }
Ejemplo n.º 18
0
        private DreamCookieJar GetJar(XDoc setCookieElement)
        {
            DreamCookieJar     jar        = new DreamCookieJar();
            List <DreamCookie> collection = new List <DreamCookie>();

            collection.Add(DreamCookie.ParseSetCookie(setCookieElement));
            jar.Update(collection, null);
            return(jar);
        }
Ejemplo n.º 19
0
        public void ParseBadCookie5()
        {
            var cookies = DreamCookie.ParseCookieHeader("  foo=\"bar\", hello=wo;;rld; authtoken=\"1234\"  ");

            Assert.AreEqual(4, cookies.Count, "Failed to parse cookies, wrong number of resulting cookies");
            Assert.AreEqual(cookies[0].Name, "foo", "bad cookie name");
            Assert.AreEqual(cookies[0].Value, "bar", "bad cookie value");
            Assert.AreEqual(cookies[3].Name, "authtoken", "bad cookie name");
            Assert.AreEqual(cookies[3].Value, "1234", "bad cookie value");
        }
Ejemplo n.º 20
0
        public void Parse_2_cookies_separated_by_semicolon()
        {
            List <DreamCookie> cookies = DreamCookie.ParseCookieHeader("PHPSESSID=663e17bc2eaef4e355c6e6fe1bb86c04; authtoken=1_633644446772281250_c3dd88ad4539197ef12f3614e91fec8f");

            Assert.AreEqual(2, cookies.Count);
            Assert.AreEqual("PHPSESSID", cookies[0].Name);
            Assert.AreEqual("663e17bc2eaef4e355c6e6fe1bb86c04", cookies[0].Value);
            Assert.AreEqual("authtoken", cookies[1].Name);
            Assert.AreEqual("1_633644446772281250_c3dd88ad4539197ef12f3614e91fec8f", cookies[1].Value);
        }
Ejemplo n.º 21
0
        public void ParseBadCookie1()
        {
            var cookies = DreamCookie.ParseCookieHeader("foo=\"bar\"; [index.php]scayt_verLang=5; authtoken=\"1234\"");

            Assert.AreEqual(3, cookies.Count, "Failed to parse cookies, wrong number of resulting cookies");
            Assert.AreEqual(cookies[0].Name, "foo", "bad cookie name");
            Assert.AreEqual(cookies[0].Value, "bar", "bad cookie value");
            Assert.AreEqual(cookies[2].Name, "authtoken", "bad cookie name");
            Assert.AreEqual(cookies[2].Value, "1234", "bad cookie value");
        }
Ejemplo n.º 22
0
        public void Parse_5_cookies_separated_by_semicolon()
        {
            List <DreamCookie> cookies = DreamCookie.ParseCookieHeader("authtoken=\"3_633644459231333750_74b1192b1846f065523d01ac18c772c5\"; PHPSESSID=34c4b18a50a91dd99adb1ed1e6b570cb; __utma=14492279.2835659202033839600.1228849092.1228849092.1228849092.1; __utmc=14492279; __utmz=14492279.1228849092.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)");

            Assert.AreEqual(5, cookies.Count);
            Assert.AreEqual("authtoken", cookies[0].Name);
            Assert.AreEqual("3_633644459231333750_74b1192b1846f065523d01ac18c772c5", cookies[0].Value);
            Assert.AreEqual("PHPSESSID", cookies[1].Name);
            Assert.AreEqual("34c4b18a50a91dd99adb1ed1e6b570cb", cookies[1].Value);
        }
Ejemplo n.º 23
0
        public void ParseBadCookie3()
        {
            var cookies = DreamCookie.ParseCookieHeader("  foo=\"bar\", lithiumLogin:successfactors=~2acHBr09HxytcqIXV~eVqhSr8s74VfDTjhQ8XU615EaYeGn-7OdDSN70BshVnsYG71yPbJvKPoZzHl05KP; authtoken=\"1234\"  ");

            Assert.AreEqual(3, cookies.Count, "Failed to parse cookies, wrong number of resulting cookies");
            Assert.AreEqual(cookies[0].Name, "foo", "bad cookie name");
            Assert.AreEqual(cookies[0].Value, "bar", "bad cookie value");
            Assert.AreEqual(cookies[2].Name, "authtoken", "bad cookie name");
            Assert.AreEqual(cookies[2].Value, "1234", "bad cookie value");
        }
Ejemplo n.º 24
0
        public void GetCookie_with_no_path()
        {
            List <DreamCookie> cookies = new List <DreamCookie>();

            cookies.Add(new DreamCookie("foo", "bar", null));
            DreamCookie c = DreamCookie.GetCookie(cookies, "foo");

            Assert.IsNotNull(c);
            Assert.AreEqual("bar", c.Value);
        }
Ejemplo n.º 25
0
        //--- Methods ---
        protected override Yield Start(XDoc config, Result result)
        {
            yield return(Coroutine.Invoke(base.Start, config, new Result()));

            _varnish            = Plug.New(Config["uri.varnish"].AsUri);
            _deki               = Plug.New(Config["uri.deki"].AsUri);
            _apikey             = Config["apikey"].AsText;
            _delayPurgeTimespan = TimeSpan.FromSeconds(config["varnish-purge-delay"].AsInt ?? 10);
            var dispatcher = new UpdateRecordDispatcher(OnQueueExpire);

            _updateDelayQueue = new UpdateDelayQueue(_delayPurgeTimespan, dispatcher);

            // set up subscription for pubsub
            XDoc subscriptionSet = new XDoc("subscription-set")
                                   .Elem("uri.owner", Self.Uri)
                                   .Start("subscription")
                                   .Add(DreamCookie.NewSetCookie("service-key", InternalAccessKey, Self.Uri).AsSetCookieDocument)
                                   .Elem("channel", "event://*/deki/pages/create")
                                   .Elem("channel", "event://*/deki/pages/move")
                                   .Elem("channel", "event://*/deki/pages/update")
                                   .Elem("channel", "event://*/deki/pages/delete")
                                   .Elem("channel", "event://*/deki/pages/revert")
                                   .Elem("channel", "event://*/deki/pages/createalias")
                                   .Elem("channel", "event://*/deki/pages/tags/update")
                                   .Elem("channel", "event://*/deki/pages/dependentschanged/comments/create")
                                   .Elem("channel", "event://*/deki/pages/dependentschanged/comments/update")
                                   .Elem("channel", "event://*/deki/pages/dependentschanged/comments/delete")
                                   .Elem("channel", "event://*/deki/pages/dependentschanged/files/create")
                                   .Elem("channel", "event://*/deki/pages/dependentschanged/files/update")
                                   .Elem("channel", "event://*/deki/pages/dependentschanged/files/delete")
                                   .Elem("channel", "event://*/deki/pages/dependentschanged/files/move")
                                   .Elem("channel", "event://*/deki/pages/dependentschanged/files/restore")
                                   .Elem("channel", "event://*/deki/files/create")
                                   .Elem("channel", "event://*/deki/files/update")
                                   .Elem("channel", "event://*/deki/files/delete")
                                   .Elem("channel", "event://*/deki/files/move")
                                   .Elem("channel", "event://*/deki/files/restore")
                                   .Start("recipient")
                                   .Attr("authtoken", _apikey)
                                   .Elem("uri", Self.Uri.At("queue"))
                                   .End()
                                   .End();
            Result <DreamMessage> subscriptionResult;

            yield return(subscriptionResult = PubSub.At("subscribers").PostAsync(subscriptionSet));

            string accessKey = subscriptionResult.Value.ToDocument()["access-key"].AsText;
            XUri   location  = subscriptionResult.Value.Headers.Location;

            Cookies.Update(DreamCookie.NewSetCookie("access-key", accessKey, location), null);
            _subscriptionLocation = location.AsLocalUri().WithoutQuery();
            _log.DebugFormat("subscribed VarnishPurgeService for events at {0}", _subscriptionLocation);
            result.Return();
        }
Ejemplo n.º 26
0
        public void SetCookie_without_uri()
        {
            DreamCookie cookie = DreamCookie.NewSetCookie("foo", "bar", null);

            Assert.IsNull(cookie.Path);
            Assert.IsNull(cookie.Domain);
            string cookieHeader = cookie.ToSetCookieHeader();

            Assert.IsFalse(cookieHeader.Contains("Path"));
            Assert.IsFalse(cookieHeader.Contains("Domain"));
        }
Ejemplo n.º 27
0
        public void ParseCookies5()
        {
            List <DreamCookie> result = DreamCookie.ParseCookieHeader("Customer=WILE_E_COYOTE; $Path=\"/acme\", Part_Number=\"Rocket \\\"Launcher\\\" 0001\"; $Path=\"/acme\"");

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("Customer", result[0].Name);
            Assert.AreEqual("WILE_E_COYOTE", result[0].Value);
            Assert.AreEqual("/acme", result[0].Path);
            Assert.AreEqual("Part_Number", result[1].Name);
            Assert.AreEqual("Rocket \"Launcher\" 0001", result[1].Value);
            Assert.AreEqual("/acme", result[1].Path);
        }
Ejemplo n.º 28
0
        public void TestCookie2()
        {
            Plug         test    = _host.At("test");
            DreamMessage request = DreamMessage.Ok();
            DreamCookie  cookie  = new DreamCookie("test-cookie", "test-value", null);

            request.Cookies.Add(cookie);
            DreamMessage response = test.Post(request);

            Assert.AreEqual(DreamStatus.Ok, response.Status);
            Assert.IsFalse(response.ToDocument()["body"].IsEmpty);
            Assert.AreEqual(cookie.ToString(), DreamCookie.ParseCookie(response.ToDocument()["headers/cookie"]).ToString());
        }
Ejemplo n.º 29
0
        public void ParseCookies7()
        {
            List <DreamCookie> cookies = new List <DreamCookie>();

            cookies.Add(new DreamCookie("Customer", "WILE_E_COYOTE", new XUri("http://localhost/acme")));
            string header = DreamCookie.RenderCookieHeader(cookies);

            cookies = DreamCookie.ParseCookieHeader(header);
            Assert.AreEqual(1, cookies.Count, "failed to parse cookies");
            Assert.AreEqual("Customer", cookies[0].Name, "bad cookie name");
            Assert.AreEqual("WILE_E_COYOTE", cookies[0].Value, "bad cookie value");
            Assert.AreEqual("/acme", cookies[0].Path, "bad cookie path");
        }
Ejemplo n.º 30
0
 private Yield ProloguePrivateStorage(DreamContext context, DreamMessage request, Result <DreamMessage> response)
 {
     //check if this services is private
     if (_private)
     {
         DreamCookie cookie = DreamCookie.GetCookie(request.Cookies, "service-key");
         if (cookie == null || cookie.Value != PrivateAccessKey)
         {
             throw new DreamForbiddenException("insufficient access privileges");
         }
     }
     response.Return(request);
     yield break;
 }