Esempio n. 1
1
        //--- Constructors ---
        public S3Storage(XDoc configuration, ILog log) {
            _timerFactory = TaskTimerFactory.Create(this);
            _log = log;
            _publicKey = configuration["publickey"].AsText;
            _privateKey = configuration["privatekey"].AsText;
            _bucket = configuration["bucket"].AsText;
            _prefix = configuration["prefix"].AsText;
            if(string.IsNullOrEmpty(_publicKey)) {
                throw new ArgumentException("Invalid Amazon S3 publickey");
            }
            if(string.IsNullOrEmpty(_privateKey)) {
                throw new ArgumentException("Invalid Amazon S3 privatekey");
            }
            if(string.IsNullOrEmpty(_bucket)) {
                throw new ArgumentException("Invalid Amazon S3 bucket");
            }
            if(string.IsNullOrEmpty(_prefix)) {
                throw new ArgumentException("Invalid Amazon S3 prefix");
            }
            _tempDirectory = Path.Combine(Path.GetTempPath(), "s3_cache_" + XUri.EncodeSegment(_prefix));
            if(Directory.Exists(_tempDirectory)) {
                Directory.Delete(_tempDirectory, true);
            }
            Directory.CreateDirectory(_tempDirectory);
            _allowRedirects = configuration["allowredirects"].AsBool ?? false;
            _redirectTimeout = TimeSpan.FromSeconds(configuration["redirecttimeout"].AsInt ?? 60);
            _cacheTtl = (configuration["cachetimeout"].AsInt ?? 60 * 60).Seconds();

            // initialize S3 plug
            _s3 = Plug.New("http://s3.amazonaws.com", TimeSpan.FromSeconds(configuration["timeout"].AsDouble ?? DEFAUTL_S3_TIMEOUT)).WithPreHandler(S3AuthenticationHeader).At(_bucket);
        }
Esempio n. 2
0
        private void SaveCommentsLinks(XDoc spaceManifest, string space, long confluencePageId, string mtPath) {
            RemoteComment[] comments = _confluenceService.GetComments(confluencePageId);

            foreach(RemoteComment comment in comments) {
                LogCommentConversion(spaceManifest, space, comment, mtPath);
            }
        }
Esempio n. 3
0
        public Yield GetFileHandler(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            string suffixPath = string.Join("" + Path.DirectorySeparatorChar, context.GetSuffixes(UriPathFormat.Decoded));
            string filename = Path.Combine(_path, suffixPath);
            if(Directory.Exists(filename)) {
                XDoc ret = new XDoc("files");
                string pattern = context.GetParam("pattern", "");
                AddDirectories(new DirectoryInfo(filename), pattern, ret);
                AddFiles(new DirectoryInfo(filename), pattern, ret);
                response.Return(DreamMessage.Ok(ret));
                yield break;
            }

            DreamMessage message;
            try {
                message = DreamMessage.FromFile(filename, StringUtil.EqualsInvariant(context.Verb, "HEAD"));
            } catch(FileNotFoundException) {
                message = DreamMessage.NotFound("file not found");
            } catch(Exception) {
                message = DreamMessage.BadRequest("invalid path");
            }

            // open file and stream it to the requester
            response.Return(message);
        }
Esempio n. 4
0
 private UpdateRecord(UpdateRecord current, XDoc meta) {
     Id = current.Id;
     ActionStack = current.ActionStack;
     Meta = meta;
     WikiId = current.WikiId;
     QueueIds.AddRange(current.QueueIds);
 }
 public void Can_roundtrip_DispatchItem_with_complex_event()
 {
     var body = new XDoc("msg").Elem("foo", "bar");
     var channel = new XUri("channel://foo.com/bar");
     var resource = new XUri("http://foo.com/baz/0");
     var origin1 = new XUri("http://foo.com/baz/1");
     var origin2 = new XUri("http://foo.com/baz/2");
     var recipient1 = new DispatcherRecipient(new XUri("http://recipient1"));
     var recipient2 = new DispatcherRecipient(new XUri("http://recipient2"));
     var via1 = new XUri("http://via1");
     var via2 = new XUri("http://via2");
     var ev = new DispatcherEvent(body, channel, resource, origin1, origin2);
     ev = ev.WithRecipient(false, recipient1, recipient2).WithVia(via1).WithVia(via2);
     var item = new DispatchItem(
         new XUri("http://foo"),
         ev,
         "abc"
     );
     var serializer = new DispatchItemSerializer();
     var stream = serializer.ToStream(item);
     var item2 = serializer.FromStream(stream);
     Assert.AreEqual(item.Uri, item2.Uri, "uri mismatch");
     Assert.AreEqual(item.Location, item2.Location, "location mismatch");
     Assert.AreEqual(item.Event.Id, item2.Event.Id, "id mismatch");
     Assert.AreEqual(body.ToCompactString(), item2.Event.AsDocument().ToCompactString(), "body mismatch");
     Assert.AreEqual(channel, item2.Event.Channel, "channel mismatch");
     Assert.AreEqual(resource, item2.Event.Resource, "resource mismatch");
     Assert.AreEqual(origin1, item2.Event.Origins[0], "first origin mismatch");
     Assert.AreEqual(origin2, item2.Event.Origins[1], "second origin mismatch");
     Assert.AreEqual(recipient1.Uri, item2.Event.Recipients[0].Uri, "first recipient mismatch");
     Assert.AreEqual(recipient2.Uri, item2.Event.Recipients[1].Uri, "second recipient mismatch");
     Assert.AreEqual(via1, item2.Event.Via[0], "first via mismatch");
     Assert.AreEqual(via2, item2.Event.Via[1], "second via mismatch");
 }
Esempio n. 6
0
 public void Can_provide_list_of_args_as_repeated_params_to_feature()
 {
     MockServiceInfo mock = MockService.CreateMockService(_hostInfo);
     mock.Service.CatchAllCallback = delegate(DreamContext context, DreamMessage request, Result<DreamMessage> response2) {
         XDoc msg = new XDoc("ids");
         foreach(KeyValuePair<string, string> kv in context.GetParams()) {
             if(kv.Key == "id") {
                 msg.Elem("id", kv.Value);
             }
         }
         response2.Return(DreamMessage.Ok(msg));
     };
     Plug p = mock.AtLocalHost;
     int n = 100;
     List<string> ids = new List<string>();
     for(int i = 0; i < n; i++) {
         p = p.With("id", i);
         ids.Add(i.ToString());
     }
     DreamMessage result = p.GetAsync().Wait();
     Assert.IsTrue(result.IsSuccessful);
     List<string> seen = new List<string>();
     foreach(XDoc id in result.ToDocument()["id"]) {
         string v = id.AsText;
         Assert.Contains(v, ids);
         Assert.IsFalse(seen.Contains(v));
         seen.Add(v);
     }
     Assert.AreEqual(ids.Count, seen.Count);
 }
 public void Caching_search_with_apikey_does_not_pass_auth_info_to_lucene() {
     var searchMock = CreateMocks().Item1;
     var responseXml = new XDoc("response");
     var luceneXml = new XDoc("lucene");
     var searchQuery = new SearchQuery("raw", "processed", new LuceneClauseBuilder(), null);
     var searchResult = new SearchResult();
     searchMock.Setup(x => x.BuildQuery("foo", "", SearchQueryParserType.BestGuess, true)).Returns(searchQuery).AtMostOnce().Verifiable();
     searchMock.Setup(x => x.GetCachedQuery(searchQuery)).Returns((SearchResult)null).AtMostOnce().Verifiable();
     XUri luceneUriCalled = null;
     MockPlug.Register(Utils.Settings.LuceneMockUri, (p, v, u, req, res) => {
         luceneUriCalled = u;
         res.Return(DreamMessage.Ok(luceneXml));
     });
     searchMock.Setup(x => x.CacheQuery(It.Is<XDoc>(v => v == luceneXml), It.IsAny<SearchQuery>(), It.IsAny<TrackingInfo>()))
         .Returns(searchResult);
     searchMock.Setup(x => x.FormatResultSet(
             searchResult,
             It.IsAny<SetDiscriminator>(),
             false,
             It.IsAny<TrackingInfo>(),
             It.IsAny<Result<XDoc>>()
         ))
         .Returns(new Result<XDoc>().WithReturn(responseXml));
     var response = _search
         .With("q", "foo")
         .With("apikey", Utils.Settings.ApiKey)
         .Get(new Result<DreamMessage>()).Wait();
     Assert.IsTrue(response.IsSuccessful, response.ToErrorString());
     Assert.IsNotNull(luceneUriCalled, "lucene was not called");
     Assert.AreEqual(Utils.Settings.LuceneMockUri.At("compact"), luceneUriCalled.WithoutQuery(), "lucene was called at wrong uri");
     Assert.IsNull(luceneUriCalled.GetParam("apiuri"), "lucene request contained an apiuri parameter");
     Assert.IsNull(luceneUriCalled.GetParam("userid"), "lucene request contained a userid parameter");
     Assert.AreEqual(searchQuery.LuceneQuery, luceneUriCalled.GetParam("q"), "lucene request had incorrect q parameter");
 }
