public void TestAttachmentDescriptionAssociations() { DreamMessage msg = null; Plug p = Utils.BuildPlugForAdmin(); string pageId1, pageId2 = null; msg = PageUtils.CreateRandomPage(p, out pageId1); msg = PageUtils.CreateRandomPage(p, out pageId2); string description = null; string fileid = null; string filename = null; string propertyEtag = null; string propertyName = "urn:deki.mindtouch.com#description"; //Create initial file rev FileUtils.UploadRandomFile(p, pageId1, null, null, out fileid, out filename); //set initial file description description = "Content r1 on p1"; msg = p.At("files", fileid, "properties").WithHeader("Slug", XUri.Encode(propertyName)).PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, description)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "POST property got non 200"); Assert.AreEqual(msg.ToDocument()["/property/contents"].AsText, description, "Contents don't match!"); propertyEtag = msg.ToDocument()["/property/@etag"].AsText; //Validate intitial file description msg = p.At("files", fileid, "info").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "GET file info returned non 200:" + msg.ToString()); Assert.AreEqual(description, msg.ToDocument()["description"].AsText, "Unexpected description"); //update file description description = "Content r1 on p1 updated description 1"; msg = p.At("files", fileid, "properties", XUri.DoubleEncode(propertyName)).WithHeader(DreamHeaders.ETAG, propertyEtag).PutAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, description)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "PUT property got non 200"); Assert.AreEqual(msg.ToDocument()["/property/contents"].AsText, description, "Contents don't match!"); propertyEtag = msg.ToDocument()["/property/@etag"].AsText; //New file revision msg = p.At("pages", pageId1, "files", "=" + filename).PutAsync(DreamMessage.Ok(MimeType.ANY_TEXT, "Some content")).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "File upload failed: " + msg.ToString()); //Updated file description description = "Content r2 on p1"; msg = p.At("files", fileid, "properties", XUri.DoubleEncode(propertyName)).WithHeader(DreamHeaders.ETAG, propertyEtag).PutAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, description)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "PUT property got non 200"); Assert.AreEqual(msg.ToDocument()["/property/contents"].AsText, description, "Contents don't match!"); propertyEtag = msg.ToDocument()["/property/@etag"].AsText; //Move file msg = p.At("files", fileid, "move").With("to", pageId2).Post(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "File move failed:" + msg.ToString()); //Update file description description = "Content r2 on p2"; msg = p.At("files", fileid, "properties", XUri.DoubleEncode(propertyName)).WithHeader(DreamHeaders.ETAG, propertyEtag).PutAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, description)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "PUT property got non 200"); Assert.AreEqual(msg.ToDocument()["/property/contents"].AsText, description, "Contents don't match!"); propertyEtag = msg.ToDocument()["/property/@etag"].AsText; }
public void PageRevert() { // POST:pages/{pageid}/revert // http://developer.mindtouch.com/Deki/API_Reference/POST%3apages%2f%2f%7bpageid%7d%2f%2frevert Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); msg = p.At("pages", "=" + XUri.DoubleEncode(path), "revisions").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsFalse(msg.ToDocument()["page"].IsEmpty); string oldContent = "This is an old content"; PageUtils.SavePage(p, path, oldContent); msg = p.At("pages", id, "revisions").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsFalse(msg.ToDocument()["page"].IsEmpty); PageUtils.SavePage(p, path, "New content 2"); p.At("pages", id, "revert").With("fromrevision", -1).Post(); msg = p.At("pages", id, "contents").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsTrue(msg.ToDocument()["body"].AsText == oldContent); PageUtils.DeletePageByID(p, id, true); }
public static DreamMessage SavePage(Plug p, string parentPath, string pageTitle, string content, string edittime, out string id, out string path) { string title = pageTitle; if (parentPath != string.Empty) { title = parentPath + pageTitle; } title = "=" + XUri.DoubleEncode(title); p = p.At("pages", title, "contents"); if (!string.IsNullOrEmpty(edittime)) { p = p.With("edittime", edittime); } DreamMessage msg = p.PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, content)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page creation failed!"); id = msg.ToDocument()["page/@id"].AsText; path = msg.ToDocument()["page/path"].AsText; Assert.IsTrue(!string.IsNullOrEmpty(path), "Page path is null!"); Assert.IsTrue(!string.IsNullOrEmpty(id), "Page ID is null!"); return(msg); }
public void PageWithLineBreakInLink() { // Login as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Creates a page with contents containing a link with a line break string content = "<p>[[http://www.mindtouch.com/|\n<strong>Link Text</strong>\n]] </p>"; string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); // Retrieve page content msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").With("mode", "view").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page contents retrieval failed"); content = msg.ToDocument()["body"].AsText; // Assert link is rendered correctly XDoc html = XDocFactory.From("<html>" + System.Web.HttpUtility.HtmlDecode(content) + "</html>", MimeType.HTML); Assert.IsTrue(1 == html["//a"].ListLength && "Link Text" == html["//a/strong"].Contents && "http://www.mindtouch.com/" == html["//a/@href"].Contents, "Link did not render correctly"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void ContentNewUser_PointsToInvalidPage_DefaultUserPageContents() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Add content/new-user key to point to some bogus page SiteUtils.AddConfigKey(p, "content/new-user", Utils.GenerateUniqueName()); // Create a user string userid; string username; UserUtils.CreateRandomContributor(p, out userid, out username); // Retrieve user page contents DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode("User:"******"contents").Get(new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve user page contents"); string content = msg.ToDocument()["body"].AsText ?? String.Empty; // Retrieve default new user page content from resources string resource = "MindTouch.Templates.userwelcome.visitor"; msg = p.At("site", "localization").With("resource", resource).Get(new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Unable to retrieve resource for string: " + resource); string expectedContent = "<p>" + msg.AsText() + "</p>" ?? String.Empty; Assert.AreEqual(expectedContent, content, "Unexpected contents"); }
public void DeleteComment() { // DELETE:pages/{pageid}/comments/{commentnumber} // http://developer.mindtouch.com/Deki/API_Reference/DELETE%3apages%2f%2f%7bpageid%7d%2f%2fcomments%2f%2f%7bcommentnumber%7d Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); string comment = Utils.GetSmallRandomText(); DreamMessage postMsg = DreamMessage.Ok(MimeType.TEXT_UTF8, comment); msg = p.At("pages", id, "comments").Post(postMsg); Assert.AreEqual(DreamStatus.Ok, msg.Status); string commentId1 = msg.ToDocument()["@id"].AsText; Assert.IsFalse(string.IsNullOrEmpty(commentId1)); Assert.IsTrue(msg.ToDocument()["content"].AsText == comment); msg = p.At("pages", id, "comments", "1").Delete(); Assert.AreEqual(DreamStatus.Ok, msg.Status); msg = p.At("pages", "=" + XUri.DoubleEncode(path), "comments").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsTrue(msg.ToDocument()["@count"].AsInt == 0); PageUtils.DeletePageByID(p, id, true); }
public void UploadFile() { // Acquire ADMIN permissions Plug p = Utils.BuildPlugForAdmin(); // Create a random page string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); // Create a file string fileName = FileUtils.CreateRamdomFile(null); msg = DreamMessage.FromFile(fileName); fileName = XUri.DoubleEncode(System.IO.Path.GetFileName(fileName)); // Upload file to page msg = p.At("pages", id, "files", "=" + fileName).Put(msg); // Assert file upload returned 200 OK HTTP status Assert.AreEqual(DreamStatus.Ok, msg.Status, "PUT request failed"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void GetSubpages() { // GET:pages/{pageid}/subpages // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2fsubpages Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); msg = p.At("pages", id, "subpages").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsTrue(msg.ToDocument()["page.subpage"].IsEmpty); msg = PageUtils.CreateRandomPage(p, path + "/" + Utils.GenerateUniqueName()); Assert.AreEqual(DreamStatus.Ok, msg.Status); string subid = msg.ToDocument()["page/@id"].AsText; Assert.IsTrue(!string.IsNullOrEmpty(subid)); msg = p.At("pages", "=" + XUri.DoubleEncode(path), "subpages").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsFalse(msg.ToDocument()[string.Format("page.subpage[@id=\"{0}\"]", subid)].IsEmpty); PageUtils.DeletePageByID(p, id, true); }
public void AllFeeds_Get_Ok() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Retrieve all feeds and verify OK status returned DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode("User:"******"feed").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve /pages/{pageid}/feed"); msg = p.At("pages", "=" + XUri.DoubleEncode("User:"******"feed", "new").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve //pages/{pageid}/feed/new"); msg = p.At("site", "feed").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve /site/feed"); msg = p.At("site", "feed", "new").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve /site/feed/new"); msg = p.At("users", "=" + XUri.DoubleEncode(USERNAME), "feed").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve /users/{userid}/feed"); msg = p.At("users", "=" + XUri.DoubleEncode(USERNAME), "favorites", "feed").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve /users/{userid}/favorites/feed"); }
public void ContentNewUser_PointsToValidPage_UserPageGetsPageContents() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); DreamMessage msg; // Create page content/new-user points to string content = "test userpage content"; string pageid; string path; PageUtils.SavePage(p, String.Empty, PageUtils.GenerateUniquePageName(), content, out pageid, out path); // Add content/new-user key SiteUtils.AddConfigKey(p, "content/new-user", path); // Create a user string userid; string username; UserUtils.CreateRandomContributor(p, out userid, out username); // Retrieve a page id. This is to render the template using the "pageid" parameter in the page/{pageid}/contents feature. msg = PageUtils.GetPage(p, String.Empty); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve home page"); uint homepageid = msg.ToDocument()["@id"].AsUInt ?? 0; Assert.IsTrue(homepageid > 0, "Invalid homepage ID"); // Retrieve user page contents and verify it matches content msg = p.At("pages", "=" + XUri.DoubleEncode("User:"******"contents").With("pageid", homepageid).Get(new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve user page contents"); Assert.AreEqual(content, msg.ToDocument()["body"].AsText ?? String.Empty, "Unexpected contents"); }
public void PageCreate_NameDoesNotEqualTitle_Unlinked() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create a page where name != title string path = PageUtils.GenerateUniquePageName(); DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents") .With("title", "unique title") .PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, "Linked test")).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page creation failed!"); // Retrieve the page msg = p.At("pages", "=" + XUri.DoubleEncode(path)).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed!"); // Check that the page is unlinked (i.e. path/@type attribute == custom) string type = msg.ToDocument()["path/@type"].AsText; Assert.AreEqual("custom", type, "Page is unlinked!"); // Delete the page PageUtils.DeletePageByName(p, path, true); }
public void PageWithMailToLink() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create a page with contents containing and email address string content = "<p>[email protected]</p>"; string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); // Retrieve page contents msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").With("mode", "view").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page content retrieval failed"); // Assert email link is rendered correctly XDoc html = XDocFactory.From("<html>" + System.Web.HttpUtility.HtmlDecode(msg.ToDocument()["body"].AsText) + "</html>", MimeType.HTML); Assert.IsTrue("mailto:[email protected]" == html["//a/@href"].AsText, "Link did not render correctly"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public static DreamMessage RestrictPage(Plug p, string path, string cascade, string restriction) { path = "=" + XUri.DoubleEncode(path); XDoc securityDoc = new XDoc("security"); if (!string.IsNullOrEmpty(restriction)) { securityDoc.Start("permissions.page").Start("restriction").Value(restriction).End().End(); } //if (userIdGrantsHash != null && userIdGrantsHash.Keys.Count > 0) //{ // x.Start("grants"); // foreach (KeyValuePair<int, List<string>> grantsForUser in userIdGrantsHash) // { // foreach (string grant in grantsForUser.Value) // { // x.Start("grant").Start("permissions").Start("role").Value(grant).End().End().Start("user").Attr("id", grantsForUser.Key).End().End(); // } // } // x.End(); //} DreamMessage msg = p.At("pages", path, "security").WithQuery("cascade=" + cascade).Put(securityDoc); Assert.AreEqual(DreamStatus.Ok, msg.Status); return(msg); }
public static DreamMessage GetPage(Plug p, string path, PageContentFilterSettings pageContentFilter) { path = "=" + XUri.DoubleEncode(path); DreamMessage msg = null; var contentFilter = new List <string>(); if (pageContentFilter.ExcludeOutboundLinks) { contentFilter.Add("outbound"); } if (pageContentFilter.ExcludeInboundLinks) { contentFilter.Add("inbound"); } var pagesPlug = p.At("pages", path); if (contentFilter.Count > 0) { pagesPlug = pagesPlug.With("exclude", String.Join(",", contentFilter.ToArray())); } msg = pagesPlug.GetAsync().Wait(); Assert.IsTrue(msg.Status == DreamStatus.Ok || msg.Status == DreamStatus.NotFound, string.Format("Unexpected status: {0}", msg.Status)); return(msg); }
public static DreamMessage DeletePageByName(Plug p, string path, bool recurse) { path = "=" + XUri.DoubleEncode(path); var msg = p.At("pages", path).WithQuery("recursive=" + recurse.ToString()).DeleteAsync().Wait(); Assert.IsTrue(msg.IsSuccessful, "Page delete by name failed!"); return(msg); }
public void CommentsForTreeOfPages() { //Assumptions: //Actions: // Create tree of pages // Add comment to every page // Try to get all comments //Expected result: // All comments received Plug p = Utils.BuildPlugForAdmin(); string baseTreePath = PageUtils.BuildPageTree(p); string commentForA = Utils.GetSmallRandomText(); DreamMessage postMsg = DreamMessage.Ok(MimeType.TEXT_UTF8, commentForA); DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "comments").Post(postMsg); string commentForAId = msg.ToDocument()["@id"].AsText; string commentForB = Utils.GetSmallRandomText(); postMsg = DreamMessage.Ok(MimeType.TEXT_UTF8, commentForB); msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B"), "comments").Post(postMsg); string commentForBId = msg.ToDocument()["@id"].AsText; string commentForC = Utils.GetSmallRandomText(); postMsg = DreamMessage.Ok(MimeType.TEXT_UTF8, commentForC); msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B/C"), "comments").Post(postMsg); string commentForCId = msg.ToDocument()["@id"].AsText; string commentForD = Utils.GetSmallRandomText(); postMsg = DreamMessage.Ok(MimeType.TEXT_UTF8, commentForD); msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B/D"), "comments").Post(postMsg); string commentForDId = msg.ToDocument()["@id"].AsText; string commentForE1 = Utils.GetSmallRandomText(); postMsg = DreamMessage.Ok(MimeType.TEXT_UTF8, commentForE1); msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/E"), "comments").Post(postMsg); string commentForE1Id = msg.ToDocument()["@id"].AsText; string commentForE2 = Utils.GetSmallRandomText(); postMsg = DreamMessage.Ok(MimeType.TEXT_UTF8, commentForE2); msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/E"), "comments").Post(postMsg); string commentForE2Id = msg.ToDocument()["@id"].AsText; msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath), "comments").With("depth", "infinity").Get(); Assert.IsTrue(msg.ToDocument()["@count"].AsInt == 6); Assert.AreEqual(msg.ToDocument()[string.Format("comment[@id='{0}']/content", commentForAId)].AsText, commentForA); Assert.AreEqual(msg.ToDocument()[string.Format("comment[@id='{0}']/content", commentForBId)].AsText, commentForB); Assert.AreEqual(msg.ToDocument()[string.Format("comment[@id='{0}']/content", commentForCId)].AsText, commentForC); Assert.AreEqual(msg.ToDocument()[string.Format("comment[@id='{0}']/content", commentForDId)].AsText, commentForD); Assert.AreEqual(msg.ToDocument()[string.Format("comment[@id='{0}']/content", commentForE1Id)].AsText, commentForE1); Assert.AreEqual(msg.ToDocument()[string.Format("comment[@id='{0}']/content", commentForE2Id)].AsText, commentForE2); }
public void TestPrivateAndPostSecurity() { //Actions: // Create user with role "Viewer" // Admin sets restriction:private on A/* ; grant to user viewer // User adds grant for user viewer on A/B/C //Expected result: // User unable to set the grant Plug p = Utils.BuildPlugForAdmin(); string baseTreePath = PageUtils.BuildPageTree(p); string username = null; string userid = null; DreamMessage msg = UserUtils.CreateRandomUser(p, "Viewer", out userid, out username); XDoc securityDoc = new XDoc("security") .Start("permissions.page") .Elem("restriction", "Private") .End() .Start("grants") .Start("grant") .Start("permissions") .Elem("role", "Viewer") .End() .Start("user").Attr("id", userid).End() .End() .End(); msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "security"). WithQuery("cascade=absolute").Put(securityDoc); Assert.AreEqual(DreamStatus.Ok, msg.Status); p = Utils.BuildPlugForUser(username, "password"); securityDoc = new XDoc("security") .Start("permissions.page") .Elem("restriction", "Private") .End() .Start("grants") .Start("grant") .Start("permissions") .Elem("role", "Contributor") .End() .Start("user").Attr("id", userid).End() .End() .End(); try { msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B/C"), "security"). WithQuery("cascade=absolute").Post(securityDoc); Assert.IsTrue(false); } catch (DreamResponseException ex) { Assert.IsTrue(ex.Response.Status == DreamStatus.Forbidden); } }
/// <summary> /// Retrieves the title as the {pageid} parameter for an API call. The output is double uri encoded. /// Ex. =User:Admin%252fMyPage /// </summary> public string AsApiParam() { // returns the title in an {pageid} api consumable form if (IsHomepage) { return("home"); } return("=" + NSAndPathToString(_namespace, XUri.DoubleEncode(AsUnprefixedDbPath()))); }
public static DreamMessage MovePage(Plug p, string path, string targetPath) { path = "=" + XUri.DoubleEncode(path); DreamMessage msg = p.At("pages", path, "move").With("to", targetPath).Post(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page move failed!"); return(msg); }
public static DreamMessage CreateRandomRole(Plug p, out string name) { XDoc permissionsDoc = new XDoc("permissions") .Elem("operations", "READ"); name = Utils.GenerateUniqueName(); return(p.At("site", "roles", "=" + XUri.DoubleEncode(name)).Put(permissionsDoc)); }
public void PageCreate_PagePathEncoding_CorrectName() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); DreamMessage msg; string pathmeta; string name; // Create parent for all encoding test page creations string parentid; string parentpath; PageUtils.CreateRandomPage(p, out parentid, out parentpath); // Test cases <Input encoded name, Expected human-readable name> // null == BAD REQUEST // FEEL FREE TO ADD TEST CASES Dictionary <string, string> d = new Dictionary <string, string>(); d.Add(String.Empty, null); d.Add("%2520", null); d.Add("test", "test"); d.Add("foo%2520bar", "foo_bar"); // TODO: figure out special/edge cases // BUG 8051: // d.Add("fooo%252520baar", "fooo%20baar"); // Iterate through every testcase foreach (KeyValuePair <string, string> testcase in d) { // Create page with following path: parentpath/key msg = p.At("pages", "=" + XUri.DoubleEncode(parentpath + "/") + testcase.Key, "contents") .PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, "Page Encoding Test")).Wait(); // if value is null, assert bad request returned if (testcase.Value == null) { Assert.AreEqual(DreamStatus.BadRequest, msg.Status, String.Format("Page creation succeeded for bogus name?!")); } else { Assert.AreEqual(DreamStatus.Ok, msg.Status, String.Format("Page {0} create failed!", testcase.Key)); // Retrieve decoded segment and compare it to expected value pathmeta = msg.ToDocument()["page/path"].AsText; name = pathmeta.Substring(pathmeta.LastIndexOf("/") + 1); Assert.AreEqual(testcase.Value, name, "Path decoded incorrectly"); } } // Delete parent page and all children PageUtils.DeletePageByID(p, parentid, true); }
public void CreatingPageByUnbanned() { //Assumptions: // //Actions: // Create user as contributor // Ban user // Unban user // Try to create page from user //Expected result: // Ok 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); string banid = msg.ToDocument()["@id"].AsText; Assert.IsTrue(!string.IsNullOrEmpty(banid)); msg = p.At("site", "bans", banid).Delete(); 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.Ok, msg.Status); string pageId = msg.ToDocument()["page/@id"].AsText; p = Utils.BuildPlugForAdmin(); PageUtils.DeletePageByID(p, pageId, true); }
public void Contents_PageWithTalkPage_ManyParameterChanges_CorrectContent() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create a page with some content and save edittime string path = PageUtils.GenerateUniquePageName(); string content = "test content"; string title = "test title"; string comment = "new page!"; MimeType mime = MimeType.TEXT_UTF8; DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents") .With("title", title) .With("comment", comment) .Post(DreamMessage.Ok(mime, content), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Creating page failed"); msg = PageUtils.GetPage(p, path); string edittime = msg.ToDocument()["date.edited"].AsText; Assert.IsNotNull(edittime, "No date.edited in page document!"); // Create a talk page string talkid; string talkpath; PageUtils.CreateTalkPage(p, path, out talkid, out talkpath); // Now make some changes string lang = "de"; content = "new test content!"; comment = "edit page!"; title = "new title!"; mime = MimeType.TEXT; msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents") .With("title", title) .With("comment", comment) .With("language", lang) .With("edittime", edittime) .Post(DreamMessage.Ok(mime, content), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Editing page contents failed"); // Verify changes msg = PageUtils.GetPage(p, path); Assert.AreEqual(title, msg.ToDocument()["title"].AsText ?? String.Empty, "Unexpected title"); Assert.AreEqual(content, msg.ToDocument()["summary"].AsText ?? String.Empty, "Unexpected content"); Assert.AreEqual(lang, msg.ToDocument()["properties/language"].AsText ?? String.Empty, "Unexpected language"); Assert.AreEqual(comment + "; " + "2 words added; " + "page display name changed to '" + title + "'; " + "page language changed to Deutsch", msg.ToDocument()["description"].AsText ?? String.Empty, "Unexpected description"); }
public void Contents_BadTitle_Conflict() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Attempt to save a page with a bad title string path = PageUtils.GenerateUniquePageName(); string title = " "; DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").With("title", title). Post(DreamMessage.Ok(MimeType.TEXT_UTF8, "test content"), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Conflict, msg.Status, "Saving page with invalid title succeeded?!"); }
public static DreamMessage CreateTalkPage(Plug p, string pagepath, out string talkid, out string talkpath) { talkpath = "Talk:" + pagepath; DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(talkpath), "contents"). Post(DreamMessage.Ok(MimeType.TEXT_UTF8, "test talk page"), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Talk page creation failed"); talkid = msg.ToDocument()["page/@id"].AsText ?? String.Empty; talkpath = msg.ToDocument()["page/path"].AsText ?? String.Empty; Assert.IsTrue(!string.IsNullOrEmpty(talkpath), "Page path is null!"); Assert.IsTrue(!string.IsNullOrEmpty(talkid), "Page ID is null!"); return(msg); }
public static DreamMessage CreatePageWithNamespace(Plug p, string name_space, out string id, out string path) { path = name_space + ":" + PageUtils.GenerateUniquePageName(); DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents"). Post(DreamMessage.Ok(MimeType.TEXT_UTF8, "test talk page"), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, name_space + " page creation failed"); id = msg.ToDocument()["page/@id"].AsText ?? String.Empty; path = msg.ToDocument()["page/path"].AsText ?? String.Empty; Assert.IsTrue(!string.IsNullOrEmpty(path), "Page path is null!"); Assert.IsTrue(!string.IsNullOrEmpty(id), "Page ID is null!"); return(msg); }
public void InvokeNoUSCTemplateWithUnsafeContent() { // Create a contributor string userid; string username; DreamMessage msg = UserUtils.CreateRandomContributor(Utils.BuildPlugForAdmin(), out userid, out username); Plug p = Utils.BuildPlugForUser(username, "password"); // Check that user does not have USC permissions Assert.IsFalse((msg.ToDocument()["permissions.effective/operations"].AsText ?? "UNSAFECONTENT").Contains("UNSAFECONTENT"), "Created user has UNSAFECONTENT permissions"); // Create a template with unsafe content string safe_content = "This is a template"; string unsafe_content = "<p><script type=\"text/javascript\">document.write(\"With unsafe content\");</script></p>"; string template_content = safe_content + unsafe_content; string template_name = "test" + DateTime.Now.Ticks.ToString(); string template_path = "Template:" + template_name; msg = p.At("pages", "=" + XUri.DoubleEncode(template_path), "contents") .Post(DreamMessage.Ok(MimeType.TEXT_UTF8, template_content), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Template page creation failed!"); // Log in as ADMIN p = Utils.BuildPlugForAdmin(); // There are 3 different dekiscript methods to invoke templates string[] template_call = new string[] { "<pre class=\"script\">Template('" + template_name + "');</pre>", "<pre class=\"script\">Template." + template_name + "();</pre>", "<pre class=\"script\">wiki.Template('" + template_name + "');</pre>" }; // Create page that calls template string page_id; string page_path; PageUtils.CreateRandomPage(p, out page_id, out page_path); for (int i = 0; i < template_call.Length; i++) { // Use template_call[i] as page contents msg = p.At("pages", "=" + XUri.DoubleEncode(page_path), "contents") .With("edittime", String.Format("{0:yyyyMMddHHmmss}", DateTime.Now)) .Post(DreamMessage.Ok(MimeType.TEXT_UTF8, template_call[i]), new Result <DreamMessage>()).Wait(); // Retrieve page contents. Expected only safe content present msg = p.At("pages", "=" + XUri.DoubleEncode(page_path), "contents").Get(new Result <DreamMessage>()).Wait(); Assert.AreEqual(safe_content, msg.ToDocument()["body"].AsText ?? String.Empty, "Unexpected contents"); } // Clean up PageUtils.DeletePageByName(p, template_path, true); }
private string ComputeSpaceRootPath(string basePath, RemoteSpaceSummary space, string teamlabel) { string ret = string.Empty; if (space.type == ConfluencePersonalSpaceTypeName) { //Personal space path. Confluence uses "~username" as key of personal space string userName = space.key.Substring(1); string dekiUserName = userName; ACConverterUserInfo userInfo = null; if (_convertedUsers.TryGetValue(userName.ToLower(), out userInfo)) { dekiUserName = userInfo.DekiUserName; } ret = basePath; if (!string.IsNullOrEmpty(basePath)) { ret += XUri.DoubleEncode("/"); } //append team label path here if it exists if (!String.IsNullOrEmpty(teamlabel)) { ret += Utils.DoubleUrlEncode(teamlabel + "/"); } ret = Utils.DoubleUrlEncode(Utils.GetDekiUserPageByUserName(dekiUserName)); } else { // Global space path ret = basePath; if (!string.IsNullOrEmpty(basePath)) { ret += XUri.DoubleEncode("/"); } //append team label path here if it exists if (!String.IsNullOrEmpty(teamlabel)) { //there is already a slash at the end of the ret so no need to add it // if (( ret.Length == 0) || (ret.LastIndexOf('/') != ret.Length)) // ret += XUri.DoubleEncode("/"); ret += Utils.DoubleUrlEncode(teamlabel + "/"); } ret += Utils.DoubleUrlEncode(space.key); } return(ret); }
public void GetPageProperties() { Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); msg = p.At("pages", id, "properties").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status); msg = p.At("pages", "=" + XUri.DoubleEncode(path), "properties").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status); PageUtils.DeletePageByID(p, id, true); }
public void GetPageDiffWithoutTags() { // 1. Create a page with some content // 2. Retrieve revisions list // (3) Assert revisions list is populated // 4. Save page with some new content // 5. Retrieve revisions list // (6) Assret revisions list is populated // 7. Perform a diff // (8) Assert diff result matches expected diff // 9. Delete the page // GET:pages/{pageid}/revisions // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2frevisions Plug p = Utils.BuildPlugForAdmin(); string content = "This is test content"; string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); msg = p.At("pages", "=" + XUri.DoubleEncode(path), "revisions").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page revisions retrieval failed (1)"); Assert.IsFalse(msg.ToDocument()["page"].IsEmpty, "Page revisions list is empty?! (1)"); PageUtils.SavePage(p, path, "New content"); msg = p.At("pages", id, "revisions").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page revisions retrieval failed (2)"); Assert.IsFalse(msg.ToDocument()["page"].IsEmpty, "Page revisions list is empty?! (2)"); // GET:pages/{pageid}/diff // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2fdiff msg = p.At("pages", id, "diff").With("revision", "head").With("previous", -1).Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "diff generation failed"); string diff = "<ins>New</ins><del>This is test</del> content"; Assert.AreEqual(diff, msg.ToDocument().Contents, "diff result does not match expected result"); PageUtils.DeletePageByID(p, id, true); }