Beispiel #1
0
        public void TestDeleteWithNoCascadeHasChildren()
        {
            //Bug http://bugs.opengarden.org/view.php?id=1964

            // 1. Create page tree
            // (2) Assert all pages have been created
            // 3. Delete /A/B non recursive
            // (4) Assert A/B/C, A/B/D exists; A/B is reset; and _new_ A/B becomes parent of A/B/C, A/B/D

            Plug p = Utils.BuildPlugForAdmin();
            string baseTreePath = PageUtils.BuildPageTree(p);

            DreamMessage pageAresponse = PageUtils.GetPage(p, baseTreePath + "/A");
            DreamMessage pageABresponse = PageUtils.GetPage(p, baseTreePath + "/A/B");
            DreamMessage pageABCresponse = PageUtils.GetPage(p, baseTreePath + "/A/B/C");
            DreamMessage pageABDresponse = PageUtils.GetPage(p, baseTreePath + "/A/B/D");
            DreamMessage pageAEresponse = PageUtils.GetPage(p, baseTreePath + "/A/E");

            Assert.AreEqual("A", pageAresponse.ToDocument()["//title"].Contents);
            Assert.AreEqual("B", pageABresponse.ToDocument()["//title"].Contents);
            Assert.AreEqual("C", pageABCresponse.ToDocument()["//title"].Contents);
            Assert.AreEqual("D", pageABDresponse.ToDocument()["//title"].Contents);
            Assert.AreEqual("E", pageAEresponse.ToDocument()["//title"].Contents);

            int pageA = pageAresponse.ToDocument()["@id"].AsInt.Value;
            int pageAB = pageABresponse.ToDocument()["@id"].AsInt.Value;
            int pageABC = pageABCresponse.ToDocument()["@id"].AsInt.Value;
            int pageABD = pageABDresponse.ToDocument()["@id"].AsInt.Value;
            int pageAE = pageAEresponse.ToDocument()["@id"].AsInt.Value;

            DreamMessage deleteResponse = PageUtils.DeletePageByName(p, baseTreePath + "/A/B", false);
            Assert.IsTrue(deleteResponse.Status == DreamStatus.Ok);

            DreamMessage pageAresponse2 = PageUtils.GetPage(p, baseTreePath + "/A");
            DreamMessage pageABresponse2 = PageUtils.GetPage(p, baseTreePath + "/A/B");
            DreamMessage pageABCresponse2 = PageUtils.GetPage(p, baseTreePath + "/A/B/C");
            DreamMessage pageABDresponse2 = PageUtils.GetPage(p, baseTreePath + "/A/B/D");
            DreamMessage pageAEresponse2 = PageUtils.GetPage(p, baseTreePath + "/A/E");

            Assert.AreEqual(DreamStatus.Ok, pageAresponse2.Status);
            Assert.AreEqual(DreamStatus.Ok, pageABresponse2.Status);
            Assert.AreEqual(DreamStatus.Ok, pageABDresponse2.Status);
            Assert.AreEqual(DreamStatus.Ok, pageAEresponse2.Status);
            Assert.AreEqual(DreamStatus.Ok, pageABCresponse2.Status);

            int pageA2 = pageAresponse2.ToDocument()["@id"].AsInt.Value;
            int pageAB2 = pageABresponse2.ToDocument()["@id"].AsInt.Value;
            int pageABC2 = pageABCresponse2.ToDocument()["@id"].AsInt.Value;
            int pageABD2 = pageABDresponse2.ToDocument()["@id"].AsInt.Value;
            int pageAE2 = pageAEresponse2.ToDocument()["@id"].AsInt.Value;

            Assert.AreEqual(pageA, pageA2);
            Assert.AreNotEqual(pageAB, pageAB2);
            Assert.AreEqual(pageABC, pageABC2);
            Assert.AreEqual(pageABD, pageABD2);
            Assert.AreEqual(pageAE, pageAE2);

            Assert.AreEqual(pageAB2, pageABCresponse2.ToDocument()["page.parent/@id"].AsInt.Value);
            Assert.AreEqual(pageAB2, pageABDresponse2.ToDocument()["page.parent/@id"].AsInt.Value);
        }