Esempio n. 8
0
 private void ConvertAllWidgets(string method, XDoc xhtml, string action, string pageID) {
     foreach (XDoc widget in new List<XDoc>(xhtml["//default:span[@class='widget']"])) {
         string widgetType = widget["@widgettype"].Contents;
         if (widgetType == string.Empty) {
             LogUtils.LogWarning(_log, method + ": no widgettype attribute", widget);
             continue;
         }
         XDoc htmlData = widget[string.Format("default:span[@class='{0}']", widgetType)];
         if (htmlData.IsEmpty) {
             LogUtils.LogWarning(_log, method + ": no widget data with class", widgetType, widget);
             continue;
         }
         XDoc data = XDoc.FromXSpan(htmlData);
         if (data.IsEmpty) {
             LogUtils.LogWarning(_log, method + ": no xspan data", htmlData);
             continue;
         }
         string widgetID = widget["@widgetid"].Contents;
         XUri uri = Env.RootUri.At("wiki-data", widgetType, action).With("id", widgetID);
         if (pageID != "")
             uri = uri.With("pageid", pageID);
         Plug plug = Plug.New(uri);
         XDoc widgetXhtml = plug.Post(data).Document;
         if (widgetXhtml == null || widgetXhtml.IsEmpty) {
             LogUtils.LogWarning(_log, method + string.Format(": null/empty document for /wiki-data/{0}/{1}/ (data)", widgetType, action), data);
             continue;
         }
         LogUtils.LogTrace(_log, method, widgetType, data, widgetXhtml);
         widget.Replace(widgetXhtml);
     }
 }
Esempio n. 9
0
        public virtual XDoc BuildXDoc(XDoc rootDoc, string xpath, int nodeCount)
        {
            XDoc subdoc = rootDoc[xpath];
            if(nodeCount == subdoc.ListLength) {
                return subdoc;
            }
            string[] segments = xpath.Split('/');

            // assume the doc root is out rootPath for the collection
            if(nodeCount > 1 && segments.Length == 1 && segments[0].StartsWith("@")) {
                throw new ArgumentException("Cannot have a collection whose xpath is an attribute on the root");
            }
            bool lastIsAttribute = segments[segments.Length - 1].StartsWith("@");
            string last = segments[segments.Length - 1];
            if(lastIsAttribute) {
                last = last.Substring(1);
            }
            string lastElement = null;
            int lastElementIndex = lastIsAttribute ? segments.Length - 2 : segments.Length - 1;
            if(lastElementIndex >= 0) {
                lastElement = segments[lastElementIndex];
            }
            int rootLength = lastIsAttribute ? segments.Length - 1 : segments.Length;
            string[] rootPathSegments = new string[rootLength];
            Array.Copy(segments, rootPathSegments, rootLength);
            XDoc localRoot = CreateRootPath(rootDoc, rootPathSegments);

            if(nodeCount == 1) {
                if(lastIsAttribute && lastElement != null) {
                    if(localRoot[lastElement].IsEmpty) {
                        localRoot.Elem(lastElement);
                    }
                    localRoot = localRoot[lastElement];
                }
                if(lastIsAttribute) {
                    localRoot.Attr(last, "");
                } else {
                    localRoot.Elem(last);
                }
            } else {

                // dump current matches
                foreach(XDoc old in localRoot[lastElement]) {
                    old.Remove();
                }

                // rebuild a fresh set
                if(lastIsAttribute && lastElement != null) {
                    for(int i = 0; i < nodeCount; i++) {
                        localRoot.Start(lastElement).Attr(last,"").End();
                    }
                } else {
                    for(int i = 0; i < nodeCount; i++) {
                        localRoot.Elem(last);
                    }
                }
            }
            subdoc = rootDoc[xpath];
            return subdoc;
        }
 public void GlobalSetup() {
     _log.Debug("setup");
     var assemblyPath = @"MindTouch.Deki.Util.Tests.dll";
     _inspector = new TypeInspector();
     _inspector.InspectAssembly(assemblyPath);
     _xmlDocumentation = XDocFactory.LoadFrom(@"MindTouch.Deki.Util.Tests.xml", MimeType.TEXT_XML);
 }
Esempio n. 11
0
        public void SecurityPagePost()
        {
            // POST:pages/{pageid}/security
            // http://developer.mindtouch.com/Deki/API_Reference/POST%3apages%2f%2f%7bpageid%7d%2f%2fsecurity

            Plug p = Utils.BuildPlugForAdmin();

            string id = null;
            string path = null;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path);

            msg = p.At("users", "current").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            string userid = msg.ToDocument()["@id"].AsText;
            Assert.IsFalse(string.IsNullOrEmpty(userid));

            XDoc securityDoc = new XDoc("security")
                .Start("permissions.page")
                    .Elem("restriction", "Private")
                .End()
                .Start("grants.added")
                    .Start("grant")
                        .Start("permissions")
                            .Elem("role", "Contributor")
                        .End()
                        .Start("user").Attr("id", userid).End()
                        .Elem("date.expires", DateTime.Today.AddYears(1))
                    .End()
                .End();
            msg = p.At("pages", id, "security").Post(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.ToDocument()["grants/grant/permissions/role"].AsText == "Contributor");

            PageUtils.DeletePageByID(p, id, true);
        }
Esempio n. 12
0
        public void Get_page_data() {
            Plug deki = Plug.New("http://mock/deki");
            AutoMockPlug autoMock = MockPlug.Register(deki.Uri);
            PageChangeCache cache = new PageChangeCache(deki, (key, trigger) => { });
            DateTime timestamp = DateTime.Parse("2009/02/01 10:10:00");
            XUri pageUri = deki.Uri.At("pages", "10").With("redirects", "0");
            XDoc pageResponse = new XDoc("page")
                .Elem("uri.ui", "http://foo.com/@api/deki/pages/10")
                .Elem("title", "foo")
                .Elem("path", "foo/bar");
            XUri feedUri = deki.Uri
                .At("pages", "10", "feed")
                .With("redirects", "0")
                .With("format", "raw")
                .With("since", timestamp.Subtract(TimeSpan.FromSeconds(10)).ToString("yyyyMMddHHmmss"));
            XDoc changeResponse = new XDoc("table")
                .Start("change")
                .Elem("rc_summary", "Two edits")
                .Elem("rc_comment", "edit 1")
                .Elem("rc_comment", "edit 2")
                .Elem("rc_timestamp", "20090201101000")
                .End();

            _log.Debug("first get");
            autoMock.Expect("GET", pageUri, (XDoc)null, DreamMessage.Ok(pageResponse));
            autoMock.Expect("GET", feedUri, (XDoc)null, DreamMessage.Ok(changeResponse));
            PageChangeData data = Coroutine.Invoke(cache.GetPageData, (uint)10, "foo", timestamp, CultureInfo.InvariantCulture, (string)null, new Result<PageChangeData>()).Wait();
            Assert.IsTrue(autoMock.WaitAndVerify(TimeSpan.FromSeconds(10)));

            //string plainbody = "foo\r\n[ http://foo.com/@api/deki/pages/10 ]\r\n\r\n - edit 1 (Sun, 01 Feb 2009 10:10:00 GMT)\r\n   [ http://foo.com/@api/deki/pages/10?revision ]\r\n\r\n";
            XDoc htmlBody = XDocFactory.From("<html><p><b><a href=\"http://foo.com/@api/deki/pages/10\">foo</a></b> ( Last edited by <a href=\"http://foo.com/User%3A\" /> )<br /><small><a href=\"http://foo.com/@api/deki/pages/10\">http://foo.com/@api/deki/pages/10</a></small><br /><small><a href=\"http://foo.com/index.php?title=Special%3APageAlerts&amp;id=10\">Unsubscribe</a></small></p><p><ol><li>edit 1 ( <a href=\"http://foo.com/@api/deki/pages/10?revision\">Sun, 01 Feb 2009 10:10:00 GMT</a> by <a href=\"http://foo.com/User%3A\" /> )</li></ol></p><br /></html>", MimeType.TEXT_XML);
            Assert.AreEqual(htmlBody.ToString(), data.HtmlBody.ToString());
        }
Esempio n. 13
0
        //--- Methods ---
        public override void Start(XDoc config) {
            base.Start(config);

            // create helper services
            _global = CreateService("$global", "http://services.mindtouch.com/dream/stable/2007/03/events");
            _users = CreateService("$users", "http://services.mindtouch.com/dream/stable/2007/03/directory");
        }
Esempio n. 14
0
		public static void Setup(TestContext testContext)
		{
			var instances = new XDoc("instances")
				.Start("instance").Attr("webhost", "test.foiremuses.org").Attr("databaseName", "foiremusesxml")
				.Start("components")
				.Start("component").Attr("type", "FoireMuses.Core.Interfaces.IScoreDataMapper, FoireMuses.Core")
				.Attr("implementation", "FoireMuses.Core.Loveseat.LoveseatScoreDataMapper, FoireMuses.Core.Loveseat")
				.Attr("name", "ScoreDataMapper").End()
				.Start("component").Attr("type", "FoireMuses.Core.Interfaces.IPlayDataMapper, FoireMuses.Core")
				.Attr("implementation", "FoireMuses.Core.Loveseat.LoveseatPlayDataMapper, FoireMuses.Core.Loveseat")
				.Attr("name", "PlayDataMapper").End()
				.Start("component").Attr("type", "FoireMuses.Core.Interfaces.ISourceDataMapper, FoireMuses.Core")
				.Attr("implementation", "FoireMuses.Core.Loveseat.LoveseatSourceDataMapper, FoireMuses.Core.Loveseat")
				.Attr("name", "SourceDataMapper").End()
				.Start("component").Attr("type", "FoireMuses.Core.Interfaces.IUserDataMapper, FoireMuses.Core")
				.Attr("implementation", "FoireMuses.Core.Loveseat.LoveseatUserDataMapper, FoireMuses.Core.Loveseat")
				.Attr("name", "UserDataMapper").End()
				.Start("component").Attr("type", "FoireMuses.Core.Interfaces.IConverterFactory, FoireMuses.Core")
				.Attr("implementation", "FoireMuses.Core.ConverterFactory, FoireMuses.Core")
				.Attr("name", "ConverterFactory").End()
				.Start("component").Attr("type", "FoireMuses.Core.Interfaces.INotificationManager, FoireMuses.Core")
				.Attr("implementation", "FoireMuses.Core.Loveseat.NotificationManager, FoireMuses.Core.Loveseat")
				.Attr("name", "ConverterFactory").End()
				.End().End();
			theInstanceFactory = new InstanceFactory(new ContainerBuilder().Build(), instances);
		}
