Beispiel #1
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 #2
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);
        }
        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);
        }
Beispiel #4
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);
        }
        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);
            }
        }
Beispiel #6
0
        public void UploadRename()
        {
            // 1. Build a page tree
            // 2. Upload a file to the root of page tree (A)
            // 3. Replace file and rename it
            // (4) Assert replacement succeeded
            // (5) Assert the file revisions accurately reflect changes
            // (6) Assert new file name is consistent
            // 7. Upload a file to page with same name
            // (8) Assert Conflict response is returned
            // 9. Delete the page (recursive)

            Plug p = Utils.BuildPlugForAdmin();

            string baseTreePath = PageUtils.BuildPageTree(p);

            string pageid = PageUtils.GetPage(p, baseTreePath + "/A").ToDocument()["@id"].AsText;

            string       fileid      = null;
            string       filename    = null;
            string       newfilename = "newfilename";
            DreamMessage msg         = FileUtils.UploadRandomFile(p, pageid, out fileid, out filename);

            //Upload a new rev with rename
            msg = p.At("files", fileid, "=" + newfilename).Put(DreamMessage.Ok(MimeType.BINARY, FileUtils.GenerateRandomContent()));
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "upload with rename failed");

            //validate revisions
            msg = p.At("files", fileid, "revisions").With("changefilter", "all").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "get revisions failed");
            string actions = null;

            actions = msg.ToDocument()["file[@revision = '1']/user-action/@type"].AsText ?? string.Empty;
            Assert.IsTrue(actions.Contains("content"), "expected user action missing");
            Assert.IsTrue(actions.Contains("parent"), "expected user action missing");
            Assert.IsTrue(actions.Contains("name"), "expected user action missing");
            actions = msg.ToDocument()["file[@revision = '2']/user-action/@type"].AsText ?? string.Empty;
            Assert.IsTrue(actions.Contains("content"), "expected user action missing");
            Assert.IsTrue(actions.Contains("name"), "expected user action missing");

            //Confirm new filename
            Assert.AreEqual(newfilename, msg.ToDocument()["file[@revision = '2']/filename"].AsText, "Filenames do not match!");

            string file3name;
            string file3id;

            msg = FileUtils.UploadRandomFile(p, pageid, out file3id, out file3name);

            //Upload new rev of file with rename that conflits with previous rename
            msg = p.At("files", file3id, "=" + newfilename).PutAsync(DreamMessage.Ok(MimeType.BINARY, FileUtils.GenerateRandomContent())).Wait();
            Assert.AreEqual(DreamStatus.Conflict, msg.Status, "upload with conflicting rename check failed");

            PageUtils.DeletePageByID(p, pageid, 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 MoveFileToChildPage()
        {
            //Assumptions:
            //
            //Actions:
            // 1. Create A
            // 2. Create B as child of page A
            // 3. Upload file to A
            // (4) Assert file exists on page A
            // 5. Try to move file to page B
            // (6) Assert file does not exist on page A
            // (7) Assert file exists on page B
            // 8. Delete page A recursively
            //Expected result:
            // file is moved

            Plug p = Utils.BuildPlugForAdmin();

            string baseTreePath = PageUtils.BuildPageTree(p);

            string id   = PageUtils.GetPage(p, baseTreePath + "/A").ToDocument()["@id"].AsText;
            string toid = PageUtils.GetPage(p, baseTreePath + "/A/B").ToDocument()["@id"].AsText;

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

            msg = p.At("pages", id, "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "GET pages/{id}/files request failed. BEFORE move");
            Assert.IsFalse(msg.ToDocument()[string.Format("file[@id=\"{0}\"]", fileid)].IsEmpty, "Page does not contain generated file! BEFORE move");

            msg = p.At("files", fileid, "move").With("to", toid).Post();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "Move request failed");

            msg = p.At("pages", id, "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "GET pages/{id}/files request failed. AFTER move");
            Assert.IsTrue(msg.ToDocument()[string.Format("file[@id=\"{0}\"]", fileid)].IsEmpty, "Generated file still attached to page! AFTER move");

            msg = p.At("pages", toid, "files").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "GET pages/{toid}/files request failed. AFTER move");
            Assert.IsFalse(msg.ToDocument()[string.Format("file[@id=\"{0}\"]", fileid)].IsEmpty, "Subpage does not contain generated file! AFTER move");

            PageUtils.DeletePageByID(p, id, true);
        }
Beispiel #9
0
        public void TestDeleteWithCascadeOnNoAccessNode()
        {
            // 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  4. Restrict A/B as private (user has no delete/update access)
            // 5. Delete /A/B* as user
            // (6) Assert "Forbidden" response returned
            // (7) Assert no changes made

            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);
            string path = "=" + XUri.DoubleEncode(baseTreePath + "/A/B");
            DreamMessage deleteResponse = p.At("pages", path).WithQuery("recursive=" + "true").DeleteAsync().Wait();
            Assert.AreEqual(DreamStatus.Forbidden, deleteResponse.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.Ok, pageABDresponse2.Status);
            Assert.AreEqual(DreamStatus.Ok, pageAEresponse2.Status);
            Assert.AreEqual(DreamStatus.Ok, pageABCresponse2.Status);

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

            Assert.AreEqual(pageA, pageA2);
            Assert.AreEqual(pageAB, pageAB2);
            Assert.AreEqual(pageABC, pageABC2);
            Assert.AreEqual(pageABD, pageABD2);
            Assert.AreEqual(pageAE, pageAE2);
        }
        public void TestCascadingWithSkipIfUnableToSet()
        {
            //Assumptions:
            //Actions:
            //  Create user with "Contributor" role
            //  Admin sets restriction:private on A/B
            //  User adds grant for self viewer on A/*
            //  User sets grant for self viewer on A/*
            //Expected result:
            //  User is viewer on A, A/B/C, A/B/D, A/E but no change on A/B

            Plug p = Utils.BuildPlugForAdmin();

            string baseTreePath = PageUtils.BuildPageTree(p);

            string       userid   = null;
            string       username = null;
            DreamMessage msg      = UserUtils.CreateRandomContributor(p, out userid, out username);

            XDoc securityDoc = new XDoc("security")
                               .Start("permissions.page")
                               .Elem("restriction", "Private")
                               .End();

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B"), "security").
                  WithQuery("cascade=none").Put(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "restrict /A/B to private");

            p = Utils.BuildPlugForUser(username, "password");

            securityDoc = new XDoc("security")
                          .Start("grants.added")
                          .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=delta").Post(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "grant viewer on /A/*");

            p = Utils.BuildPlugForAdmin(); // relogin as admin

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "security").Get();
            Assert.AreEqual(msg.ToDocument()[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid)].Contents, "Viewer", "confirm viewer grant on /A");

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B"), "security").Get();
            Assert.AreEqual(msg.ToDocument()["permissions.page/restriction"].Contents, "Private", "confirm private restriction on /A/B");
            Assert.AreEqual(msg.ToDocument()["grants/grant[2]"].IsEmpty, true, "confirm single grant on /A/B");

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B/C"), "security").Get();
            var doc = msg.ToDocument();

            Assert.AreEqual(doc[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid)].Contents, "Viewer", "confirm viewer grant on /A/B/C");
            Assert.AreEqual(string.IsNullOrEmpty(doc["permissions.page/operations"].AsText), true, "confirm no available operations on /A/B/C");

            p = Utils.BuildPlugForUser(username, "password"); // relogin as user

            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();

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "security").
                  WithQuery("cascade=absolute").Put(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "grant contributor on /A/*");

            p = Utils.BuildPlugForAdmin(); // relogin as admin

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "security").Get();
            Assert.AreEqual(msg.ToDocument()[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid)].Contents, "Contributor", "confirm contributor grant on /A");

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B"), "security").Get();
            Assert.AreEqual(msg.ToDocument()["permissions.page/restriction"].Contents, "Private", "reconfirm private restriction on /A/B");
            Assert.AreEqual(msg.ToDocument()["grants/grant[2]"].IsEmpty, true, "reconfirm single grant on /A/B");

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B/C"), "security").Get();
            Assert.AreEqual(msg.ToDocument()[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid)].Contents, "Contributor", "confirm contributor grant on /A/B/C");
            Assert.AreEqual(msg.ToDocument()["permissions.page/restriction"].Contents, "Private", "confirm private restriction on /A/B/C");
        }
        public void TestPostDeltas()
        {
            //Assumptions:
            // Role 'Contributor' exists
            // Role 'Viewer' exists
            //Actions:
            // Create User1, User2 and User3
            // User1 is contributor, User2 is contributor on /A/B*
            // User3 is a viewer on A* (grant added)
            //Expected result:
            // User3 is viewer on /A*
            // User1 and user2 are contributors on /A/B*

            Plug p = Utils.BuildPlugForAdmin();

            string baseTreePath = PageUtils.BuildPageTree(p);

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

            string userid2 = null;

            msg = UserUtils.CreateRandomContributor(p, out userid2);

            string userid3 = null;

            msg = UserUtils.CreateRandomContributor(p, out userid3);

            XDoc 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", userid1).End()
                               .End()
                               .Start("grant")
                               .Start("permissions")
                               .Elem("role", "Contributor")
                               .End()
                               .Start("user").Attr("id", userid2).End()
                               .End()
                               .End();

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B"), "security").
                  WithQuery("cascade=absolute").Put(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            securityDoc = new XDoc("security")
                          .Start("permissions.page")
                          .Elem("restriction", "Private")
                          .End()
                          .Start("grants.added")
                          .Start("grant")
                          .Start("permissions")
                          .Elem("role", "Viewer")
                          .End()
                          .Start("user").Attr("id", userid3).End()
                          .End()
                          .End();

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "security").
                  WithQuery("cascade=delta").Post(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "security").Get();
            Assert.AreEqual(msg.ToDocument()[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid3)].Contents, "Viewer");

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B/C"), "security").Get();
            Assert.AreEqual(msg.ToDocument()["permissions.page/restriction"].Contents, "Private");
            Assert.AreEqual(msg.ToDocument()[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid1)].Contents, "Contributor");
            Assert.AreEqual(msg.ToDocument()[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid2)].Contents, "Contributor");
            Assert.AreEqual(msg.ToDocument()[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid3)].Contents, "Viewer");
        }
        public void TestEmptyDeltaCascadesNothing()
        {
            //Assumptions:
            // Role 'Contributor' exists
            // Role 'Viewer' exists
            //Actions:
            // Create User1
            // User1 is contributor /A/B and Viewer on /A
            //Expected result:
            // nothing changed

            Plug p = Utils.BuildPlugForAdmin();

            string baseTreePath = PageUtils.BuildPageTree(p);

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

            XDoc 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", userid1).End()
                               .End()
                               .End();

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B"), "security").
                  WithQuery("cascade=absolute").Put(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            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", userid1).End()
                          .End()
                          .End();

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "security").
                  WithQuery("cascade=none").Put(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B"), "security").Get();
            Assert.AreEqual("Contributor", msg.ToDocument()[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid1)].Contents);

            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", userid1).End()
                          .End()
                          .End();

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "security").
                  WithQuery("cascade=delta").Put(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "security").Get();
            Assert.AreEqual("Viewer", msg.ToDocument()[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid1)].Contents);

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B"), "security").Get();
            Assert.AreEqual("Contributor", msg.ToDocument()[string.Format("grants/grant[user/@id=\"{0}\"]/permissions/role", userid1)].Contents);
        }
        public void TestAbsoluteCascading()
        {
            //Assumptions:
            //role 'contributor' exists
            //Actions:
            // Create User1 and User2
            //User1 is contributor on /A/B/* with absolute cascading
            //User2 is contributor on /A* with absolute cascading
            //Expected result:
            // A/* including A/B does not have user1 as contributor

            Plug p = Utils.BuildPlugForAdmin();

            string baseTreePath = PageUtils.BuildPageTree(p);

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

            string userid2 = null;

            msg = UserUtils.CreateRandomContributor(p, out userid2);

            XDoc 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", userid1).End()
                               .End()
                               .End();

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B"), "security").
                  WithQuery("cascade=absolute").Put(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            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", userid2).End()
                          .End()
                          .End();

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A"), "security").
                  WithQuery("cascade=absolute").Put(securityDoc);
            Assert.AreEqual(DreamStatus.Ok, msg.Status);

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/B"), "security").Get();
            Assert.AreEqual(msg.ToDocument()["permissions.page/restriction"].Contents, "Private");
            Assert.AreEqual(msg.ToDocument()["grants/grant[1]/user/@id"].Contents, userid2);
            Assert.IsTrue(msg.ToDocument()["grants/grant[2]"].IsEmpty);
        }
Beispiel #14
0
        public void RenameFile()
        {
            // 1. Create a source page
            // 2. Create a destination page (child of source page)
            // 3. Upload a file to source page
            // (4) Assert move request without parameters fails
            // (5) Assert move request without renaming the file and without specifying destination fails
            // (6) Assert move request to same path fails
            // (7) Assert move request to exact same path and filename fails
            // (8) Assert move request to different location and name succeeds
            // (9) Assert a rename to a new name succeeds
            // (10) Assert move request to a different location works
            // (11) Assert the file revisions accurately reflect changes
            // 12. Delete the page

            Plug p = Utils.BuildPlugForAdmin();

            string baseTreePath = PageUtils.BuildPageTree(p);

            string id   = PageUtils.GetPage(p, baseTreePath + "/A").ToDocument()["@id"].AsText;
            string toid = PageUtils.GetPage(p, baseTreePath + "/A/B").ToDocument()["@id"].AsText;

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

            //Test no parametrs
            msg = p.At("files", fileid, "move").PostAsync().Wait();
            Assert.AreEqual(DreamStatus.BadRequest, msg.Status, "No parameter test failed");

            //Test no change
            msg = p.At("files", fileid, "move").With("name", filename).PostAsync().Wait();
            Assert.AreEqual(DreamStatus.BadRequest, msg.Status, "No change test failed");

            msg = p.At("files", fileid, "move").With("to", id).PostAsync().Wait();
            Assert.AreEqual(DreamStatus.BadRequest, msg.Status, "No change test failed");

            msg = p.At("files", fileid, "move").With("to", id).With("name", filename).PostAsync().Wait();
            Assert.AreEqual(DreamStatus.BadRequest, msg.Status, "No change test failed");

            string newFileName = "newname.txt";

            //Move and rename
            msg = p.At("files", fileid, "move").With("to", toid).With("name", newFileName).Post();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "move+rename failed");
            Assert.AreEqual(toid, msg.ToDocument()["page.parent/@id"].AsText, "New page id is incorrect");
            Assert.AreEqual(newFileName, msg.ToDocument()["filename"].AsText, "New filename is incorrect");

            //rename
            msg = p.At("files", fileid, "move").With("name", filename).Post();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "rename failed");
            Assert.AreEqual(filename, msg.ToDocument()["filename"].AsText, "New filename is incorrect");

            //move
            msg = p.At("files", fileid, "move").With("to", id).Post();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "move failed");
            Assert.AreEqual(id, msg.ToDocument()["page.parent/@id"].AsText, "New page id is incorrect");

            //verify all revisions
            msg = p.At("files", fileid, "revisions").With("changefilter", "all").Get();
            Assert.AreEqual(DreamStatus.Ok, msg.Status, "get revisions failed");
            string actions = null;

            actions = msg.ToDocument()["file[@revision = '1']/user-action/@type"].AsText ?? string.Empty;
            Assert.IsTrue(actions.Contains("content"), "expected user action missing");
            Assert.IsTrue(actions.Contains("parent"), "expected user action missing");
            Assert.IsTrue(actions.Contains("name"), "expected user action missing");
            actions = msg.ToDocument()["file[@revision = '2']/user-action/@type"].AsText ?? string.Empty;
            Assert.IsTrue(actions.Contains("parent"), "expected user action missing");
            Assert.IsTrue(actions.Contains("name"), "expected user action missing");
            actions = msg.ToDocument()["file[@revision = '3']/user-action/@type"].AsText ?? string.Empty;
            Assert.IsTrue(actions.Contains("name"), "expected user action missing");
            actions = msg.ToDocument()["file[@revision = '4']/user-action/@type"].AsText ?? string.Empty;
            Assert.IsTrue(actions.Contains("parent"), "expected user action missing");
            Assert.IsTrue(msg.ToDocument()["file[@revision = '5']"].IsEmpty, "5th rev exists!");

            PageUtils.DeletePageByID(p, id, true);
        }
Beispiel #15
0
        public void CommentsForTreeOfPagesWithSecurity()
        {
            //Assumptions:
            //Actions:
            //  Create tree of pages
            //  Add comment to every page
            //  Set private restrictions for E page
            //  Try to get comments from user which doesn't have rights for E page
            //Expected result:
            //  All comments received except comments for E

            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;

            XDoc securityDoc = new XDoc("security")
                               .Start("permissions.page")
                               .Elem("restriction", "Private")
                               .End();

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath + "/A/E"), "security").
                  WithQuery("cascade=none").Put(securityDoc);

            string userid   = null;
            string username = null;

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

            p = Utils.BuildPlugForUser(username);

            msg = p.At("pages", "=" + XUri.DoubleEncode(baseTreePath), "comments").With("depth", "infinity").Get();
            Assert.IsTrue(msg.ToDocument()["@count"].AsInt == 4);
            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.IsTrue(msg.ToDocument()[string.Format("comment[@id='{0}']", commentForE1Id)].IsEmpty);
            Assert.IsTrue(msg.ToDocument()[string.Format("comment[@id='{0}']", commentForE2Id)].IsEmpty);
        }