Beispiel #2
0
        public void TestDeleteWithCascadeNoReset()
        {
            // 1. Build page tree
            // (2) Assert all pages in tree were created
            // 3. Delete A recursively
            // (4) Assert all pages in tree are no longer alive

            Plug p = Utils.BuildPlugForAdmin();

            string baseTreePath = PageUtils.BuildPageTree(p);

            Assert.AreEqual("A", PageUtils.GetPage(p, baseTreePath + "/A").ToDocument()["//title"].Contents);
            Assert.AreEqual("B", PageUtils.GetPage(p, baseTreePath + "/A/B").ToDocument()["//title"].Contents);
            Assert.AreEqual("C", PageUtils.GetPage(p, baseTreePath + "/A/B/C").ToDocument()["//title"].Contents);
            Assert.AreEqual("D", PageUtils.GetPage(p, baseTreePath + "/A/B/D").ToDocument()["//title"].Contents);
            Assert.AreEqual("E", PageUtils.GetPage(p, baseTreePath + "/A/E").ToDocument()["//title"].Contents);

            Assert.AreEqual(DreamStatus.Ok, PageUtils.DeletePageByName(p, baseTreePath + "/A", true).Status);

            Assert.AreEqual(DreamStatus.NotFound, PageUtils.GetPage(p, baseTreePath + "/A").Status);
            Assert.AreEqual(DreamStatus.NotFound, PageUtils.GetPage(p, baseTreePath + "/A/B").Status);
            Assert.AreEqual(DreamStatus.NotFound, PageUtils.GetPage(p, baseTreePath + "/A/B/C").Status);
            Assert.AreEqual(DreamStatus.NotFound, PageUtils.GetPage(p, baseTreePath + "/A/B/D").Status);
            Assert.AreEqual(DreamStatus.NotFound, PageUtils.GetPage(p, baseTreePath + "/A/E").Status);
        }
Beispiel #3
0
        public void DeleteUserPage_UserPageRecreated()
        {
            // Log in as ADMIN
            Plug p = Utils.BuildPlugForAdmin();

            // Create a user
            string userid;
            string username;

            UserUtils.CreateRandomContributor(p, out userid, out username);

            // Retrieve user page
            DreamMessage msg = PageUtils.GetPage(p, "User:"******"Could not retrieve user page.");
            uint pageid = msg.ToDocument()["@id"].AsUInt ?? 0;

            // Delete user page
            PageUtils.DeletePageByName(p, "User:"******"User:"******"Could not retrieve user page.");
            Assert.AreEqual(pageid + 1, msg.ToDocument()["@id"].AsUInt ?? 0, "Unexpected page ID.");
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        public void TestDeleteWithCascadeSkipResetNode()
        {
            // 1. Create page tree
            // 2. Create user with Contributor role
            // (3) Assert all pages have been created
            // 4. Restrict A/B as private (user has no delete/update access)
            // 5. Delete /A* as user
            // (6) Assert A is reset; A/B is untouched; and the rest of the pages are deleted

            Plug p = Utils.BuildPlugForAdmin();
            string baseTreePath = PageUtils.BuildPageTree(p);
            string contrUserId = null;
            string contrUserName = null;
            UserUtils.CreateRandomContributor(p, out contrUserId, out contrUserName);

            DreamMessage pageAresponse = PageUtils.GetPage(p, baseTreePath + "/A");
            DreamMessage pageABresponse = PageUtils.GetPage(p, baseTreePath + "/A/B");
            DreamMessage pageABCresponse = PageUtils.GetPage(p, baseTreePath + "/A/B/C");
            DreamMessage pageABDresponse = PageUtils.GetPage(p, baseTreePath + "/A/B/D");
            DreamMessage pageAEresponse = PageUtils.GetPage(p, baseTreePath + "/A/E");

            Assert.AreEqual("A", pageAresponse.ToDocument()["//title"].Contents);
            Assert.AreEqual("B", pageABresponse.ToDocument()["//title"].Contents);
            Assert.AreEqual("C", pageABCresponse.ToDocument()["//title"].Contents);
            Assert.AreEqual("D", pageABDresponse.ToDocument()["//title"].Contents);
            Assert.AreEqual("E", pageAEresponse.ToDocument()["//title"].Contents);

            int pageA = pageAresponse.ToDocument()["@id"].AsInt.Value;
            int pageAB = pageABresponse.ToDocument()["@id"].AsInt.Value;
            int pageABC = pageABCresponse.ToDocument()["@id"].AsInt.Value;
            int pageABD = pageABDresponse.ToDocument()["@id"].AsInt.Value;
            int pageAE = pageAEresponse.ToDocument()["@id"].AsInt.Value;

            PageUtils.RestrictPage(p, baseTreePath + "/A/B", "none", "Private");
            
            p = Utils.BuildPlugForUser(contrUserName);
            Assert.AreEqual(DreamStatus.Ok, PageUtils.DeletePageByName(p, baseTreePath + "/A", true).Status);

            p = Utils.BuildPlugForAdmin();
            DreamMessage pageAresponse2 = PageUtils.GetPage(p, baseTreePath + "/A");
            DreamMessage pageABresponse2 = PageUtils.GetPage(p, baseTreePath + "/A/B");
            DreamMessage pageABCresponse2 = PageUtils.GetPage(p, baseTreePath + "/A/B/C");
            DreamMessage pageABDresponse2 = PageUtils.GetPage(p, baseTreePath + "/A/B/D");
            DreamMessage pageAEresponse2 = PageUtils.GetPage(p, baseTreePath + "/A/E");

            Assert.AreEqual(DreamStatus.Ok, pageAresponse2.Status);
            Assert.AreEqual(DreamStatus.Ok, pageABresponse2.Status);
            Assert.AreEqual(DreamStatus.NotFound, pageABDresponse2.Status);
            Assert.AreEqual(DreamStatus.NotFound, pageAEresponse2.Status);
            Assert.AreEqual(DreamStatus.NotFound, pageABCresponse2.Status);

            int pageA2 = pageAresponse2.ToDocument()["@id"].AsInt.Value;
            int pageAB2 = pageABresponse2.ToDocument()["@id"].AsInt.Value;

            Assert.AreNotEqual(pageA, pageA2);
            Assert.AreEqual(pageAB, pageAB2);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        public void TestDeleteOfLeafNode()
        {
            // 1. Build a page tree
            // (2) Assert page A/B/C was created
            // 3. Delete page A/B/C
            // (4) Assert page A/B/C is no longer alive

            Plug p = Utils.BuildPlugForAdmin();

            string baseTreePath = PageUtils.BuildPageTree(p);

            DreamMessage msg = PageUtils.GetPage(p, baseTreePath + "/A/B/C");
            Assert.AreEqual("C", msg.ToDocument()["//title"].Contents);
            msg = PageUtils.DeletePageByName(p, baseTreePath + "/A/B/C", false);
            msg = PageUtils.GetPage(p, baseTreePath + "/A/B/C");
            Assert.AreEqual(DreamStatus.NotFound, msg.Status);
        }
Beispiel #8
0
        public void Title_Case02_WithNamespacePrefix_CorrectPathTitle()
        {
            // Case 02
            // Old path:  Namespace:aaa
            // Old title: Namespace:aaa
            //            move?title=bbb
            // New path:  Namespace:bbb
            // New title: bbb

            // Log in as ADMIN
            Plug p = Utils.BuildPlugForAdmin();

            // Run this test for each namespace
            for (int i = 0; i < name_space.Length; i++)
            {
                string path = name_space[i] + Utils.GenerateUniqueName();
                PageUtils.SavePage(p, path, name_space[i] + "test");

                // Rename page from Namespace:aaa -> bbb using "title"
                string       title    = Utils.GenerateUniqueName();
                string       newtitle = title;
                string       newpath  = name_space[i] + title;
                DreamMessage msg      = PageUtils.MovePage(Utils.BuildPlugForAdmin().At("pages", "=" + XUri.DoubleEncode(path), "move").With("title", newtitle));
                Assert.IsTrue(msg.IsSuccessful, "move page failed");
                Assert.AreEqual(1, msg.ToDocument()["@count"].AsInt, "unexpected number of pages moved");
                if (msg.ToDocument()["page/path/@type"].AsText == "fixed")
                {
                    // fixed path page are not moved, just the title is changed
                    newpath = msg.ToDocument()["page/path"].AsText;
                }

                // Retrieve the page and verify correct path/title
                msg = PageUtils.GetPage(p, newpath);
                string metapath  = msg.ToDocument()["path"].AsText ?? String.Empty;
                string metatitle = msg.ToDocument()["title"].AsText ?? String.Empty;

                // path should be Namespace:bbb, title should be bbb, page should be linked
                Assert.AreEqual(newpath, metapath, "Unexpected path");
                Assert.AreEqual(newtitle, metatitle, "Unexpected title");
                PageUtils.IsLinked(msg);

                // Delete page as to not contaminate the namespace
                PageUtils.DeletePageByName(p, newpath, true);
            }
        }
Beispiel #9
0
        public void DeletePageByName()
        {
            // 1. Create a page
            // 2. Delete the page by name
            // (3) Assert page is no longer aliveas
            // (4) Assert page is present in archives

            Plug p = Utils.BuildPlugForAdmin();

            string id = null;
            string path = null;
            DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path);
            
            msg = PageUtils.DeletePageByName(p, path, true);
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page delete failed");

            msg = p.At("pages", "=" + XUri.DoubleEncode(path)).GetAsync().Wait();
            Assert.AreEqual(DreamStatus.NotFound, msg.Status, "Page retrieval succeeded?!");

            msg = p.At("archive", "pages", id).Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page archive retrieval failed");
            Assert.AreEqual(path, msg.ToDocument()["path"].AsText, "Page is not in archive?!");
        }
Beispiel #10
0
        public void Title_Case04_WithNamespacePrefix_CorrectPathTitle()
        {
            // Case 04
            // Old path:  Namespace:aaa/bbb
            // Old title: Namespace:aaa/bbb
            //            move?title=ccc
            // New path:  Namespace:aaa/ccc
            // New title: Namespace:aaa/ccc

            // Log in as ADMIN
            Plug p = Utils.BuildPlugForAdmin();

            // Run this test for each namespace
            for (int i = 0; i < name_space.Length; i++)
            {
                string presegment = name_space[i] + Utils.GenerateUniqueName() + "/";
                string path       = presegment + Utils.GenerateUniqueName();
                PageUtils.SavePage(p, path, name_space + "test");

                // Rename page from Namespace:aaa/bbb -> ccc using "title"
                string title   = Utils.GenerateUniqueName();
                string newpath = presegment + title;
                PageUtils.MovePage(Utils.BuildPlugForAdmin().At("pages", "=" + XUri.DoubleEncode(path), "move").With("title", title));

                // Retrieve the page and verify correct path/title
                DreamMessage msg       = PageUtils.GetPage(p, newpath);
                string       metapath  = msg.ToDocument()["path"].AsText ?? String.Empty;
                string       metatitle = msg.ToDocument()["title"].AsText ?? String.Empty;

                // path shouldbe Namespace:aaa/Namespace:ccc title should be Namespace:ccc
                Assert.AreEqual(newpath, metapath, "Unexpected path");
                Assert.AreEqual(title, metatitle, "Unexpected title");

                // Delete page as to not contaminate the namespace
                PageUtils.DeletePageByName(p, newpath, true);
            }
        }