Esempio n. 15
0
 //--- Class Methods ---
 public static NotificationUpdateRecord FromDocument(XDoc doc) {
     var record = new NotificationUpdateRecord(doc["@wikiid"].AsText, doc["@userid"].AsUInt.Value);
     foreach(var page in doc["page"]) {
         record.Add(page["@id"].AsUInt.Value, page["@modified"].AsDate.Value);
     }
     return record;
 }
Esempio n. 16
0
 private static XDoc EnsureElement(XDoc doc, string parentKey, string key, string def) {
     XDoc parent = doc[parentKey];
     if (parent.IsEmpty) {
         doc.Start(parentKey);
         if (key == null)
             doc.Value(def);
         doc.End();
         parent = doc[parentKey];
     }
     if (key == null)
         return parent;
     XDoc child = parent[key];
     if (child.IsEmpty) {
         if (def == null) {
             child = null;
         } else {
             parent.Start(key);
             parent.Value(def);
             parent.End();
             child = parent[key];
         }
     } else if (def == null && child.Contents == "") {
         child.Remove();
         child = null;
     }
     return child;
 }
Esempio n. 17
0
 public Yield GetSiteStatus(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
     PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.UPDATE);
     var status = new XDoc("status")
         .Elem("state", DekiContext.Current.Instance.Status);
     response.Return(DreamMessage.Ok(status));
     yield break;
 }
Esempio n. 18
0
        //--- Constructors ---
        public PageSubscriptionInstance(string wikiId, XDoc config, IContainer container) {
            _log.DebugFormat("created PageSubscriptionInstance for wikiid '{0}'", wikiId);
            _wikiId = wikiId;
            _pageSubscriptionSessionFactory = container.Resolve<IPageSubscriptionDataSessionFactory>(new NamedParameter("config", config));

            // derive siteinfo
            _sitename = config["ui/sitename"].AsText;
            if(string.IsNullOrEmpty(_sitename)) {
                _log.WarnFormat("missing ui/sitename for instance {0}", _wikiId);
            }
            _timezone = config["ui/timezone"].AsText;
            var emailFromAddress = config["page-subscription/from-address"].AsText;
            if(string.IsNullOrEmpty(emailFromAddress)) {
                emailFromAddress = config["admin/email"].AsText;
            }
            if(string.IsNullOrEmpty(emailFromAddress)) {
                _log.WarnFormat("missing page-subscription/from-address and admin/email for instance {0}", _wikiId);
            } else {
                var address = new MailAddress(emailFromAddress);
                if(string.IsNullOrEmpty(address.DisplayName)) {
                    address = new MailAddress(emailFromAddress, emailFromAddress);
                }
                _emailFromAddress = address.ToString();
            }
            _emailFormat = config["page-subscription/email-format"].AsText;
            _useShortEmailAddress = config["page-subscription/use-short-email-address"].AsBool ?? false;
            _culture = CultureUtil.GetNonNeutralCulture(config["ui/language"].AsText) ?? CultureInfo.GetCultureInfo("en-us");
        }
Esempio n. 19
0
        public void CreateUser() {
            // Build ADMIN plug
            Plug p = Utils.BuildPlugForAdmin();

            try {
                // Define user information and generate user XML document
                string name = Utils.GenerateUniqueName();
                string email = "*****@*****.**";
                string fullName = "newuser1's full name";
                string role = "Contributor";

                XDoc usersDoc = new XDoc("user")
                    .Elem("username", name)
                    .Elem("email", email)
                    .Elem("fullname", fullName)
                    .Start("permissions.user")
                        .Elem("role", role)
                    .End();

                // Create the User
                DreamMessage msg = p.At("users").Post(usersDoc);
                Assert.AreEqual(DreamStatus.Ok, msg.Status, "User creation failed");

                // Assert all the information in the returned document is consistent
                Assert.IsTrue(msg.ToDocument()["username"].AsText == name, "Name does not match that in return document");
                Assert.IsTrue(msg.ToDocument()["email"].AsText == email, "Email does not match that in return document");
                Assert.IsTrue(msg.ToDocument()["fullname"].AsText == fullName, "Full name does not match that in return document");
                Assert.IsTrue(msg.ToDocument()["permissions.user/role"].AsText == role, "User permissions does not match that in return document");
            }

            // In the case the username already exists
            catch(MindTouch.Dream.DreamResponseException ex) {
                Assert.IsTrue(ex.Response.Status == DreamStatus.Conflict, "Username already exists, but did not return Conflict?!");
            }
        }
Esempio n. 20
0
 public ImportItem(string dataId, XDoc request, XDoc manifest, Stream data, long length) {
     DataId = dataId;
     Request = request;
     Manifest = manifest;
     Data = data;
     DataLength = length;
 }
Esempio n. 21
0
 private static XDoc GetFeatureOverview(XDoc feature)
 {
     // generate a document containing the overview information for a feature
     XDoc overviewDoc = new XDoc("html");
     overviewDoc.Start("h2").Value("Overview").End();
     overviewDoc.Add(GetWarning());
     overviewDoc.Start("p").Start("strong").Value(feature["access"].Contents + ".  ").End().Value(feature["description"].Contents).End();
     XDoc uriParams = new XDoc("uriParams");
     XDoc queryParams = new XDoc("queryParams");
     foreach(XDoc param in feature["param"]) {
         string paramName = param["name"].Contents;
         if(paramName.StartsWith("{")) {
             if(feature["pattern"].Contents.Contains(paramName)) {
                 param["name"].ReplaceValue(paramName.Trim(new char[] { '{', '}' }));
                 uriParams.Add(param);
             }
         } else {
             queryParams.Add(param);
         }
     }
     overviewDoc.Start("h5").Value("Uri Parameters").End();
     overviewDoc.Add(GetTable(new string[] { "Name", "Type", "Description" }, uriParams["param"]));
     overviewDoc.Start("h5").Value("Query Parameters").End();
     overviewDoc.Add(GetTable(new string[] { "Name", "Type", "Description" }, queryParams["param"]));
     overviewDoc.Start("h5").Value("Return Codes").End();
     XDoc statusesDoc = new XDoc("statuses");
     foreach(XDoc statusDoc in feature["status"]) {
         DreamStatus status = (DreamStatus)statusDoc["@value"].AsInt;
         statusesDoc.Start("status").Elem("name", status.ToString()).Elem("value", (int)status).Elem("description", statusDoc.Contents).End();
     }
     overviewDoc.Add(GetTable(new string[] { "Name", "Value", "Description" }, statusesDoc["status"]));
     return overviewDoc;
 }
Esempio n. 22
0
        public void Exporter_hits_export_feature_on_creation_using_relto() {

            // Arrange
            XUri dekiApiUri = new XUri("http://mock/@api/deki");
            XDoc exportDocument = new XDoc("export")
                .Start("page")
                    .Attr("path", "/")
                    .Attr("recursive", "true")
                    .Attr("exclude", "all")
                .End();
            XDoc exportResponse = new XDoc("export")
                .Start("requests")
                .End()
                .Start("manifest")
                    .Elem("justanode")
                .End();
            AutoMockPlug mock = MockPlug.Register(dekiApiUri);
            mock.Expect("POST", dekiApiUri.At("site", "export").With("relto", 5.ToString()), exportDocument, DreamMessage.Ok(exportResponse));

            // Act
            Exporter exporter = Exporter.CreateAsync(Plug.New(dekiApiUri), exportDocument, 5, new Result<Exporter>()).Wait();

            //Assert
            Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)));
            Assert.AreEqual(exportResponse["manifest"], exporter.Manifest);
        }
        public Yield GetSearchDescription(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
            XDoc description = new XDoc("OpenSearchDescription", "http://a9.com/-/spec/opensearch/1.1/");
            description.Elem("ShortName", string.Format(DekiResources.OPENSEARCH_SHORTNAME, DekiContext.Current.Instance.SiteName))
                       .Elem("Description", DekiResources.OPENSEARCH_DESCRIPTION)
                       .Start("Query")
                            .Attr("role", "example")
                            .Attr("searchTerms", "Wiki")
                       .End();

            // HACK HACK HACK: we can't use XUri because it encodes the "{}" characters
            string uri = DekiContext.Current.ApiUri.At("site", "opensearch").ToString();
            uri += "?q={searchTerms}&offset={startIndex}&limit={count?}&";

            description.Start("Url")
                 .Attr("type", "text/html")
                 .Attr("indexOffset", 0)
                 .Attr("template", DekiContext.Current.UiUri.At("Special:Search").ToString() + "?search={searchTerms}&offset=0&limit={count?}&format=html")
            .End()
            .Start("Url")
                 .Attr("type", "application/atom+xml")
                 .Attr("indexOffset", 0)
                 .Attr("template", uri + "format=atom")
            .End()
            .Start("Url")
                 .Attr("type", "application/rss+xml")
                 .Attr("indexOffset", 0)
                 .Attr("template", uri + "format=rss")
            .End()
            .Start("Url")
                 .Attr("type", "application/x-suggestions+json")
                 .Attr("template", DekiContext.Current.ApiUri.At("site", "opensearch", "suggestions").ToString() + "?q={searchTerms}")
             .End();
            response.Return(DreamMessage.Ok(description));
            yield break;
        }
Esempio n. 24
0
 public void Add_recipients_to_event()
 {
     XDoc msg = new XDoc("msg");
     DispatcherRecipient r1 = new DispatcherRecipient(new XUri("mailto:///[email protected]"));
     DispatcherRecipient r2 = new DispatcherRecipient(new XUri("mailto:///[email protected]"));
     DispatcherRecipient r3 = new DispatcherRecipient(new XUri("mailto:///[email protected]"));
     DispatcherEvent ev1 = new DispatcherEvent(msg, new XUri("channel://foo.com/bar"), new XUri("http://foo.com/baz"));
     DispatcherEvent ev2 = ev1.WithRecipient(false, r1);
     Assert.AreEqual(0, ev1.Recipients.Length);
     Assert.AreEqual(1, ev2.Recipients.Length);
     Assert.AreEqual(r1, ev2.Recipients[0]);
     DispatcherEvent ev3 = ev2.WithRecipient(false, r2, r3);
     Assert.AreEqual(3, ev3.Recipients.Length);
     Assert.AreEqual(r1, ev3.Recipients[0]);
     Assert.AreEqual(r2, ev3.Recipients[1]);
     Assert.AreEqual(r3, ev3.Recipients[2]);
     DreamMessage ev3msg = ev3.AsMessage();
     Assert.AreEqual(msg, ev3msg.ToDocument());
     Assert.AreEqual(ev1.Id, ev3.Id);
     Assert.AreEqual("channel://foo.com/bar", ev3msg.Headers.DreamEventChannel);
     Assert.AreEqual("http://foo.com/baz", ev3msg.Headers.DreamEventOrigin[0]);
     string[] recipients = ev3msg.Headers.DreamEventRecipients;
     Assert.AreEqual(3, recipients.Length);
     Assert.AreEqual(r1.ToString(), recipients[0]);
     Assert.AreEqual(r2.ToString(), recipients[1]);
     Assert.AreEqual(r3.ToString(), recipients[2]);
 }
 //--- Methods ---
 public void Enqueue(XDoc meta) {
     XUri channel = meta["channel"].AsUri;
     RecordType type;
     int id;
     string path = string.Empty;
     string wikiid = meta["@wikiid"].AsText;
     if(channel.Segments[1] == "pages") {
         type = RecordType.Page;
         id = meta["pageid"].AsInt ?? 0;
         path = meta["path"].AsText;
     } else {
         type = RecordType.File;
         id = meta["fileid"].AsInt ?? 0;
     }
     string key = string.Format("{0}:{1}:{2}", wikiid, type, id);
     lock(_data) {
         UpdateRecord data;
         if(!_data.TryGetValue(key, out data)) {
             _log.DebugFormat("queueing '{0}'", key);
             _queue.Enqueue(new Tuplet<string, DateTime>(key, DateTime.UtcNow.Add(_delay)));
             data = new UpdateRecord(id, type, wikiid);
             _data.Add(key,data);
         }
         if(!string.IsNullOrEmpty(path)) {
             data.Path = path;
         }
     }
 }
Esempio n. 26
0
        //--- Class Methods ---
        private static XDoc AddTableStyles(XDoc doc) {
            XDoc head = doc["head"];
            if(head.IsEmpty) {
                doc.Elem("head");
                head = doc["head"];
            }
            head.Start("style").Attr("type", "text/css").Value(@".feedtable {
    border:1px solid #999;
    line-height:1.5em;
    overflow:hidden;
    width:100%;
}
.feedtable th {
    background-color:#ddd;
    border-bottom:1px solid #999;
    font-size:14px;
}
.feedtable tr {
    background-color:#FFFFFF;
}
.feedtable tr.feedroweven td {
    background-color:#ededed;
}").End();
            return doc;
        }
        protected override Yield Start(XDoc config, Result result) {
            yield return Coroutine.Invoke(base.Start, config, new Result());

            _path = config["xmlauth-path"].AsText ?? "xmlauth.xml";

            result.Return();
        }
Esempio n. 28
0
 public DreamMessage GetContentHandler(DreamContext context, DreamMessage message) {
     user user = Authenticate(context, message, DekiUserLevel.User);
     page page = Authorize(context, user, DekiAccessLevel.Read, "pageid");
     DekiContext deki = new DekiContext(message, this.DekiConfig);
     bool nofollow = (context.Uri.GetParam("nofollow", 0, null) != null);
     string contents = page.getContent(nofollow);
     string xml = string.Format(DekiWikiService.XHTML_LOOSE, contents);
     XDoc doc = XDoc.FromXml(xml);
     if (doc == null) {
         LogUtils.LogWarning(_log, "GetContentHandler: null document page content", page.PrefixedName, contents);
         throw new DreamAbortException(DreamMessage.BadRequest("null document"));
     }
     XDoc result = new XDoc("list");
     string type = context.Uri.GetParam("type", 0, null);
     string id = context.Uri.GetParam("id", 0, null);
     if (id != null) {
         XDoc widget = doc[string.Format("//default:span[@widgetid={0}]", id)];
         if (widget.IsEmpty) {
             LogUtils.LogWarning(_log, "GetContentHandler: widget not found for ID", id);
             return DreamMessage.NotFound("");
         }
         LogUtils.LogTrace(_log, "GetContentHandler: widget by id (id, xspan)", id, widget);
         result.Add(ConvertFromXSpan(widget));
     } else if (type != null) {
         foreach (XDoc widget in doc[string.Format("//default:span[@widgettype='{0}']", type)])
             result.Add(ConvertFromXSpan(widget));
         LogUtils.LogTrace(_log, "GetContentHandler: widget by type (type, #)", type, result.Count);
     } else {
         foreach (XDoc widget in doc["//default:span[@class='widget']"])
             result.Add(ConvertFromXSpan(widget));
         LogUtils.LogTrace(_log, "GetContentHandler: all widgets (#)", type, result.Count);
     }
     return DreamMessage.Ok(result);
 }
Esempio n. 29
0
 //--- Methods ---
 public SqsMessage NewMockMessage(int id)
 {
     var messageId = id.ToString();
     var MessageReceipt = Guid.NewGuid().ToString();
     var body = new XDoc("doc").Elem("id", messageId).Elem("receipt-handle", MessageReceipt).ToCompactString();
     return new SqsMessage(new SqsMessageId(messageId), new SqsMessageReceipt(MessageReceipt), body);
 }
Esempio n. 30
0
        public XDoc StockQuote(
            [DekiExtParam("stock ticker symbol")] string symbol
        ) {

            // check keys
            string app = Config["finance-app-id"].AsText;
            string sig = Config["finance-sig"].AsText;
            if(string.IsNullOrEmpty(app) || string.IsNullOrEmpty(sig)) {
                return new XDoc("html").Start("body").Start("span").Attr("style", "color:red;font-weight:bold;").Value("The Yahoo! Finance Application ID or Signature are missing").End().End();
            }

            // create control
            symbol = symbol.ToUpperInvariant();
            XDoc result = new XDoc("html").Start("body").Start("iframe")
                .Attr("allowtransparency", "true")
                .Attr("marginwidth", "0")
                .Attr("marginheight", "0")
                .Attr("hspace", "0")
                .Attr("vspace", "0")
                .Attr("frameborder", "0")
                .Attr("scrolling", "no")
                .Attr("src", string.Format("http://api.finance.yahoo.com/instrument/1.0/{0}/badge;quote/HTML?AppID={1}&sig={2}", XUri.EncodeSegment(symbol), XUri.EncodeQuery(app), XUri.EncodeQuery(sig)))
                .Attr("width", "200px")
                .Attr("height", "250px")
                .Start("a").Attr("href", "http://finance.yahoo.com").Value("Yahoo! Finance").End()
                .Elem("br")
                .Start("a").Attr("href", string.Format("http://finance.yahoo.com/q?s={0}", XUri.EncodeQuery(symbol))).Value(string.Format("Quote for {0}", symbol)).End()
            .End().End();
            return result;
        }
Esempio n. 31
0
        //--- Methods ---
        protected override Yield Start(XDoc config, Result result)
        {
            yield return(Coroutine.Invoke(base.Start, config, new Result()));

            _path = Environment.ExpandEnvironmentVariables(config["mount"].Contents);
            if (!Path.IsPathRooted(_path))
            {
                throw new ArgumentException(string.Format("storage path is not absolute: {0}", _path));
            }
            if (!Directory.Exists(_path))
            {
                throw new ArgumentException(string.Format("mount path does not exist: {0}", _path));
            }

            // make sure path ends with a '\' as it makes processing simpler later on
            if ((_path.Length != 0) && ((_path[_path.Length - 1] != '/') || (_path[_path.Length - 1] != '\\')))
            {
                _path += Path.DirectorySeparatorChar;
            }
            result.Return();
        }
Esempio n. 32
0
        public Yield GetServices(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            bool privateDetails = PermissionsBL.IsUserAllowed(DekiContext.Current.User, Permissions.ADMIN);

            //Private feature requires api-key
            uint totalCount;
            uint queryCount;
            IList <ServiceBE> services = ServiceBL.GetServicesByQuery(context, out totalCount, out queryCount);
            XDoc result = new XDoc("services");

            result.Attr("count", services.Count);
            result.Attr("querycount", queryCount);
            result.Attr("totalcount", totalCount);
            result.Attr("href", DekiContext.Current.ApiUri.At("site", "services"));
            foreach (ServiceBE s in services)
            {
                result.Add(ServiceBL.GetServiceXmlVerbose(DekiContext.Current.Instance, s, null, privateDetails));
            }
            response.Return(DreamMessage.Ok(result));
            yield break;
        }
Esempio n. 33
0
        public void Importer_hits_import_feature_with_reltopath()
        {
            // Arrange
            XUri dekiApiUri     = new XUri("http://mock/@api/deki");
            XDoc importManifest = new XDoc("manifest");
            XDoc importResponse = new XDoc("requests")
                                  .Start("request").Attr("dataid", "a").End()
                                  .Start("request").Attr("dataid", "b").End()
                                  .Start("request").Attr("dataid", "c").End();
            AutoMockPlug mock = MockPlug.Register(dekiApiUri);

            mock.Expect("POST", dekiApiUri.At("site", "import").With("reltopath", "/foo/bar"), importManifest, DreamMessage.Ok(importResponse));

            // Act
            Importer importer = Importer.CreateAsync(Plug.New(dekiApiUri), importManifest, "/foo/bar", new Result <Importer>()).Wait();

            //Assert
            Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)));
            Assert.AreEqual(importManifest, importer.Manifest);
            Assert.AreEqual(new[] { "a", "b", "c" }, importer.Items.Select(x => x.DataId).ToArray());
        }
Esempio n. 34
0
        private void ReplaceLinkAttribute(Dictionary <string, string> pathMap, XDoc doc, string attributeName, bool removeIfNotFound)
        {
            string atAttributeName = "@" + attributeName;
            string link            = doc[atAttributeName].AsText;

            if (link != null)
            {
                string dekiUrl = GetMtPathFromConfluencePath(pathMap, link);
                if (dekiUrl != null)
                {
                    doc.Attr(attributeName, dekiUrl);
                }
                else
                {
                    if (removeIfNotFound && Utils.IsRelativePath(link))
                    {
                        doc.Remove();
                    }
                }
            }
        }
Esempio n. 35
0
 internal Yield PostServices(DreamContext context, DreamMessage request, Result <DreamMessage> response)
 {
     ServiceBL.EnsureServiceAdministrationAllowed();
     if (request.HasDocument && !request.ToDocument().IsEmpty)
     {
         //Add or Modify a service
         ServiceBE service = ServiceBL.PostServiceFromXml(request.ToDocument(), null);
         response.Return(DreamMessage.Ok(ServiceBL.GetServiceXmlVerbose(DekiContext.Current.Instance, service, null)));
     }
     else
     {
         //Backward compatibility: posting an empty document restarts all local services
         XDoc ret = new XDoc("services");
         foreach (ServiceBE service in ServiceBL.RestartServices())
         {
             ret.Add(ServiceBL.GetServiceXml(service, null));
         }
         response.Return(DreamMessage.Ok(ret));
     }
     yield break;
 }
Esempio n. 36
0
        public static void Validate(XDoc license)
        {
            try {
                // check if license has a valid element name
                if (!license.HasName("license.public") && !license.HasName("license.private"))
                {
                    throw new DekiLicenseException(DekiLicenseException.ReasonKind.INVALID_LICENSE, string.Format("Server returned an invalid license document. Expected <license.public>, but received <{0}>.", license.Name));
                }

                // check if license is valid using the public key
                if (!license.HasValidSignature(MindTouchPublicKey))
                {
                    throw new DekiLicenseException(DekiLicenseException.ReasonKind.INVALID_SIGNATURE, "Server license validation failed. The license signature is not valid.");
                }

                // check license type
                string type = license["@type"].Contents;
                if (!type.EqualsInvariantIgnoreCase("commercial") && !type.EqualsInvariantIgnoreCase("trial") && !type.EqualsInvariantIgnoreCase("community"))
                {
                    throw new DekiLicenseException(DekiLicenseException.ReasonKind.INVALID_LICENSE_TYPE, string.Format("Server license type must be either 'community', 'commercial' or 'trial' instead of '{0}'.", type ?? "none"));
                }

                // check license issue date
                DateTime issued = license["date.issued"].AsDate ?? DateTime.MinValue;
                if (issued > DateTime.UtcNow)
                {
                    throw new DekiLicenseException(DekiLicenseException.ReasonKind.INVALID_LICENSE, string.Format("Server license has future issue date of {0}.", issued.ToString("dddd, d MMMM yyyy")));
                }

                // check license expiration date
                DateTime expires = license["date.expiration"].AsDate ?? DateTime.MaxValue;
                if (expires < DateTime.UtcNow)
                {
                    throw new DekiLicenseException(DekiLicenseException.ReasonKind.EXPIRED_LICENSE, string.Format("Server license expired on {0}.", expires.ToString("dddd, d MMMM yyyy")));
                }
            } catch (Exception e) {
                _log.WarnFormat(e.Message);
                throw;
            }
        }
Esempio n. 37
0
        public void Bug_8488_Contents_With_Tags_Inherits_Restrictions()
        {
            // Log in as ADMIN
            Plug p = Utils.BuildPlugForAdmin();

            // Create a page
            string page_id;
            string page_path;
            var    msg = PageUtils.CreateRandomPage(p, out page_id, out page_path);

            // Set page to private
            XDoc secXML = new XDoc("security").Start("permissions.page").Elem("restriction", "Private").End();

            msg = p.At("pages", page_id, "security").Put(secXML, new Result <DreamMessage>()).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Setting restrictions of parent page to 'Private' failed!");

            // Create a subpage to page with tag contents
            string content      = "<p>test page bug 8488</p>";
            string tags         = "<p class=\"template:tag-insert\"><em>Tags recommended by the template: </em><a href=\"#\">test:foo</a></p>";
            string subpage_path = page_path + "/" + Utils.GenerateUniqueName();

            msg = p.At("pages", "=" + XUri.DoubleEncode(subpage_path), "contents")
                  .Post(DreamMessage.Ok(MimeType.TEXT_UTF8, content + tags), new Result <DreamMessage>()).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Subpage creation failed!");

            // Verify tag test:foo created
            msg = p.At("pages", "=" + XUri.DoubleEncode(subpage_path), "tags").Get(new Result <DreamMessage>()).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Tag retrieval failed!");
            Assert.AreEqual("test:foo", msg.ToDocument()["tag/@value"].AsText, "Unexpected tag value");

            // Verify tag data is not part of contents
            msg = p.At("pages", "=" + XUri.DoubleEncode(subpage_path), "contents").Get(new Result <DreamMessage>()).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Content retrieval failed!");
            Assert.AreEqual(content, msg.ToDocument()["body"].AsText, "Unexpected contents");

            // Retrieve subpage security and verify it is private
            msg = p.At("pages", "=" + XUri.DoubleEncode(subpage_path), "security").Get(new Result <DreamMessage>()).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Security retrieval failed!");
            Assert.AreEqual("Private", msg.ToDocument()["permissions.page/restriction"].AsText ?? String.Empty, "Subpage did not inherit 'Private' restriction!");
        }
Esempio n. 38
0
        private void WriteMeta(string filePath, TimeSpan?ttl, DateTime?when)
        {
            lock (_expirationEntries) {
                var metaPath = GetMetaPath(filePath);
                if (ttl.HasValue)
                {
                    // set up expiration and write to meta file
                    if (when.HasValue)
                    {
                        _expirationEntries.SetOrUpdate(filePath, when.Value, ttl.Value);
                    }
                    else
                    {
                        _expirationEntries.SetOrUpdate(filePath, ttl.Value);
                        when = _expirationEntries[filePath].When;
                    }
                    var meta = new XDoc("meta")
                               .Elem("expire.ttl", ttl.Value.TotalSeconds)
                               .Elem("expire.date", when.Value);
                    Directory.CreateDirectory(Path.GetDirectoryName(metaPath));
                    meta.Save(metaPath);
                }
                else
                {
                    // remove expiration and remove it from meta file
                    _expirationEntries.Delete(filePath);
                    if (File.Exists(metaPath))
                    {
                        try {
                            File.Delete(metaPath);
                        } catch {
                            // ignore file deletion exception

                            // BUG #806: we should try again in a few seconds; however, we need to be smart about it and count how often
                            //           we tried, otherwise we run the risk of bogging down the system b/c we're attempting to delete undeletable files.
                        }
                    }
                }
            }
        }
        public ActionResult Publish(string scoreId, bool overwrite, HttpPostedFileBase file)
        {
            theLogger.Info("POST Publish");
            if (file == null || file.ContentType != "text/xml" || file.ContentLength == 0)
            {
                ViewBag.Error = "Error during the upload, please be sure to choose a valid xml file from your computer";
                return(View("Publish"));
            }
            FoireMusesConnection connection = GetConnection();
            Score score = null;

            try
            {
                if (scoreId == null)
                {
                    XDoc theDoc = XDocFactory.From(file.InputStream, MimeType.XML);
                    score = connection.CreateScoreWithXml(theDoc, new Result <Score>()).Wait();
                }
                else
                {
                    Score current = connection.GetScore(scoreId, new Result <Score>()).Wait();
                    if (current == null)
                    {
                        return(RedirectToAction("Missing", "Error", null));
                    }
                    score = connection.UpdateScoreWithXml(current.Id, current.Rev, XDocFactory.From(file.InputStream, MimeType.XML), overwrite, new Result <Score>()).Wait();
                    if (score == null)
                    {
                        return(RedirectToAction("Problem", "Error", null));
                    }
                    return(RedirectToAction("Details", new { scoreId = score.Id }));
                }
            }
            catch (Exception e)
            {
                theLogger.Error("Stacktrace:\n" + e.StackTrace);
                return(RedirectToAction("Problem", "Error", null));
            }
            return(RedirectToAction("Edit", new { scoreId = score.Id }));
        }
Esempio n. 40
0
        public XDoc Table(
            [DekiExtParam("filter name")] string filter
            )
        {
            InitializeService();
            InitializeStatuses();
            InitializeFilters();
            InitializePriorities();

            RemoteFilter f = RetrieveFilter(filter);

            RemoteIssue[] issues = _jira.getIssuesFromFilter(_jiraToken, f.id);

            XDoc bugList = BuildBugListHTMLTable(issues);
            XDoc ret     = new XDoc("html");

            ret.Start("head")
            .Start("script").Attr("type", "text/javascript").Attr("src", Files.At("sorttable.js")).End()
            .Start("link").Attr("type", "text/css").Attr("rel", "stylesheet").Attr("href", Files.At("Jira.css")).End()
            .Start("style").Attr("type", "text/css").Value(@".feedtable {
    border:1px solid #999;
    line-height:1.5em;
    overflow:hidden;
    width:100%;
}
.feedtable th {
    background-color:#ddd;
    border-bottom:1px solid #999;
    font-size:14px;
}
.feedtable tr {
    background-color:#FFFFFF;
}
.feedtable tr.feedroweven td {
    background-color:#ededed;
}").End()
            .End();
            ret.Start("body").Add(bugList).End();
            return(ret);
        }
Esempio n. 41
0
        public void CheckBannedUsersPerms()
        {
            //Assumptions:
            //
            //Actions:
            // Create user1 as contributor
            // Ban user1
            // create public page p1
            // Call POST: pages/{p1}/allowed with user1
            //Expected result:
            // user1 should not have access to p1

            Plug p = Utils.BuildPlugForAdmin();

            string       userId   = null;
            string       userName = null;
            DreamMessage msg      = UserUtils.CreateRandomContributor(p, out userId, out userName);

            // confirm user has perms
            msg = p.At("users", userId).Get();
            Assert.IsTrue((msg.AsDocument()["permissions.effective/operations"].AsText ?? string.Empty).ContainsInvariantIgnoreCase("UPDATE"), "user doesnt have expected perms");

            // ban the user
            XDoc ban = new XDoc("bans")
                       .Elem("description", Utils.GetSmallRandomText())
                       .Elem("date.expires", DateTime.Now.AddDays(10))
                       .Start("permissions.revoked")
                       .Elem("operations", banRevokemask)
                       .End()
                       .Start("ban.users")
                       .Start("user").Attr("id", userId).End()
                       .End();

            msg = p.At("site", "bans").Post(ban);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            // confirm user has perms
            msg = p.At("users", userId).Get();
            Assert.IsFalse((msg.AsDocument()["permissions.effective/operations"].AsText ?? string.Empty).ContainsInvariantIgnoreCase("UPDATE"), "user doesnt have expected perms");
        }
Esempio n. 42
0
        public Yield GetTags(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            string type        = DreamContext.Current.GetParam("type", "");
            string fromStr     = DreamContext.Current.GetParam("from", "");
            string toStr       = DreamContext.Current.GetParam("to", "");
            bool   showPages   = DreamContext.Current.GetParam("pages", false);
            string partialName = DreamContext.Current.GetParam("q", "");

            // parse type
            TagType tagType = TagType.ALL;

            if (!string.IsNullOrEmpty(type) && !SysUtil.TryParseEnum(type, out tagType))
            {
                throw new DreamBadRequestException("Invalid type parameter");
            }

            // check and validate from date
            DateTime from = (tagType == TagType.DATE) ? DateTime.Now : DateTime.MinValue;

            if (!string.IsNullOrEmpty(fromStr) && !DateTime.TryParse(fromStr, out from))
            {
                throw new DreamBadRequestException("Invalid from date parameter");
            }

            // check and validate to date
            DateTime to = (tagType == TagType.DATE) ? from.AddDays(30) : DateTime.MaxValue;

            if (!string.IsNullOrEmpty(toStr) && !DateTime.TryParse(toStr, out to))
            {
                throw new DreamBadRequestException("Invalid to date parameter");
            }

            // execute query
            var  tagBL = new TagBL();
            var  tags  = tagBL.GetTags(partialName, tagType, from, to);
            XDoc doc   = tagBL.GetTagListXml(tags, "tags", null, showPages);

            response.Return(DreamMessage.Ok(doc));
            yield break;
        }
Esempio n. 43
0
        /// <summary>
        /// Builds a http://sitemaps.org compliant sitemap as used by google (https://www.google.com/webmasters/tools/docs/en/protocol.html)
        /// </summary>
        /// <param name="rootPage"></param>
        /// <returns></returns>
        public static XDoc BuildGoogleSiteMap(PageBE rootPage, string language)
        {
            IList <PageBE> pages = null;
            Dictionary <ulong, IList <ulong> > childrenInfo = null;

            DbUtils.CurrentSession.Pages_GetDescendants(rootPage, null, true, out pages, out childrenInfo, ConfigBL.GetInstanceSettingsValueAs <int>(ConfigBL.MAX_SITEMAP_SIZE_KEY, ConfigBL.MAX_SITEMAP_SIZE));

            PageBE[] allowedPages = PermissionsBL.FilterDisallowed(DekiContext.Current.User, pages, false, new Permissions[] { Permissions.BROWSE });
            Dictionary <ulong, PageBE> allowedPagesById = allowedPages.AsHash(e => e.ID);
            Dictionary <ulong, PageBE> addedPagesById   = null;

            if (!string.IsNullOrEmpty(language))
            {
                List <ulong> pagesToRemove = new List <ulong>();
                foreach (KeyValuePair <ulong, PageBE> page in allowedPagesById)
                {
                    if (!string.IsNullOrEmpty(page.Value.Language) && !StringUtil.EqualsInvariantIgnoreCase(page.Value.Language, language))
                    {
                        pagesToRemove.Add(page.Key);
                    }
                }
                foreach (ulong pageId in pagesToRemove)
                {
                    allowedPagesById.Remove(pageId);
                }
            }
            PageBL.AddParentsOfAllowedChildren(rootPage, allowedPagesById, addedPagesById);

            XDoc x = new XDoc("urlset", "http://www.google.com/schemas/sitemap/0.84");

            foreach (PageBE p in allowedPagesById.Values)
            {
                x.Start("url");
                x.Elem("loc", Utils.AsPublicUiUri(p.Title));
                x.Start("lastmod").Value(p.TimeStamp.ToString("yyyy-MM-dd")).End();
                x.End();
            }

            return(x);
        }
Esempio n. 44
0
        private int CreateDekiPageHistory(Plug p, string pagePath, string pageTitle, DateTime?modified, string content,
                                          out string dekiPageUrl)
        {
            Log.DebugFormat("Creating page history: '{0}' Content? {1}", XUri.DoubleDecode(pagePath), !string.IsNullOrEmpty(content));

            Plug pagePlug = p.At("pages", "=" + pagePath, "revision");

            pagePlug = pagePlug.With("abort", "never");
            modified = modified ?? DateTime.Now;
            string editTime = Utils.FormatPageDate(modified.Value.ToUniversalTime());

            pagePlug = pagePlug.With("edittime", editTime);
            if (pageTitle != null)
            {
                pagePlug = pagePlug.With("title", pageTitle);
            }
            DreamMessage msg = DreamMessage.Ok(MimeType.TEXT_UTF8, content);

            DreamMessage res = pagePlug.PostAsync(msg).Wait();

            if (res.Status != DreamStatus.Ok)
            {
                WriteLineToConsole("Error converting page \"" + XUri.DoubleDecode(pagePath) + "\"");
                WriteLineToLog("Edit time: " + editTime);
                WriteLineToLog("Page title: " + pageTitle);
                WriteErrorResponse(res);
                WriteErrorRequest(msg);
                Log.WarnFormat("Error converting page: '{0}'. Request: {0}    \nResponse: {1}", msg.ToString(), res.ToString());
            }
            else
            {
                XDoc createdPage = res.AsDocument();
                int  pageId      = createdPage["page/@id"].AsInt.Value;
                dekiPageUrl = createdPage["page/path"].AsText;

                return(pageId);
            }
            dekiPageUrl = null;
            return(-1);
        }
Esempio n. 45
0
        public void FileUploadAndPropertyUpdate()
        {
            Plug p = Utils.BuildPlugForAdmin();

            string       id       = null;
            string       path     = null;
            DreamMessage msg      = PageUtils.CreateRandomPage(p, out id, out path);
            string       filepath = FileUtils.CreateRamdomFile(null);
            string       fileName = System.IO.Path.GetFileName(filepath);

            fileName = "properties";

            //Upload file via PUT: pages/{id}/files/{filename}
            msg = p.At("pages", id, "files", "=" + XUri.DoubleEncode(fileName)).PutAsync(DreamMessage.FromFile(filepath)).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Initial upload failed");

            string fileid = msg.ToDocument()["@id"].AsText;

            //Upload another rev of file via PUT:files/{fileid}/{filename}
            msg = p.At("files", fileid, "=" + XUri.DoubleEncode(fileName)).PutAsync(DreamMessage.FromFile(filepath)).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "upload via PUT:files/{fileid}/{filename} failed");
            Assert.AreEqual("file", msg.ToDocument().Name, "File upload did not return a file xml");

            //Create a property 'foo' on the file
            msg = p.At("files", fileid, "properties").WithHeader("slug", "foo").PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, "foo content")).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Property foo set via POST:files/{id}/properties failed");
            Assert.AreEqual("property", msg.ToDocument().Name, "property upload did not return property xml");
            string propEtag = msg.ToDocument()["@etag"].AsText;

            //Update property 'foo' using the batch feature
            string newPropertyContent = "Some new content";
            XDoc   propDoc            = new XDoc("properties")
                                        .Start("property").Attr("name", "foo").Attr("etag", propEtag)
                                        .Start("contents").Attr("type", MimeType.TEXT_UTF8.ToString()).Value(newPropertyContent).End()
                                        .End();

            msg = p.At("files", fileid, "properties").PutAsync(propDoc).Wait();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "batch property call failed");
            Assert.AreEqual("properties", msg.ToDocument().Name, "batch property upload did not return properties xml");
        }
