Exemplo n.º 1
0
        public void HasPrefix_does_not_work_with_http_and_https_using_strict()
        {
            var baseUri = new XUri("http://foo/a");
            var uri     = new XUri("https://foo/a/b/c");
            var result  = uri.HasPrefix(baseUri, true);

            Assert.IsFalse(result);
        }
Exemplo n.º 2
0
        public void HasPrefix_works_with_http_and_https()
        {
            var baseUri = new XUri("http://foo/a");
            var uri     = new XUri("https://foo/a/b/c");
            var result  = uri.HasPrefix(baseUri);

            Assert.IsTrue(result);
        }
Exemplo n.º 3
0
        private XUri GetPublicUri()
        {
            // Note (arnec): This is not the same as AsPublicUri, since we do this independently of a DreamContext
            XUri uri = Uri;

            if ((uri != null) && (_publicUri != null) && (_localMachineUri != null) && uri.HasPrefix(_localMachineUri))
            {
                uri = uri.ChangePrefix(_localMachineUri, _publicUri);
            }
            return(uri);
        }
Exemplo n.º 4
0
 public void HasPrefix_works_with_http_and_https()
 {
     var baseUri = new XUri("http://foo/a");
     var uri = new XUri("https://foo/a/b/c");
     var result = uri.HasPrefix(baseUri);
     Assert.IsTrue(result);
 }
Exemplo n.º 5
0
 public void HasPrefix_does_not_work_with_http_and_https_using_strict()
 {
     var baseUri = new XUri("http://foo/a");
     var uri = new XUri("https://foo/a/b/c");
     var result = uri.HasPrefix(baseUri, true);
     Assert.IsFalse(result);
 }
Exemplo n.º 6
0
        internal bool TryGetServiceLicense(XUri sid, out string license, out DateTime?expiration)
        {
            license    = null;
            expiration = null;

            // NOTE: context may be null since services are created by DekiWikiService.Start as well as by ServiceBL.
            // This method only applies for extension services which are started with a context.
            DekiContext context = DekiContext.CurrentOrNull;

            if ((sid != null) && (context != null) && (context.LicenseManager.LicenseDocument != null))
            {
                foreach (XDoc service in context.LicenseManager.LicenseDocument["grants/service-license"])
                {
                    string text = service.AsText;

                    // check if the licensed SID matches the requested SID
                    XUri licensedSID = service["@sid"].AsUri;
                    if (licensedSID == null)
                    {
                        // parse service-license contents for the SID
                        Dictionary <string, string> values = HttpUtil.ParseNameValuePairs(text);

                        // check if the licensed SID matches the requested SID
                        string licensedSIDText;
                        if (values.TryGetValue("sid", out licensedSIDText) && XUri.TryParse(licensedSIDText, out licensedSID) && sid.HasPrefix(licensedSID, true))
                        {
                            // check if the licensed SID has an expiration date
                            string   licenseExpireText;
                            DateTime licenseExpire;
                            if (values.TryGetValue("expire", out licenseExpireText) && DateTime.TryParse(licenseExpireText, out licenseExpire))
                            {
                                if (licenseExpire >= DateTime.UtcNow)
                                {
                                    license    = text;
                                    expiration = licenseExpire;
                                    return(true);
                                }
                            }
                            else
                            {
                                license = text;
                                return(true);
                            }
                        }
                    }
                    else if (sid.HasPrefix(licensedSID, true))
                    {
                        DateTime?expire = service["@date.expire"].AsDate;

                        // check if the licensed SID has an expiration date
                        if ((expire == null) || (expire >= DateTime.UtcNow))
                        {
                            license    = text;
                            expiration = expire;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }