Example #1
0
        public void GetFiles()
        {
            // GET:archive/files
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3aarchive%2f%2ffiles

            // 1. Create a page
            // 2. Upload a file attachment to page
            // 3. Delete said attachment
            // (4) Assert file existence in archive: fileID = file.archiveID
            // 5. Delete page

            Plug         p = Utils.BuildPlugForAdmin();
            DreamMessage msg;

            string id = null;

            msg = PageUtils.CreateRandomPage(p, out id);

            string fileid = null;

            msg = FileUtils.UploadRandomFile(p, id, out fileid);

            msg = FileUtils.DeleteFile(p, fileid);

            msg = p.At("archive", "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed");
            //Assert.IsFalse(msg.ToDocument()[string.Format("file.archive[@id=\"{0}\"]", fileid)].IsEmpty, "File is not in archive!");

            //PageUtils.DeletePageByID(p, id, true);
        }
Example #2
0
        public void AdminExcludeInboundLinksTest()
        {
            // Log in as ADMIN
            Plug p = Utils.BuildPlugForAdmin();

            // Create page1
            string       page1id;
            string       page1path;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out page1id, out page1path);

            // Create page2 with contents containing a link to page1
            string page2id;
            string page2path;
            string content = string.Format("<a href=\"mks://localhost/{0}\" class=\"internal\" title=\"{0}\">a link to page1</a>", page1path);

            msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out page2id, out page2path);

            // Retrieve outbound links of page2. Verify link points to page1.
            msg = p.At("pages", page2id, "links").With("dir", "from").Get();
            Assert.IsTrue(msg.ToDocument()["page/@id"].AsText == page1id, "Outbound link of page with link does not exist!");

            // Retrieve inbound links to page1. Verify link originates from page2.
            msg = p.At("pages", page1id, "links").With("dir", "to").Get();
            Assert.IsTrue(msg.ToDocument()["page/@id"].AsText == page2id, "Inbound link of page linked to is not present!");

            // Do not exclude anything
            msg = PageUtils.GetPage(p, page1path, new PageContentFilterSettings());
            var doc = msg.ToDocument();

            Assert.IsTrue(!doc["inbound"].IsEmpty, "[1] Inbound links information was excluded even though it should not have been excluded");
            Assert.IsTrue(!doc["outbound"].IsEmpty, "[2] Outbound links information was excluded even though it should not have been excluded");

            // Exclude both inbound and outbound
            msg = PageUtils.GetPage(p, page1path, new PageContentFilterSettings {
                ExcludeInboundLinks = true, ExcludeOutboundLinks = true
            });
            doc = msg.ToDocument();
            Assert.IsTrue(doc["inbound"].IsEmpty, "[3] Inbound links information wasn't excluded");
            Assert.IsTrue(doc["outbound"].IsEmpty, "[4] Outbound links information wasn't excluded");

            // exclude outbound only
            msg = PageUtils.GetPage(p, page1path, new PageContentFilterSettings {
                ExcludeInboundLinks = false, ExcludeOutboundLinks = true
            });
            doc = msg.ToDocument();
            Assert.IsTrue(!doc["inbound"].IsEmpty, "[5] Inbound links information was excluded even though it should not be excluded");
            Assert.IsTrue(doc["outbound"].IsEmpty, "[6] Outbound links information wasn't excluded");

            // Only exclude inbound
            msg = PageUtils.GetPage(p, page1path, new PageContentFilterSettings {
                ExcludeInboundLinks = true, ExcludeOutboundLinks = false
            });
            doc = msg.ToDocument();
            Assert.IsTrue(doc["inbound"].IsEmpty, "[7] Inbound links information wasn't excluded");
            Assert.IsTrue(!doc["outbound"].IsEmpty, "[8] Outbound links information was exclude even though it should not be excluded");

            // Delete the pages
            PageUtils.DeletePageByID(p, page1id, true);
            PageUtils.DeletePageByID(p, page2id, true);
        }
Example #3
0
        public void GetFileInfo()
        {
            // GET:pages/{pageid}/files/{filename}/info
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2ffiles%2f%2f%7bfilename%7d%2f%2finfo

            Plug p = Utils.BuildPlugForAdmin();

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

            string fileid   = null;
            string filename = null;

            msg = FileUtils.UploadRandomFile(p, id, out fileid, out filename);

            msg = p.At("pages", id, "files", "=" + filename, "info").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.ToDocument()["@id"].AsText == fileid);
            Assert.IsTrue(msg.ToDocument()["page.parent/@id"].AsText == id);

            // GET:files/{fileid}/info
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3afiles%2f%2f%7bfileid%7d%2f%2finfo

            msg = p.At("files", fileid, "info").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.ToDocument()["@id"].AsText == fileid);
            Assert.IsTrue(msg.ToDocument()["page.parent/@id"].AsText == id);

            PageUtils.DeletePageByID(p, id, true);
        }
Example #4
0
        public void GetSubpages()
        {
            // GET:archive/pages/{pageid}/subpages
            // ...

            // 1. Create a page
            // 2. Create subpage to page
            // 3. Delete page (recursively)
            // (4a) Assert subpage archive ID matches deleted subpage ID
            // (4b) Assert subpage path is consistent

            Plug p = Utils.BuildPlugForAdmin();

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

            string subid   = null;
            string subpath = null;

            msg = PageUtils.CreateRandomPage(p, path + "/" + Utils.GenerateUniqueName(), out subid, out subpath);

            PageUtils.DeletePageByID(p, id, true);

            msg = p.At("archive", "pages", id, "subpages").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed");
            Assert.IsTrue((msg.ToDocument()["page.archive/@id"].AsText ?? String.Empty) == subid, "Page ID and archived page ID do not match!");
            Assert.AreEqual(subpath, msg.ToDocument()["//path"].AsText ?? String.Empty, "Page path and archived page path do not match!");
        }
Example #5
0
        public void ImportTime_query_arg_forces_import_property_creation()
        {
            // Log in as ADMIN
            Plug p = Utils.BuildPlugForAdmin();

            // Create a page
            string id   = null;
            string path = null;

            PageUtils.CreateRandomPage(p, out id, out path);

            // Set importTime property to page
            var importTime = DateTime.UtcNow.ToString("yyyyMMddHHmmss");

            p.At("pages", id, "contents")
            .With("edittime", DateTime.MaxValue.ToString("yyyyMMddHHmmss"))
            .With("redirects", "0")
            .With("importtime", importTime)
            .Post(DreamMessage.Ok(MimeType.TEXT_UTF8, "foo"), new Result <DreamMessage>()).Wait();

            // Retrieve property and assert the dates match
            var msg = p.At("pages", id, "properties", XUri.EncodeSegment("mindtouch.import#info")).Get(new Result <DreamMessage>()).Wait();

            Assert.IsTrue(msg.IsSuccessful);
            Assert.AreEqual(importTime, (msg.ToDocument()["date.modified"].AsDate ?? DateTime.MinValue).ToString("yyyyMMddHHmmss"), "Unexpected date");
        }
Example #6
0
        public void UploadFileWithLongExtensionTwoTimes()
        {
            // 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 with random content and a long extension
            string fileid   = null;
            string filename = System.IO.Path.GetTempPath() + "file" + Utils.GenerateUniqueName() + "." + Utils.GenerateUniqueName();

            filename = filename.PadRight(250, 'a');
            FileUtils.CreateFile(FileUtils.GenerateRandomContent(), filename);

            // Upload the file and assert it uploaded successfully
            msg = FileUtils.UploadFile(p, id, string.Empty, out fileid, filename);
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "File upload failed!");

            // Create a file with the same name but different content and upload and replace existing file
            FileUtils.CreateFile(FileUtils.GenerateRandomContent(), filename);
            msg = FileUtils.UploadFile(p, id, string.Empty, out fileid, filename);

            // Assert uploaded file has 2 revisions
            msg = p.At("pages", id, "files").Get();
            Assert.AreEqual(2, msg.ToDocument()["file/revisions/@count"].AsInt, "File revision count does not equal 2!");

            // Delete the page
            PageUtils.DeletePageByID(p, id, true);
        }
Example #7
0
        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);
        }
Example #8
0
        public void RatePageInvalidScore()
        {
            // Build ADMIN plug
            Plug p = Utils.BuildPlugForAdmin();

            // Create a random page
            string       id   = null;
            string       path = null;
            DreamMessage msg  = PageUtils.CreateRandomPage(p, out id, out path);

            // Attempt to rate a page without the query parameter 'score'
            msg = p.At("pages", id, "ratings").PostAsync().Wait();
            Assert.AreEqual(DreamStatus.BadRequest, msg.Status, "Page rating did not return 400: " + msg.ToString());

            // Attempt to rate page a '2' and assert a 'Bad Request' HTTP response is returned
            msg = p.At("pages", id, "ratings").With("score", 2).PostAsync().Wait();
            Assert.AreEqual(DreamStatus.BadRequest, msg.Status, "Page rating did not return 400: " + msg.ToString());

            // Attempt to rate page a '0.5' and assert a 'Bad Request' HTTP response is returned
            msg = p.At("pages", id, "ratings").With("score", 0.5).PostAsync().Wait();
            Assert.AreEqual(DreamStatus.BadRequest, msg.Status, "Page rating did not return 400: " + msg.ToString());

            // Delete the page
            PageUtils.DeletePageByID(p, id, true);
        }
Example #9
0
        public void GetSiteTagsWithPages()
        {
            // 1. Create random page
            // 2. Generate a random tag and attach it to page
            // (3) Assert tag exists with correct tag and page IDs
            // 4. Delete the page

            Plug         p         = Utils.BuildPlugForAdmin();
            string       page_id   = null;
            string       page_path = null;
            DreamMessage msg       = PageUtils.CreateRandomPage(p, out page_id, out page_path);

            Guid guid = Guid.NewGuid();

            XDoc tagsDoc = new XDoc("tags")
                           .Start("tag").Attr("value", guid.ToString()).End();

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

            uint tag_id = msg.ToDocument()["tag/@id"].AsUInt ?? 0;

            msg = p.At("site", "tags").With("pages", true).Get();

            Assert.IsTrue(msg.Status == DreamStatus.Ok, "GET request failed");
            Assert.IsFalse(msg.ToDocument()[string.Format("tag[@id=\"{0}\"]/pages/page[@id=\"{1}\"]", tag_id, page_id)].IsEmpty, "Tag with specified tag/page ID does not exist!");

            PageUtils.DeletePageByID(p, page_id, true);
        }
Example #10
0
        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;
        }
Example #11
0
        public void CheckDescription()
        {
            // GET:pages/{pageid}/files/{filename}/description
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2ffiles%2f%2f%7bfilename%7d%2f%2fdescription

            Plug p = Utils.BuildPlugForAdmin();

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

            string description = "File description text";
            string fileid      = null;
            string filename    = null;

            FileUtils.UploadRandomFile(p, id, null, description, out fileid, out filename);

            msg = p.At("pages", id, "files", "=" + filename, "description").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.AsText() == description);

            // GET:files/{fileid}/description
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3afiles%2f%2f%7bfileid%7d%2f%2fdescription

            msg = p.At("files", fileid, "description").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.AsText() == description);

            PageUtils.DeletePageByID(p, id, true);
        }
Example #12
0
        public void PostBigDescription()
        {
            //Assumptions:
            //Actions:
            // create page
            // create big description
            // post file with big description to page
            //Expected result:
            // Ok

            Plug p = Utils.BuildPlugForAdmin();

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

            try
            {
                string description = Utils.GetSmallRandomText();// Utils.GetSmallRandomText();
                string fileid      = null;
                string filename    = null;
                msg = FileUtils.UploadRandomFile(p, id, null, description, out fileid, out filename);

                msg = p.At("pages", id, "files", "=" + filename, "description").Get();
                Assert.AreEqual(DreamStatus.Ok, msg.Status);
                Assert.IsTrue(msg.AsText() == description);
            }
            catch (DreamResponseException)
            {
                Assert.Fail();
            }

            PageUtils.DeletePageByID(p, id, true);
        }
Example #13
0
        public void DeleteFileThroughPage()
        {
            // DELETE:pages/{pageid}/files/{filename}
            // http://developer.mindtouch.com/Deki/API_Reference/DELETE%3apages%2f%2f%7bpageid%7d%2f%2ffiles%2f%2f%7bfilename%7d

            Plug p = Utils.BuildPlugForAdmin();

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

            string fileid   = null;
            string filename = null;

            FileUtils.UploadRandomFile(p, id, out fileid, out filename);

            msg = p.At("pages", id, "files", "=" + filename).Delete();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            msg = p.At("pages", id, "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.ToDocument()["@count"].AsInt == 0);

            msg = p.At("archive", "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsFalse(msg.ToDocument()[string.Format("file.archive[@id=\"{0}\"]", fileid)].IsEmpty);

            PageUtils.DeletePageByID(p, id, true);
        }
Example #14
0
        public void GetFileInfo()
        {
            // GET:archive/files/{fileid}/info
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3aarchive%2f%2ffiles%2f%2f%7bfileid%7d%2f%2finfo

            // 1. Create a page
            // 2. Upload a file
            // 3. Delete file
            // (4) Assert fileID matches file.archiveID
            // 5. Delete page

            Plug p = Utils.BuildPlugForAdmin();

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

            string fileid = null;

            msg = FileUtils.UploadRandomFile(p, id, out fileid);

            msg = FileUtils.DeleteFile(p, fileid);

            msg = p.At("archive", "files", fileid, "info").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed");
            Assert.IsTrue((msg.ToDocument()["@id"].AsText ?? String.Empty) == fileid, "File archive ID does not match file ID!");

            PageUtils.DeletePageByID(p, id, true);
        }
Example #15
0
        public void UploadFileOnDeletedPage()
        {
            // 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);

            // Delete the page
            PageUtils.DeletePageByID(p, id, true);

            try
            {
                // Attempt to upload file to deleted page
                string fileid   = null;
                string filename = null;
                msg = FileUtils.UploadRandomFile(p, id, out fileid, out filename);

                // Should not get here
                Assert.IsTrue(false, "File upload succeeded?!");
            }
            catch (DreamResponseException ex)
            {
                // Assert Not Found HTTP status returned
                Assert.AreEqual(DreamStatus.NotFound, ex.Response.Status, "Status other than \"Not Found\" returned");
            }
        }
Example #16
0
        public void GetTagsByPartialName()
        {
            // 1. Create random page
            // 2. Generate a random text tag and attach it to page
            // (3) Assert the tag is returned when searching for the first 3 characters of the value
            // 4. Delete the page

            Plug         p       = Utils.BuildPlugForAdmin();
            string       page_id = null;
            string       path    = null;
            DreamMessage msg     = PageUtils.CreateRandomPage(p, out page_id, out path);

            string guid    = Guid.NewGuid().ToString();
            XDoc   tagsDoc = new XDoc("tags")
                             .Start("tag").Attr("value", guid).End();

            msg = p.At("pages", page_id, "tags").Put(tagsDoc);
            Assert.IsTrue(msg.Status == DreamStatus.Ok, "PUT request failed");
            uint tag_id = msg.ToDocument()["tag/@id"].AsUInt ?? 0;

            // GET:site/tags?q=partialName
            msg = p.At("site", "tags").With("pages", true).With("type", "text").With("q", guid.Substring(0, 3)).Get();
            Assert.IsTrue(msg.Status == DreamStatus.Ok, "GET request failed");
            Assert.IsFalse(msg.ToDocument()[string.Format("tag[@id=\"{0}\"]/pages/page[@id=\"{1}\"]", tag_id, page_id)].IsEmpty, "Tag was not returned!");

            PageUtils.DeletePageByID(p, page_id, true);
        }
Example #17
0
        public void UploadFileWithLongExtension()
        {
            // 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 with random content and a long extension
            string fileid   = null;
            string filename = System.IO.Path.GetTempPath() + "file" + Utils.GenerateUniqueName() + "." + Utils.GenerateUniqueName();

            filename = filename.PadRight(250, 'a');
            FileUtils.CreateFile(FileUtils.GenerateRandomContent(), filename);

            // Upload the file, assert it uploaded successfully, and store filename returned in document
            msg = FileUtils.UploadFile(p, id, string.Empty, out fileid, filename);
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "File upload failed");
            string savedFileName = msg.ToDocument()["filename"].AsText;

            // Retrieve page files and assert file is present
            msg = p.At("pages", id, "files").Get();
            Assert.AreEqual(savedFileName, msg.ToDocument()["file/filename"].AsText, "File is not attached to page!");

            // Delete the page
            PageUtils.DeletePageByID(p, id, true);
        }
Example #18
0
        public void RenameExistingTagDueToAccentCapitalization()
        {
            Plug         p       = Utils.BuildPlugForAdmin();
            string       page_id = null;
            string       path    = null;
            DreamMessage msg     = PageUtils.CreateRandomPage(p, out page_id, out path);

            // set lowercase tag
            string t       = StringUtil.CreateAlphaNumericKey(10).ToLower();
            XDoc   tagsDoc = new XDoc("tags")
                             .Start("tag").Attr("value", t).End();

            msg = p.At("pages", page_id, "tags").Put(tagsDoc);
            Assert.IsTrue(msg.Status == DreamStatus.Ok, "PUT request failed");
            uint tag_id = msg.ToDocument()["tag/@id"].AsUInt ?? 0;

            // set uppercase tag on new page
            msg     = PageUtils.CreateRandomPage(p, out page_id, out path);
            t       = t.ToUpper();
            tagsDoc = new XDoc("tags")
                      .Start("tag").Attr("value", t).End();
            msg = p.At("pages", page_id, "tags").Put(tagsDoc);
            Assert.IsTrue(msg.Status == DreamStatus.Ok, "PUT request failed");
            tag_id = msg.ToDocument()["tag/@id"].AsUInt ?? 0;
            string returnedTag = msg.ToDocument()["tag/@value"].AsText;

            Assert.AreEqual(t, returnedTag, "Tag not renamed!");
        }
Example #19
0
        public void UploadFileWithConfigExtension()
        {
            // 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 with random content and a .config extension
            byte[] content  = FileUtils.GenerateRandomContent();
            string fileid   = null;
            string filename = System.IO.Path.GetTempPath() + "/=file" + Utils.GenerateUniqueName() + ".config";

            FileUtils.CreateFile(content, filename);

            // Upload the file and assert it uploaded successfully
            msg = FileUtils.UploadFile(p, id, string.Empty, out fileid, filename);
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "File upload failed!");

            // Assert uploaded file has only 1 revision
            msg = p.At("pages", id, "files").Get();
            Assert.AreEqual(1, msg.ToDocument()["file/revisions/@count"].AsInt, "File revision count does not equal 1!");

            // Retrieve file, assert retrieval is successful, and assert retrieved content matches generated content
            msg = p.At("files", fileid).Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "File retrieval failed!");
            Assert.IsTrue(Utils.ByteArraysAreEqual(content, msg.AsBytes()), "Retrieved content does not match generated content!");

            // Delete the page
            PageUtils.DeletePageByID(p, id, true);
        }
Example #20
0
        public void Multiple_tags_on_single_page_point_to_their_respective_define_tags()
        {
            // Arrange
            Plug         p           = Utils.BuildPlugForAdmin();
            string       defineA     = null;
            string       defineAPath = null;
            DreamMessage msg         = PageUtils.CreateRandomPage(p, out defineA, out defineAPath);
            var          tagA        = "tagA-" + StringUtil.CreateAlphaNumericKey(8);

            msg = p.At("pages", defineA, "tags").Put(new XDoc("tags").Start("tag").Attr("value", "define:" + tagA).End());
            string defineB     = null;
            string defineBPath = null;

            msg = PageUtils.CreateRandomPage(p, out defineB, out defineBPath);
            var tagB = "tabB-" + StringUtil.CreateAlphaNumericKey(8);

            msg = p.At("pages", defineB, "tags").Put(new XDoc("tags").Start("tag").Attr("value", "define:" + tagB).End());
            string links = null;

            msg = PageUtils.CreateRandomPage(p, out links);
            msg = p.At("pages", links, "tags").Put(
                new XDoc("tags")
                .Start("tag").Attr("value", tagA).End()
                .Start("tag").Attr("value", tagB).End()
                );

            // Act
            msg = p.At("pages", links, "tags").Get();
            var tags = msg.ToDocument();

            // Assert
            Assert.AreEqual("/" + defineAPath, tags[string.Format("tag[@value='{0}']/uri", tagA)].AsUri.Path, "first define tab is pointing at wrong page");
            Assert.AreEqual("/" + defineBPath, tags[string.Format("tag[@value='{0}']/uri", tagB)].AsUri.Path, "second define tab is pointing at wrong page");
        }
Example #21
0
        public void UploadFileFromAnonymous()
        {
            // Acquire ADMIN permissions
            Plug p = Utils.BuildPlugForAdmin();

            // Create a random page
            string       id  = null;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out id);

            // Acquire Anonymous permissions
            p = Utils.BuildPlugForAnonymous();

            try
            {
                // Upload a random file to page
                string fileid   = null;
                string filename = null;
                msg = FileUtils.UploadRandomFile(p, id, out fileid, out filename);

                // Should not get here
                Assert.IsTrue(false, "File upload succeeded?!");
            }
            catch (DreamResponseException ex)
            {
                // Assert Unauthorized HTTP status returned
                Assert.AreEqual(DreamStatus.Unauthorized, ex.Response.Status, "Status other than \"Unauthroized\" returned");
            }

            // Acquire ADMIN permissions and delete page
            p = Utils.BuildPlugForAdmin();
            PageUtils.DeletePageByID(p, id, true);
        }
Example #22
0
        public void RestoreFileByID()
        {
            // POST:archive/files/restore/{fileid}
            // http://developer.mindtouch.com/Deki/API_Reference/POST%3aarchive%2f%2ffiles%2f%2frestore%2f%2f%7bfileid%7d

            Plug p = Utils.BuildPlugForAdmin();

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

            string fileid = null;

            msg = FileUtils.UploadRandomFile(p, id, out fileid);

            msg = FileUtils.DeleteFile(p, fileid);

            msg = p.At("archive", "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsFalse(msg.ToDocument()[string.Format("file.archive[@id=\"{0}\"]", fileid)].IsEmpty);

            msg = p.At("archive", "files", "restore", fileid).Post();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            msg = p.At("archive", "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.ToDocument()[string.Format("file.archive[@id=\"{0}\"]", fileid)].IsEmpty);

            msg = p.At("pages", id, "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsFalse(msg.ToDocument()[string.Format("file[@id=\"{0}\"]", fileid)].IsEmpty);
        }
Example #23
0
        public void GetPageContents()
        {
            // GET:archive/pages/{pageid}/contents
            // ...

            // 1. Create a page
            // 2. Set "This is content for page {id}" as page content
            // 3. Delete the page
            // (4) Assert page contents are consistent

            Plug p = Utils.BuildPlugForAdmin();

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

            string contents = "This is content for page " + id;

            PageUtils.SavePage(p, path, contents);

            PageUtils.DeletePageByID(p, id, false);

            msg = p.At("archive", "pages", id, "contents").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed");
            Assert.IsTrue((msg.ToDocument()["body"].AsText ?? String.Empty) == contents, "Page contents and archived page contents do not match!");
        }
Example #24
0
        public void GetComment()
        {
            // GET:pages/{pageid}/comments/{commentnumber}/content
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2fcomments%2f%2f%7bcommentnumber%7d%2f%2fcontent

            Plug p = Utils.BuildPlugForAdmin();

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

            string       content = Utils.GetSmallRandomText();
            DreamMessage postMsg = DreamMessage.Ok(MimeType.TEXT_UTF8, content);

            msg = p.At("pages", id, "comments").Post(postMsg);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            string commentId = msg.ToDocument()["@id"].AsText;

            Assert.IsFalse(string.IsNullOrEmpty(commentId));
            Assert.IsTrue(msg.ToDocument()["content"].AsText == content);

            msg = p.At("pages", id, "comments", "1", "content").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.AsText() == content);

            // GET:pages/{pageid}/comments/{commentnumber}
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2fcomments%2f%2f%7bcommentnumber%7d

            msg = p.At("pages", id, "comments", "1").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(msg.ToDocument()["@id"].AsText == commentId);
            Assert.IsTrue(msg.ToDocument()["content"].AsText == content);

            PageUtils.DeletePageByID(p, id, true);
        }
Example #25
0
        public void Bug0004185_InboundOutboundLinksAreReversed()
        {
            // Log in as ADMIN
            Plug p = Utils.BuildPlugForAdmin();

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

            // Create page2 with contents containg a link to page1
            string linkid   = null;
            string linkpath = null;
            string content  = string.Format(
                "<a href=\"mks://localhost/{0}\" class=\"internal\" title=\"{0}\">asdasdasdasda</a>", path);

            msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out linkid, out linkpath);

            // Retrieve outbound links of page2. Verify link points to page1.
            msg = p.At("pages", linkid, "links").With("dir", "from").Get();
            Assert.IsTrue(msg.ToDocument()["page/@id"].AsText == id, "Outbound link of page with link does not exist!");

            // Retrieve inbound links to page1. Verify link originates from page2.
            msg = p.At("pages", id, "links").With("dir", "to").Get();
            Assert.IsTrue(msg.ToDocument()["page/@id"].AsText == linkid, "Inbound link of page linked to is not present!");

            // Delete the pages
            PageUtils.DeletePageByID(p, id, true);
            PageUtils.DeletePageByID(p, linkid, true);
        }
Example #26
0
        public void GetRevisionSort()
        {
            Plug         p     = Utils.BuildPlugForAdmin();
            int          count = 5;
            string       id    = null;
            DreamMessage msg   = PageUtils.CreateRandomPage(p, out id);

            string fileid   = null;
            string filename = "aa.txt";
            string filepath = Path.Combine(Path.GetTempPath(), filename);

            try {
                FileUtils.CreateFile(null, filepath);
                for (int i = 0; i < count; i++)
                {
                    msg = FileUtils.UploadFile(p, id, "", out fileid, filepath);
                    msg = p.At("pages", id, "files", "=" + filename).Invoke("HEAD", DreamMessage.Ok());
                    Assert.AreEqual(DreamStatus.Ok, msg.Status);
                }
                msg = p.At("files", fileid, "revisions").Get();
                List <XDoc> files = msg.ToDocument()["file"].ToList();
                for (int i = 0; i < count; i++)
                {
                    Assert.AreEqual(i + 1, files[i]["@revision"].AsInt);
                }

                PageUtils.DeletePageByID(p, id, true);
            } finally {
                File.Delete(filepath);
            }
        }
Example #27
0
        public void GetFileFromAnonymous()
        {
            //Assumptions:
            //
            //Actions:
            // create page
            // upload file to page
            // try get file from anonymous account
            //Expected result:
            // ok

            Plug p = Utils.BuildPlugForAdmin();

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

            byte[] content  = FileUtils.GenerateRandomContent();
            string fileid   = null;
            string filename = null;

            msg = FileUtils.UploadRandomFile(p, id, content, string.Empty, out fileid, out filename);

            p = Utils.BuildPlugForAnonymous();

            msg = p.At("files", fileid).Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(Utils.ByteArraysAreEqual(content, msg.AsBytes()));

            p = Utils.BuildPlugForAdmin();
            PageUtils.DeletePageByID(p, id, true);
        }
Example #28
0
        public void UploadFileWithZeroSize()
        {
            // 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 with zero size and upload it to page
            byte[] content  = new byte[0];
            string fileid   = null;
            string filename = null;

            msg = FileUtils.UploadRandomFile(p, id, content, string.Empty, out fileid, out filename);

            // Retrieve file
            msg = p.At("files", fileid).Get();

            // Assert OK HTTP status returned
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            // Assert uploaded file content equals retrieved file content
            Assert.IsTrue(Utils.ByteArraysAreEqual(content, msg.AsBytes()));

            // Delete the page
            PageUtils.DeletePageByID(p, id, true);
        }
Example #29
0
        public void GetFileContent()
        {
            // GET:files/{fileid}
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3afiles%2f%2f%7bfileid%7d

            Plug p = Utils.BuildPlugForAdmin();

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

            byte[] content  = FileUtils.GenerateRandomContent();
            string fileid   = null;
            string filename = null;

            msg = FileUtils.UploadRandomFile(p, id, content, string.Empty, out fileid, out filename);

            msg = p.At("files", fileid).Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(Utils.ByteArraysAreEqual(content, msg.AsBytes()));

            // GET:files/{fileid}/{filename}
            // http://developer.mindtouch.com/Deki/API_Reference/GET%3afiles%2f%2f%7bfileid%7d%2f%2f%7bfilename%7d

            msg = p.At("files", fileid, "=" + filename).Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.IsTrue(Utils.ByteArraysAreEqual(content, msg.AsBytes()));

            PageUtils.DeletePageByID(p, id, true);
        }
Example #30
0
        public void TestRestoreTwoTimes()
        {
            //Assumptions:
            //
            //Actions:
            // create new page
            // delete page
            // restore page
            // restore page second time
            //Expected result:
            // not found

            Plug p = Utils.BuildPlugForAdmin();

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

            PageUtils.DeletePageByID(p, id, false);

            try
            {
                msg = p.At("archive", "pages", id, "restore").Post();
                Assert.AreEqual(DreamStatus.Ok, msg.Status);

                msg = p.At("archive", "pages", id, "restore").Post();
                Assert.IsTrue(false);
            }
            catch (DreamResponseException ex)
            {
                Assert.IsTrue(ex.Response.Status == DreamStatus.NotFound);
            }
        }