Esempio n. 46
0
 private void BuildInterfaceBlock(XDoc html, ReflectedTypeInfo type)
 {
     if (type.Interfaces.Any())
     {
         html.StartNameValueBlock("implements", "Implements")
         .Start("ul");
         foreach (var interfaceParameter in type.Interfaces)
         {
             html.Start("li");
             BuildParameterMarkup(html, interfaceParameter);
             html.End();
         }
         html.End() // ul
         .EndNameValue();
     }
     if (type.Kind == TypeKind.Interface)
     {
         var implementers = (from t in _types where t.Interfaces.Where(x => x.Type == type).Any() select t).ToList();
         if (implementers.Any())
         {
             html.StartNameValueBlock("implementors", "Implementors")
             .Start("ul");
             foreach (var implementor in implementers)
             {
                 html.Start("li");
                 if (IsTypeInDocumentation(implementor))
                 {
                     html.Link(implementor.UriPath, implementor.DisplayName);
                 }
                 else
                 {
                     html.Value(implementor.DisplayName);
                 }
                 html.End();
             }
             html.End() // ul
             .EndNameValue();
         }
     }
 }
Esempio n. 47
0
        public void RunScript(XDoc script, string path)
        {
            // check if a filename was provided
            string filename = script["@src"].AsText;

            if (filename != null)
            {
                // check if filename is relative
                if (!Path.IsPathRooted(filename) && (path != null))
                {
                    filename = Path.Combine(path, filename);
                }

                // attempt to load script file
                if (!File.Exists(filename))
                {
                    throw new FileNotFoundException(string.Format("script not found: {0}", filename));
                }
                script = XDocFactory.LoadFrom(filename, MimeType.XML);
            }

            // execute script
            if (script == null)
            {
                throw new Exception(string.Format("invalid script: {0}", script.AsText));
            }

            // convert <config> element into a <script> element
            if (script.HasName("config"))
            {
                XDoc doc = new XDoc("script");
                doc.Start("action").Attr("verb", "POST").Attr("path", "/host/services");
                doc.Add(script);
                doc.End();
                script = doc;
            }

            // execute script
            _host.At("execute").Post(script);
        }
Esempio n. 48
0
        private static XDoc GetTable(string[] columnNames, XDoc tableElements)
        {
            int numRows = tableElements.ListLength;

            string[] keys = new string[numRows];
            XDoc[]   sortedTableElements = new XDoc[numRows];
            for (int i = 0; i < numRows; i++)
            {
                keys[i] = tableElements[0].Contents;
                sortedTableElements[i] = tableElements;
                tableElements          = tableElements.Next;
            }
            Array.Sort(keys, sortedTableElements, StringComparer.Ordinal);

            // generate a document containing a table with the specified names and values
            XDoc tableDoc = null;

            if (0 == sortedTableElements.Length)
            {
                tableDoc = (new XDoc("p")).Start("em").Value("None").End();
            }
            else
            {
                tableDoc = XDocFactory.From("<table cellspacing=\"0\" cellpadding=\"1\" border=\"1\" style=\"width: 100%;\"><tbody><tr style=\"text-align: left; vertical-align: top; background-image: none; background-color: #e1e1e1;\"></tr></tbody></table>", MimeType.XML);
                foreach (string columnName in columnNames)
                {
                    tableDoc["tbody/tr"].Start("td").Start("strong").Value(columnName).End().End();
                }
                foreach (XDoc tableElement in sortedTableElements)
                {
                    XDoc rowDoc = new XDoc("tr").Attr("style", "text-align: left; vertical-align: top; background-image: none;");
                    foreach (XDoc column in tableElement.Elements)
                    {
                        rowDoc.Start("td").Value(column.Contents).End();
                    }
                    tableDoc["tbody"].Add(rowDoc);
                }
            }
            return(tableDoc);
        }
Esempio n. 49
0
        public DataCatalog(DataFactory factory, XDoc config)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            _factory = factory;

            // compose connection string from config document
            string server   = config["db-server"].AsText ?? "localhost";
            int    port     = config["db-port"].AsInt ?? 3306;
            string catalog  = config["db-catalog"].AsText;
            string user     = config["db-user"].AsText;
            string password = config["db-password"].AsText ?? string.Empty;
            string options  = config["db-options"].AsText;

            if (string.IsNullOrEmpty(catalog))
            {
                throw new ArgumentNullException("config/catalog");
            }
            if (string.IsNullOrEmpty(user))
            {
                throw new ArgumentNullException("config/user");
            }
            _connection = string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};{5}", server, port, catalog, user, password, options);

            // compose read-only connection string
            string readonly_server   = config["db-readonly-server"].AsText ?? server;
            int    readonly_port     = config["db-readonly-port"].AsInt ?? port;
            string readonly_catalog  = config["db-readonly-catalog"].AsText ?? catalog;
            string readonly_user     = config["db-readonly-user"].AsText ?? user;
            string readonly_password = config["db-readonly-password"].AsText ?? password;
            string readonly_options  = config["db-readonly-options"].AsText ?? options;

            _readonlyconnection = string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};{5}", readonly_server, readonly_port, readonly_catalog, readonly_user, readonly_password, readonly_options);
        }
Esempio n. 50
0
        public void GetPageTags()
        {
            // PUT:pages/{pageid}/tags
            // http://developer.mindtouch.com/Deki/API_Reference/PUT%3apages%2f%2f%7bpageid%7d%2f%2ftags

            // 1. Create a page
            // 2. Generate an XML document with one of each tag type: date, define, and text
            // (3) Assert tags exist for specified strings
            // 4. Delete page

            Plug p = Utils.BuildPlugForAdmin();

            string       id   = null;
            string       path = null;
            DreamMessage msg  = PageUtils.CreateRandomPage(p, out id, out path);

            Guid   guid1  = Guid.NewGuid();
            string value1 = "date:2007-08-29";
            string value2 = "define:" + guid1.ToString();
            string value3 = "text tag";

            XDoc tagsDoc = new XDoc("tags")
                           .Start("tag").Attr("value", value1).End()
                           .Start("tag").Attr("value", value2).End()
                           .Start("tag").Attr("value", value3).End();

            msg = p.At("pages", id, "tags").Put(tagsDoc);
            Assert.IsTrue(msg.Status == DreamStatus.Ok, "PUT request failed");

            // GET:pages/{pageid}/tags
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2ftags

            msg = p.At("pages", id, "tags").Get();
            Assert.IsTrue(msg.Status == DreamStatus.Ok, "GET request failed");
            Assert.IsFalse(msg.ToDocument()[string.Format("tag[@value=\"{0}\"]", value1)].IsEmpty, "Date tag does not exist!");
            Assert.IsFalse(msg.ToDocument()[string.Format("tag[@value=\"{0}\"]", value2)].IsEmpty, "Define tag does not exist!");
            Assert.IsFalse(msg.ToDocument()[string.Format("tag[@value=\"{0}\"]", value3)].IsEmpty, "Text tag does not exist!");

            PageUtils.DeletePageByID(p, id, true);
        }
Esempio n. 51
0
        public void CreatingPagesByBanned()
        {
            //Assumptions:
            //
            //Actions:
            // Create user1 as contributor
            // Ban user1
            // Try to create page from user1
            //Expected result:
            // Forbidden

            Plug p = Utils.BuildPlugForAdmin();

            string       userId   = null;
            string       userName = null;
            DreamMessage msg      = UserUtils.CreateRandomContributor(p, out userId, out userName);


            XDoc ban = new XDoc("bans")
                       .Elem("description", Utils.GetSmallRandomText())
                       .Elem("date.expires", DateTime.Now.AddDays(10))
                       .Start("permissions.revoked")
                       .Elem("operations", banRevokemask)
                       .End()
                       .Start("ban.users")
                       .Start("user").Attr("id", userId).End()
                       .End();

            msg = p.At("site", "bans").Post(ban);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            p = Utils.BuildPlugForUser(userName, UserUtils.DefaultUserPsw);

            string pageTitle = "=" + XUri.DoubleEncode(PageUtils.GenerateUniquePageName());
            string content   = Utils.GetSmallRandomText();

            msg = p.At("pages", pageTitle, "contents").With("edittime", Utils.DateToString(DateTime.MinValue)).
                  PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, content)).Wait();
            Assert.AreEqual(DreamStatus.Forbidden, msg.Status);
        }
Esempio n. 52
0
 public void Init()
 {
     _doc = new XDoc("doc")
            .Attr("source", "http://www.mindtouch.com")
            .Value("Hello ")
            .Start("bold")
            .Attr("style", "blinking")
            .Value("World")
            .End()
            .Value("!")
            .Start("br").End()
            .Start("bold")
            .Value("Cool")
            .End()
            .Start("span")
            .Value("Ce\u00e7i est \"une\" id\u00e9e")
            .End()
            .Start("struct")
            .Start("name").Value("John").End()
            .Start("last").Value("Doe").End()
            .End();
 }
Esempio n. 53
0
        public void HighlightAttributes()
        {
            // NOTE (steveb): test unamibiguous addition, deletion, and replacement

            XDoc a    = XDocFactory.From("<p>the <span class=\"red\">brown</span> fox</p>", MimeType.XML);
            XDoc b    = XDocFactory.From("<p>the <span class=\"blue\">brown</span> fox</p>", MimeType.XML);
            var  diff = XDocDiff.Diff(a, b, 10000);
            List <Tuple <string, string, string> > invisible;
            XDoc doc;
            XDoc before;
            XDoc after;

            XDocDiff.Highlight(diff, out doc, out invisible, out before, out after);

            Assert.AreEqual("<p>the <span class=\"blue\">brown</span> fox</p>", doc.ToString());
            Assert.AreEqual(1, invisible.Count);
            Assert.AreEqual(invisible[0].Item1, "/p/span/@class");
            Assert.AreEqual(invisible[0].Item2, "red");
            Assert.AreEqual(invisible[0].Item3, "blue");
            Assert.AreEqual(a.ToString(), before.ToString());
            Assert.AreEqual(b.ToString(), after.ToString());
        }
