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); }
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); }
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); }
public void ContentNewUser_PointsToInvalidPage_DefaultUserPageContents() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Add content/new-user key to point to some bogus page SiteUtils.AddConfigKey(p, "content/new-user", Utils.GenerateUniqueName()); // Create a user string userid; string username; UserUtils.CreateRandomContributor(p, out userid, out username); // Retrieve user page contents DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode("User:"******"contents").Get(new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve user page contents"); string content = msg.ToDocument()["body"].AsText ?? String.Empty; // Retrieve default new user page content from resources string resource = "MindTouch.Templates.userwelcome.visitor"; msg = p.At("site", "localization").With("resource", resource).Get(new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Unable to retrieve resource for string: " + resource); string expectedContent = "<p>" + msg.AsText() + "</p>" ?? String.Empty; Assert.AreEqual(expectedContent, content, "Unexpected contents"); }
public void 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); }
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"); }
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); }
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); } }
public void PageCreate_NameDoesNotEqualTitle_Unlinked() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create a page where name != title string path = PageUtils.GenerateUniquePageName(); DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents") .With("title", "unique title") .PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, "Linked test")).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page creation failed!"); // Retrieve the page msg = p.At("pages", "=" + XUri.DoubleEncode(path)).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed!"); // Check that the page is unlinked (i.e. path/@type attribute == custom) string type = msg.ToDocument()["path/@type"].AsText; Assert.AreEqual("custom", type, "Page is unlinked!"); // Delete the page PageUtils.DeletePageByName(p, path, true); }
public void PutFileProperties() { Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); string propertyContent = Utils.GetSmallRandomText(); string propertyName = Utils.GenerateUniqueName(); string fileid = null; msg = FileUtils.UploadRandomFile(p, id, out fileid); msg = p.At("files", fileid, "properties").WithHeader("Slug", XUri.Encode(propertyName)).PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, propertyContent)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.AreEqual(msg.ToDocument()["/property/contents"].AsText, propertyContent, "Contents don't match!"); msg = p.At("files", fileid, "properties", propertyName).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Non 200 status on get:property content: " + msg.ToString()); Assert.AreEqual(propertyContent, msg.AsText(), "Contents don't match!"); PageUtils.DeletePageByID(p, id, true); }
public void TestRestoreWithFile() { //Assumptions: // //Actions: // create new page // upload random file to the page // delete page // restore page //Expected result: // page has file Plug p = Utils.BuildPlugForAdmin(); string id = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id); string fileid = null; msg = FileUtils.UploadRandomFile(p, id, out fileid); PageUtils.DeletePageByID(p, id, false); msg = p.At("archive", "pages", id, "restore").Post(); Assert.AreEqual(DreamStatus.Ok, msg.Status); msg = p.At("pages", id).Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsTrue(msg.ToDocument()["files/file/@id"].AsText == fileid); }
public void PutPagePropertiesXml() { Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); var propertyContent = new XDoc("foo").Start("someelement").Attr("justanattribute", true).End(); var propXml = new XDoc("properties") .Start("property").Attr("name", "foo") .Start("contents").Attr("type", MimeType.XML.ToString()) .Value(propertyContent) // the xml content is not escaped! .End() .Elem("description", "whattup") .End(); msg = p.At("pages", id, "properties").PutAsync(DreamMessage.Ok(propXml)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status); msg = p.At("pages", id, "properties", "foo").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.AreEqual(propertyContent.ToPrettyString(), msg.ToDocument().ToPrettyString(), "Contents don't match!"); PageUtils.DeletePageByID(p, id, true); }
public void PropGetContentPreviewsPositive() { Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); int NUMPROPS = 5; XDoc doc = new XDoc("properties"); string contentLong = Utils.GetRandomTextByAlphabet(5000); string contentShort = "Some content"; string descTemplate = "Soem description {0}"; //Short content doc.Start("property").Attr("name", "prop_short") .Start("contents").Attr("type", MimeType.TEXT.ToString()) .Value(contentShort) .End() .End(); //Long content doc.Start("property").Attr("name", "prop_long") .Start("contents").Attr("type", MimeType.TEXT.ToString()) .Value(contentLong) .End() .End(); msg = p.At("pages", id, "properties").PutAsync(DreamMessage.Ok(doc)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "put batch property returned non 200 status: " + msg.ToString()); msg = p.At("pages", id, "properties").GetAsync(DreamMessage.Ok()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "get properties returned non 200 status: " + msg.ToString()); }
public void SaveGetPageProperty() { Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); string content = Utils.GetSmallRandomText(); //NOTE: PUT: resource/{properties}/{key} is allowing property creation. Creating properties this way is undocumented and not recommended but was added for import/export //Test property creation via PUT //msg = p.At("pages", id, "properties", "foo").PutAsync(DreamMessage.Ok(MimeType.TEXT, content)).Wait(); //Assert.AreEqual(DreamStatus.Conflict, msg.Status); msg = p.At("pages", id, "properties").WithHeader("Slug", XUri.Encode("foo")).PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, content)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "post properties returned non 200 status: " + msg.ToString()); //TODO: validate response XML for 200's msg = p.At("pages", id, "properties", "foo", "info").GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "get property returned non 200 status: " + msg.ToString()); Assert.AreEqual(content, msg.ToDocument()["/property[@name= 'foo']/contents"].AsText, "Contents don't match!"); XUri contentsUri = msg.ToDocument()["/property[@name = 'foo']/contents/@href"].AsUri; Assert.IsTrue(contentsUri != null, "Couldn't find content href"); Plug p2 = Plug.New(contentsUri).WithTimeout(p.Timeout).WithHeaders(p.Headers).WithCredentials(p.Credentials); msg = p2.GetAsync().Wait(); Assert.IsTrue(msg.Status == DreamStatus.Ok, "get property contents by uri didnt return status 200: " + msg.ToString()); Assert.IsTrue(msg.ContentType.Match(MimeType.TEXT), "get property content type didnt match: " + msg.ToString()); Assert.IsTrue(msg.AsText() == content, "get property content didnt match: " + msg.ToString()); }
public void GetSubpages() { // GET:pages/{pageid}/subpages // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2fsubpages Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); msg = p.At("pages", id, "subpages").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsTrue(msg.ToDocument()["page.subpage"].IsEmpty); msg = PageUtils.CreateRandomPage(p, path + "/" + Utils.GenerateUniqueName()); Assert.AreEqual(DreamStatus.Ok, msg.Status); string subid = msg.ToDocument()["page/@id"].AsText; Assert.IsTrue(!string.IsNullOrEmpty(subid)); msg = p.At("pages", "=" + XUri.DoubleEncode(path), "subpages").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsFalse(msg.ToDocument()[string.Format("page.subpage[@id=\"{0}\"]", subid)].IsEmpty); PageUtils.DeletePageByID(p, id, true); }
public Yield SubscribeToChange(DreamContext context, DreamMessage request, Result <DreamMessage> response) { var wikiId = GetWikiIdFromRequest(request); var pageId = context.GetParam <uint>("pageid"); var depth = context.GetParam("depth", "0") == "0" ? false : true; Result <PageSubscriptionUser> userResult; yield return(userResult = Coroutine.Invoke(GetRequestUser, request, new Result <PageSubscriptionUser>()).Catch()); if (userResult.HasException) { ReturnUserError(userResult.Exception, response); yield break; } var userInfo = userResult.Value; DreamMessage pageAuth = null; yield return(_deki .At("pages", pageId.ToString(), "allowed") .With("permissions", "read,subscribe") .WithHeaders(request.Headers) .Post(new XDoc("users").Start("user").Attr("id", userInfo.Id).End(), new Result <DreamMessage>()) .Set(x => pageAuth = x)); if (!pageAuth.IsSuccessful || pageAuth.ToDocument()["user/@id"].AsText != userInfo.Id.ToString()) { throw new DreamForbiddenException("User not permitted to subscribe to page"); } var dataSession = GetDataSession(wikiId); dataSession.Subscribe(userInfo.Id, pageId, depth); response.Return(DreamMessage.Ok()); yield break; }
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!"); }
public void PostBanByIP() { // POST:site/bans // ... Plug p = Utils.BuildPlugForAdmin(); XDoc ban = new XDoc("bans") .Elem("description", Utils.GetSmallRandomText()) .Elem("date.expires", DateTime.Now.AddDays(10)) .Start("permissions.revoked") .Elem("operations", banRevokemask) .End() .Start("ban.addresses") .Elem("address", "192.168.0.1") .End(); DreamMessage msg = p.At("site", "bans").Post(ban); Assert.AreEqual(DreamStatus.Ok, msg.Status); string banid = msg.ToDocument()["@id"].AsText; Assert.IsTrue(!string.IsNullOrEmpty(banid)); msg = p.At("site", "bans").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsFalse(msg.ToDocument()[string.Format("ban[@id=\"{0}\"]", banid)].IsEmpty); msg = p.At("site", "bans", banid).Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.AreEqual(banid, msg.ToDocument()["@id"].AsText); }
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); }
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); }
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); } }
public void ConnectToDeki(string dreamAPI, string dekiUserName, string dekiUserPassword) { this._dreamAPI = dreamAPI; this._dekiPlug = Plug.New(_dreamAPI).WithCredentials(dekiUserName, dekiUserPassword); DreamMessage authResponse = _dekiPlug.At("users", "authenticate").GetAsync().Wait(); if (!authResponse.IsSuccessful) { Log.FatalFormat("Could not connect to MT API '{0}' username: '******' password: '******' Error:", _dekiPlug.ToString(), dekiUserName, dekiUserPassword, authResponse.ToString()); throw new DreamAbortException(authResponse); } //Check that user have admin rights DreamMessage userResponse = _dekiPlug.At("users", "=" + Utils.DoubleUrlEncode(dekiUserName)).Get(); XDoc resDoc = userResponse.AsDocument(); string roleName = resDoc["permissions.user/role"].AsText; if ((roleName == null) || (roleName.ToLower() != "admin")) { WriteLineToConsole("User " + dekiUserName + " should have Admin role in Deki."); return; } _connectedToDeki = true; }
private XDoc FetchSchema(Plug adoNetPlug) { XDoc ret = null; string key = adoNetPlug.At(METADATA_PATH).ToString(); lock (_cache) { _cache.TryGetValue(key, out ret); } if (ret == null) { string temp = adoNetPlug.At(METADATA_PATH).Get().AsTextReader().ReadToEnd(); //HACKHACKHACK to workaround ns issue temp = temp.Replace("xmlns=\"http://schemas.microsoft.com/ado/2006/04/edm\"", ""); ret = XDocFactory.From(temp, MimeType.XML); // add result to cache and start a clean-up timer lock (_cache) { _cache[key] = ret; } TaskTimer.New(TimeSpan.FromSeconds(CACHE_TTL), RemoveCachedEntry, key, TaskEnv.None); } //TODO: throw exception if schema is invalid somehow (or if the schema changed) return(ret); }
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); }
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); }
public void PageRevert() { // POST:pages/{pageid}/revert // http://developer.mindtouch.com/Deki/API_Reference/POST%3apages%2f%2f%7bpageid%7d%2f%2frevert Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); msg = p.At("pages", "=" + XUri.DoubleEncode(path), "revisions").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsFalse(msg.ToDocument()["page"].IsEmpty); string oldContent = "This is an old content"; PageUtils.SavePage(p, path, oldContent); msg = p.At("pages", id, "revisions").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsFalse(msg.ToDocument()["page"].IsEmpty); PageUtils.SavePage(p, path, "New content 2"); p.At("pages", id, "revert").With("fromrevision", -1).Post(); msg = p.At("pages", id, "contents").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status); Assert.IsTrue(msg.ToDocument()["body"].AsText == oldContent); PageUtils.DeletePageByID(p, id, true); }
public 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); }
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); }
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); }
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"); }
//--- Constructors --- /// <summary> /// Create new client instance /// </summary> /// <param name="config">Client configuration.</param> /// <param name="timerFactory">Timer factory.</param> public AmazonS3Client(AmazonS3ClientConfig config, TaskTimerFactory timerFactory) { _config = config; _bucketPlug = Plug.New(_config.S3BaseUri) .WithS3Authentication(_config.PrivateKey, _config.PublicKey) .WithTimeout(_config.Timeout) .At(_config.Bucket); _rootPlug = _bucketPlug; if(!string.IsNullOrEmpty(_config.RootPath)) { _keyRootParts = _config.RootPath.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries); if(_keyRootParts != null && _keyRootParts.Any()) { _rootPlug = _rootPlug.At(_keyRootParts); } } _expirationEntries = new ExpiringHashSet<string>(timerFactory); _expirationEntries.EntryExpired += OnDelete; }
public void Init() { _hostInfo = DreamTestHelper.CreateRandomPortHost(); _hostInfo.Host.Self.At("load").With("name", "test.mindtouch.dream").Post(DreamMessage.Ok()); var config = new XDoc("config") .Elem("path", "test") .Elem("sid", "http://services.mindtouch.com/dream/test/2010/07/featuretestserver"); DreamMessage result = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).PostAsync(config).Wait(); Assert.IsTrue(result.IsSuccessful, result.ToText()); _plug = Plug.New(_hostInfo.LocalHost.Uri.WithoutQuery()).At("test"); _blueprint = _plug.At("@blueprint").Get().ToDocument(); }
public void Init() { var builder = new ContainerBuilder(); builder.RegisterType<Foo>().As<IFoo>().RequestScoped(); _hostInfo = DreamTestHelper.CreateRandomPortHost(new XDoc("config"), builder.Build(ContainerBuildOptions.None)); _hostInfo.Host.Self.At("load").With("name", "test.mindtouch.dream").Post(DreamMessage.Ok()); var config = new XDoc("config") .Elem("path", "test") .Elem("sid", "http://services.mindtouch.com/dream/test/2010/07/featuretestserver"); DreamMessage result = _hostInfo.LocalHost.At("host", "services").With("apikey", _hostInfo.ApiKey).Post(config, new Result<DreamMessage>()).Wait(); Assert.IsTrue(result.IsSuccessful, result.ToText()); _plug = Plug.New(_hostInfo.LocalHost.Uri.WithoutQuery()).At("test"); _blueprint = _plug.At("@blueprint").Get().ToDocument(); }