Esempio n. 54
0
        public void Service_throwing_on_start_does_not_grab_the_uri()
        {
            XDoc config = new XDoc("config")
                          .Elem("path", "bad")
                          .Elem("throw", "true")
                          .Elem("sid", "sid://mindtouch.com/TestBadStartService");

            try {
                DreamTestHelper.CreateService(_hostInfo, config);
                Assert.Fail("service creation should have failed");
            } catch { }
            var response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();

            Assert.AreEqual(0, response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStartService']")].ListLength);
            config = new XDoc("config")
                     .Elem("path", "bad")
                     .Elem("throw", "false")
                     .Elem("sid", "sid://mindtouch.com/TestBadStartService");
            DreamTestHelper.CreateService(_hostInfo, config);
            response = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Get();
            Assert.AreEqual(1, response.ToDocument()[string.Format("service[sid='sid://mindtouch.com/TestBadStartService']")].ListLength);
        }
 public Result <Score> CreateScoreWithXml(XDoc xdoc, Result <Score> aResult)
 {
     theServiceUri
     .At("scores", "musicxml")
     .Post(DreamMessage.Ok(MimeType.XML, xdoc.ToString()), new Result <DreamMessage>())                    //WORKAROUND
     .WhenDone(delegate(Result <DreamMessage> answer)
     {
         if (!answer.Value.IsSuccessful)
         {
             if (answer.Value.Status != DreamStatus.Ok)
             {
                 aResult.Throw(new Exception());
             }
         }
         else
         {
             aResult.Return(new Score(JObject.Parse(answer.Value.ToText())));
         }
     }
               );
     return(aResult);
 }
Esempio n. 56
0
 private void ConvertAllWidgets(string method, XDoc xhtml, string action, string pageID)
 {
     foreach (XDoc widget in new List <XDoc>(xhtml["//default:span[@class='widget']"]))
     {
         string widgetType = widget["@widgettype"].Contents;
         if (widgetType == string.Empty)
         {
             LogUtils.LogWarning(_log, method + ": no widgettype attribute", widget);
             continue;
         }
         XDoc htmlData = widget[string.Format("default:span[@class='{0}']", widgetType)];
         if (htmlData.IsEmpty)
         {
             LogUtils.LogWarning(_log, method + ": no widget data with class", widgetType, widget);
             continue;
         }
         XDoc data = XDoc.FromXSpan(htmlData);
         if (data.IsEmpty)
         {
             LogUtils.LogWarning(_log, method + ": no xspan data", htmlData);
             continue;
         }
         string widgetID = widget["@widgetid"].Contents;
         XUri   uri      = Env.RootUri.At("wiki-data", widgetType, action).With("id", widgetID);
         if (pageID != "")
         {
             uri = uri.With("pageid", pageID);
         }
         Plug plug        = Plug.New(uri);
         XDoc widgetXhtml = plug.Post(data).Document;
         if (widgetXhtml == null || widgetXhtml.IsEmpty)
         {
             LogUtils.LogWarning(_log, method + string.Format(": null/empty document for /wiki-data/{0}/{1}/ (data)", widgetType, action), data);
             continue;
         }
         LogUtils.LogTrace(_log, method, widgetType, data, widgetXhtml);
         widget.Replace(widgetXhtml);
     }
 }
Esempio n. 57
0
        public void DiffAttributes()
        {
            // NOTE (steveb): test attribute changes

            XDoc a    = XDocFactory.From("<p>the <span class=\"red\">brown</span> fox</p>", MimeType.XML);
            XDoc b    = XDocFactory.From("<p>the <span class=\"blue\">brown</span> fox</p>", MimeType.XML);
            var  diff = XDocDiff.Diff(a, b, 10000);

            Match(diff[0], ArrayDiffKind.Same, XmlNodeType.Element, "p");
            Match(diff[1], ArrayDiffKind.Same, XmlNodeType.EndElement, string.Empty);
            Match(diff[2], ArrayDiffKind.Same, XmlNodeType.Text, "the");
            Match(diff[3], ArrayDiffKind.Same, XmlNodeType.Text, " ");
            Match(diff[4], ArrayDiffKind.Same, XmlNodeType.Element, "span");
            Match(diff[5], ArrayDiffKind.Removed, XmlNodeType.Attribute, "class=red");
            Match(diff[6], ArrayDiffKind.Added, XmlNodeType.Attribute, "class=blue");
            Match(diff[7], ArrayDiffKind.Same, XmlNodeType.EndElement, "");
            Match(diff[8], ArrayDiffKind.Same, XmlNodeType.Text, "brown");
            Match(diff[9], ArrayDiffKind.Same, XmlNodeType.None, "span");
            Match(diff[10], ArrayDiffKind.Same, XmlNodeType.Text, " ");
            Match(diff[11], ArrayDiffKind.Same, XmlNodeType.Text, "fox");
            Match(diff[12], ArrayDiffKind.Same, XmlNodeType.None, "p");
        }
Esempio n. 58
0
        private void SaveUsersAndGroupsToXML()
        {
            XDoc doc = new XDoc(UsersAndGroupsXMLRootName);

            foreach (string confluenceUserName in _convertedUsers.Keys)
            {
                ACConverterUserInfo userInfo = _convertedUsers[confluenceUserName];
                XDoc userDoc = new XDoc(UserXMLTagName);
                userDoc.Attr(ConfluenceUserNameXMLAttributeName, confluenceUserName);
                userDoc.Attr(DekiUserNameXMLAttributeName, userInfo.DekiUserName);
                doc.Add(userDoc);
            }
            foreach (string confluenceGroupName in _convertedGroups.Keys)
            {
                ACConverterGroupInfo groupInfo = _convertedGroups[confluenceGroupName];
                XDoc groupDoc = new XDoc(GroupXMLTagName);
                groupDoc.Attr(ConfluenceGroupNameXMLAttributeName, confluenceGroupName);
                groupDoc.Attr(DekiGroupNameXMLAttributeName, groupInfo.DekiGroupName);
                doc.Add(groupDoc);
            }
            doc.Save(ConvertedUsersAndGroupsFileName);
        }
        public void License_check_returns_checked_clone()
        {
            // Arrange
            var   license         = new XDoc("license");
            var   newLicenseState = LicenseStateType.COMMERCIAL;
            var   newExpiration   = DateTime.UtcNow.AddDays(1);
            var   newPermissions  = Permissions.BROWSE;
            ulong?newSiteOwnerId  = 1;
            var   checkedDate     = DateTime.UtcNow;
            var   licenseData     = new LicenseData()
                                    .WithLicenseDocument(license)
                                    .WithState(LicenseStateType.COMMERCIAL)
                                    .WithExpiration(DateTime.UtcNow)
                                    .WithPermissions(Permissions.NONE)
                                    .WithSiteOwnerUserId(1)
                                    .Checked(DateTime.MinValue);

            _licenseBLMock.Setup(x => x.DetermineLicenseState(It.Is <LicenseData>(l => l.AreSame(licenseData)), true, false))
            .Returns(new LicenseData().WithLicenseDocument(license)
                     .WithState(newLicenseState)
                     .WithExpiration(newExpiration)
                     .WithPermissions(newPermissions)
                     .WithSiteOwnerUserId(newSiteOwnerId)
                     .Checked(checkedDate)
                     );
            _seatingBLMock.Setup(x => x.IsSeatLicensingEnabled(license)).Returns(false);

            // Act
            var checkedLicense = _licenseController.VerifyLicenseData(licenseData, _licenseBLMock.Object, _seatingBLMock.Object);

            // Assert
            _licenseBLMock.Verify(x => x.DetermineLicenseState(It.Is <LicenseData>(l => l.AreSame(licenseData)), true, false), Times.Once());
            Assert.AreEqual(license, checkedLicense.LicenseDoc);
            Assert.AreEqual(newLicenseState, checkedLicense.LicenseState);
            Assert.AreEqual(newExpiration, checkedLicense.LicenseExpiration);
            Assert.AreEqual(newSiteOwnerId, checkedLicense.SiteOwnerUserId);
            Assert.AreEqual(newPermissions, checkedLicense.AnonymousPermissions);
            Assert.AreEqual(checkedDate, checkedLicense.LicenseStateChecked);
        }
Esempio n. 60
0
        public void Can_get_Terms()
        {
            var  mock     = CreateMocks().Item1;
            var  before   = DateTime.UtcNow.AddDays(-2).WithoutMilliseconds();
            var  since    = DateTime.UtcNow.AddDays(-1).WithoutMilliseconds();
            uint limit    = 10;
            uint offset   = 20;
            var  termsXml = new XDoc("results");

            mock.Setup(x => x.GetTermsXml(false, since, before, limit, offset)).Returns(termsXml).AtMostOnce().Verifiable();
            var response = _search.At("log", "terms")
                           .With("since", since)
                           .With("before", before)
                           .With("limit", limit)
                           .With("offset", offset)
                           .With("apikey", Utils.Settings.ApiKey)
                           .Get(new Result <DreamMessage>()).Wait();

            Assert.IsTrue(response.IsSuccessful, response.ToErrorString());
            mock.VerifyAll();
            Assert.AreEqual(termsXml, response.ToDocument());
        }