public void TestComplaintBannedEmailIsCaughtUserNotLoggedIn() { // First make sure that the test user can make a complint before we put the email in the banned emails list DnaTestURLRequest request = new DnaTestURLRequest("h2g2"); request.SetCurrentUserNotLoggedInUser(); request.RequestPage("UserComplaintPage?postid=1&skin=purexml"); XmlDocument xml = request.GetLastResponseAsXML(); // Check to make sure that no errors came back Assert.IsTrue(xml.SelectSingleNode("//USER-COMPLAINT-FORM/ERROR") == null, "There should not be any errors present in the XML!"); // Now put the users email into the banned emails list for complaints if it's not already there IInputContext context = DnaMockery.CreateDatabaseInputContext(); using (IDnaDataReader reader = context.CreateDnaDataReader("AddEMailToBannedList")) { reader.AddParameter("Email", "*****@*****.**"); reader.AddParameter("SigninBanned", 0); reader.AddParameter("ComplaintBanned", 1); reader.AddParameter("EditorID", 6); reader.Execute(); Assert.IsTrue(reader.HasRows, "No rows came back from the AddEMailToBannedList storedprocedure"); Assert.IsTrue(reader.Read(), "Failed to read the first set of results from the AddEMailToBannedList storedprocedure"); Assert.IsTrue(reader.Exists("Duplicate"), "The Duplicate result field is not in the AddEMailToBannedList dataset"); } // Now try to complain again request.RequestPage("UserComplaintPage?postid=1&Submit=1&email=damnyoureyes72%[email protected]&skin=purexml"); xml = request.GetLastResponseAsXML(); // Check to make sure that no errors came back Assert.IsTrue(xml.SelectSingleNode("//ERROR") != null, "There should be an error present in the XML!"); Assert.IsTrue(xml.SelectSingleNode("//ERROR[@TYPE='EMAILNOTALLOWED']") != null, "There should be an EMAILNOTALLOWED error present in the XML!"); }
public void NotLoggedInUser() { Console.WriteLine("Before userTypes - NotLoggedInUser"); DnaTestURLRequest request = new DnaTestURLRequest(testUtils_ratingsAPI.sitename); request.SetCurrentUserNotLoggedInUser(); doIt_xml(request, HttpStatusCode.Unauthorized); Console.WriteLine("After userTypes - NotLoggedInUser"); }
protected static string CallAPIRequest(DnaTestURLRequest request, string requestURL, string postData, DnaTestURLRequest.usertype userType, string requestMethod) { if (userType == DnaTestURLRequest.usertype.SUPERUSER) { request.SetCurrentUserSuperUser(); } else if (userType == DnaTestURLRequest.usertype.EDITOR) { request.SetCurrentUserEditor(); } else if (userType == DnaTestURLRequest.usertype.NORMALUSER) { request.SetCurrentUserNormal(); } else { request.SetCurrentUserNotLoggedInUser(); } request.AssertWebRequestFailure = false; request.RequestPageWithFullURL(requestURL, postData, "application/json", requestMethod); return requestURL; }
public void GetMonthlySummaryArticles_FailsWithMonthSummaryNotFound() { Console.WriteLine("Before GetMonthlySummaryArticles_FailsWithMonthSummaryNotFound"); ClearArticlesForTheLastMonthForMonthSummaryFail(); DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNotLoggedInUser(); request.AssertWebRequestFailure = false; string url = String.Format("http://" + _server + "/dna/api/articles/ArticleService.svc/V1/site/{0}/articles/month?format=xml", _sitename); try { // now get the response request.RequestPageWithFullURL(url, null, "text/xml"); } catch (WebException) { } Assert.AreEqual(HttpStatusCode.NotFound, request.CurrentWebResponse.StatusCode); ErrorData errorData = (ErrorData)StringUtils.DeserializeObject(request.GetLastResponseAsXML().OuterXml, typeof(ErrorData)); Assert.AreEqual(ErrorType.MonthSummaryNotFound.ToString(), errorData.Code); Console.WriteLine("After GetMonthlySummaryArticles_FailsWithMonthSummaryNotFound"); }
public void CreateUsersLinksListTestWithUnknownIdentityUserName() { Console.WriteLine("Before CreateUsersLinksListTestWithUnknownIdentityUserName"); string identityusername = "******"; DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNotLoggedInUser(); request.AssertWebRequestFailure = false; try { string url = String.Format("http://" + _server + "/dna/api/users/UsersService.svc/V1/site/{0}/users/{1}/links?format=xml", _sitename, identityusername); // now get the response request.RequestPageWithFullURL(url, null, "text/xml"); } catch (WebException) { } Assert.AreEqual(HttpStatusCode.NotFound, request.CurrentWebResponse.StatusCode); ErrorData errorData = (ErrorData)StringUtils.DeserializeObject(request.GetLastResponseAsXML().OuterXml, typeof(ErrorData)); Assert.AreEqual(ErrorType.UserNotFound.ToString(), errorData.Code); Console.WriteLine("After CreateUsersLinksListTestWithUnknownIdentityUserName"); }
public void GetCallingUserInfo_AsNotLoggedInUser_Returns401() { Console.WriteLine("Before GetCallingUserInfo_AsNotLoggedInUser_Returns401"); DnaTestURLRequest request = new DnaTestURLRequest("h2g2"); request.SetCurrentUserNotLoggedInUser(); request.AssertWebRequestFailure = false; try { request.RequestPageWithFullURL(callinguserfull_secure_url); } catch (WebException) { } Assert.AreEqual(HttpStatusCode.Unauthorized, request.CurrentWebResponse.StatusCode); ErrorData errorData = (ErrorData)StringUtils.DeserializeObject(request.GetLastResponseAsXML().OuterXml, typeof(ErrorData)); Assert.AreEqual(ErrorType.MissingUserCredentials.ToString(), errorData.Code); Console.WriteLine("After GetCallingUserInfo_AsNotLoggedInUser_Returns401"); }
public void RemoveAs_notLoggedIn() { DnaTestURLRequest myRequest = new DnaTestURLRequest(testUtils_ratingsAPI.sitename); BBC.Dna.Api.RatingForum returnedForum = null; string forumId = testUtils_ratingsAPI.makeTestForum(); string ratingId = testUtils_ratingsAPI.makeTestItem(forumId); string url = makeCreatePickUrl(ratingId); // mark this comment as an editor's pick (this will crash if it fails) markComment(ratingId); returnedForum = readForum(forumId); // assume complete succes, don't keep cheking it // Now try to unmark it - can't use helper because it is designed to succeed string postData = testUtils_ratingsAPI.makeTimeStamp(); // needs some sort of post data otherwise it uses GET myRequest = new DnaTestURLRequest(testUtils_ratingsAPI.sitename); myRequest.SetCurrentUserNotLoggedInUser(); try { myRequest.RequestPageWithFullURL(url, String.Empty, String.Empty, "DELETE"); } catch { } Assert.IsTrue(myRequest.CurrentWebResponse.StatusCode == HttpStatusCode.Unauthorized, "Failed to clear an editor's pick. Got: " + myRequest.CurrentWebResponse.StatusCode + "\n" + myRequest.CurrentWebResponse.StatusDescription); }
public void ReadAs_notLoggedIn_someInMany() { // chose some random numbers. Severly constrained by the smallnes of testUtils_ratingsAPI.maxNumDiffUsers Random randomGen = new Random(); int index1 = randomGen.Next(0, 1); int index2 = randomGen.Next(2, 3); int index3 = randomGen.Next(4, 5); string[] commentArray; List<string> ratingList = new List<string>(); // create the data // first the forum string forumId = testUtils_ratingsAPI.makeTestForum(); // then a list of ratings for (int i = 0; i < testUtils_ratingsAPI.maxNumDiffUsers; i++) { ratingList.Add(testUtils_ratingsAPI.makeTestItem(forumId, i)); } // convert it to an array so it is easier to deal with commentArray = ratingList.ToArray(); // mark some markComment(commentArray[index1]); markComment(commentArray[index2]); markComment(commentArray[index3]); // read the list of editor's picks string url = makeReadPickUrl(forumId); DnaTestURLRequest myRequest = new DnaTestURLRequest(testUtils_ratingsAPI.sitename); myRequest.SetCurrentUserNotLoggedInUser(); try { myRequest.RequestPageWithFullURL(url); } catch { } Assert.IsTrue(myRequest.CurrentWebResponse.StatusCode == HttpStatusCode.OK, "Failed listing editor's picks. Got: " + myRequest.CurrentWebResponse.StatusCode + "\n" + myRequest.CurrentWebResponse.StatusDescription ); XmlDocument xml = myRequest.GetLastResponseAsXML(); DnaXmlValidator myValidator = new DnaXmlValidator(xml.InnerXml, testUtils_ratingsAPI._schemaRatingForum); myValidator.Validate(); BBC.Dna.Api.RatingForum returnedForum = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(myRequest.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum)); Assert.IsTrue(returnedForum.ratingsList.TotalCount == 3); // the default sort is by creation date and the marking should be in order down this list Assert.IsTrue(returnedForum.ratingsList.ratings[0].ID.ToString() == commentArray[index1], "First item does not match"); Assert.IsTrue(returnedForum.ratingsList.ratings[1].ID.ToString() == commentArray[index2], "Second item does not match"); Assert.IsTrue(returnedForum.ratingsList.ratings[2].ID.ToString() == commentArray[index3], "Third item does not match"); }
public void TestHtmlCachingOnNotLoggedIn() { Console.WriteLine("TestHtmlCachingOnNotLoggedIn"); int expiryTime = 30; SetHtmlCaching(true); SetHtmlCachingExpiryTime(expiryTime); RefreshSiteOptions(); CreateXSLTFile("HTML caching is ON"); DateTime start = DateTime.Now; DnaTestURLRequest request = new DnaTestURLRequest(_siteUrlName); request.SetCurrentUserNotLoggedInUser(); string s = RequestPage(request); Assert.IsTrue(s.Contains("HTML caching is ON"),"Initial request doesn't contain correct string"); CreateXSLTFile("HTML caching is STILL ON"); s = RequestPage(request); Assert.IsTrue(s.Contains("HTML caching is ON"),"Second request doesn't contain initial string"); Assert.IsFalse(s.Contains("HTML caching is STILL ON"),"Second request contains new string when it should still be the old one"); TimeSpan ts = DateTime.Now.Subtract(start); Assert.IsTrue(ts.Seconds < expiryTime,"Test didn't run fast enough"); // Sleep until the HTML caching has expired System.Threading.Thread.Sleep((expiryTime+1) * 1000 - ts.Milliseconds); s = RequestPage(request); Assert.IsFalse(s.Contains("HTML caching is ON"),"Request still has initial string - it should be the new on now"); Assert.IsTrue(s.Contains("HTML caching is STILL ON"),"The new string is not there yet"); }
public void TestHtmlCachingOffNotLoggedIn() { Console.WriteLine("TestHtmlCachingOffNotLoggedIn"); int expiryTime = 30; SetHtmlCaching(false); SetHtmlCachingExpiryTime(expiryTime); RefreshSiteOptions(); CreateXSLTFile("HTML caching is OFF"); DateTime start = DateTime.Now; DnaTestURLRequest request = new DnaTestURLRequest(_siteUrlName); request.SetCurrentUserNotLoggedInUser(); string s = RequestPage(request); Assert.IsTrue(s.Contains("HTML caching is OFF"),"Initial request doesn't contain correct string"); CreateXSLTFile("HTML caching is STILL OFF"); s = RequestPage(request); Assert.IsTrue(s.Contains("HTML caching is STILL OFF"), "Second request doesn't contain new string"); DateTime end = DateTime.Now; // This test has to complete within a time limit TimeSpan ts = end.Subtract(start); Assert.IsTrue(ts.Seconds < expiryTime,"Test didn't complete in time"); }
public void Test3BannedUser() { // First make sure that the test user can make a complaint before we put the email in the banned emails list DnaTestURLRequest request = new DnaTestURLRequest("haveyoursay"); request.SetCurrentUserNotLoggedInUser(); request.RequestPage("UserComplaintPage?postid=" + Convert.ToString(_postId) + "&action=submit&complaintreason=libellous&complainttext=Complaint&[email protected]&skin=purexml"); XmlDocument xml = request.GetLastResponseAsXML(); // Check to make sure complaint was processed Assert.IsTrue(xml.SelectSingleNode("//H2G2/USERCOMPLAINT/@REQUIRESVERIFICATION") != null, "Complaint did not succeed"); // Now put the users email into the banned emails list for complaints IInputContext context = DnaMockery.CreateDatabaseInputContext(); using (IDnaDataReader reader = context.CreateDnaDataReader("AddEMailToBannedList")) { reader.AddParameter("Email", "*****@*****.**"); reader.AddParameter("SigninBanned", 0); reader.AddParameter("ComplaintBanned", 1); reader.AddParameter("EditorID", 6); reader.AddIntReturnValue(); reader.Execute(); var duplicate = reader.GetIntReturnValue(); Assert.AreEqual(0,duplicate, "The Duplicate result should be false (0)"); } // Now try to complain again request = new DnaTestURLRequest("haveyoursay"); request.SetCurrentUserNotLoggedInUser(); request.RequestPage("UserComplaintPage?postid=" + Convert.ToString(_postId) + "&action=submit&complaintreason=libellous&complainttext=Complaint&[email protected]&skin=purexml"); xml = request.GetLastResponseAsXML(); // Check to make sure that complaint was not made. Assert.IsTrue(xml.SelectSingleNode("//H2G2/USERCOMPLAINT/@MODID") == null, "User is banned from complaining."); Assert.IsTrue(xml.SelectSingleNode("//H2G2/ERROR") != null, "User is banned from complaining."); }
public void RemoveAs_notLoggedIn() { DnaTestURLRequest myRequest = new DnaTestURLRequest(testUtils_CommentsAPI.sitename); BBC.Dna.Api.CommentForum returnedForum = null; string forumId = testUtils_CommentsAPI.makeTestCommentForum(); string commentID = testUtils_CommentsAPI.makeTestComment(forumId); string url = ""; // mark this comment as an editor's pick (this will crash if it fails) markComment(commentID); returnedForum = readForum(forumId); // assume complete succes, don't keep cheking it // Now try to unmark it - can't use helper becuse it is designed to succeed url = String.Format( "http://{0}/dna/api/comments/CommentsService.svc/V1/site/{1}/comments/{2}/editorpicks/", testUtils_CommentsAPI.server, testUtils_CommentsAPI.sitename, commentID ); string postData = testUtils_CommentsAPI.makeTimeStamp(); // needs some sort of post data otherwise it uses GET myRequest = new DnaTestURLRequest(testUtils_CommentsAPI.sitename); myRequest.SetCurrentUserNotLoggedInUser(); try { myRequest.RequestPageWithFullURL(url, String.Empty, String.Empty, "DELETE"); } catch { } Assert.IsTrue(myRequest.CurrentWebResponse.StatusCode == HttpStatusCode.Unauthorized, "Failed to clear an editor's pick. Got: " + myRequest.CurrentWebResponse.StatusCode + "\n" + myRequest.CurrentWebResponse.StatusDescription); }
public void ReadAs_notLoggedIn_someInMany() { XmlDocument xml; DnaXmlValidator myValidator; DnaTestURLRequest myRequest = new DnaTestURLRequest(testUtils_CommentsAPI.sitename); Random randomGen = new Random(); int listLen = randomGen.Next(10, 20); int index1 = randomGen.Next(0, 3); int index2 = randomGen.Next(4, 6); int index3 = randomGen.Next(7, listLen); string[] commentArray; List<string> commentList = new List<string>(); string forumId = testUtils_CommentsAPI.makeTestCommentForum(); for( int i = 0; i < listLen; i++){ commentList.Add(testUtils_CommentsAPI.makeTestComment(forumId)); } commentArray = commentList.ToArray(); markComment(commentArray[index1]); markComment(commentArray[index2]); markComment(commentArray[index3]); // now read the list of editor's picks myRequest.SetCurrentUserNotLoggedInUser(); string url = String.Format( "http://{0}/dna/api/comments/CommentsService.svc/V1/site/{1}/commentsforums/{2}/?filterBy=EditorPicks", testUtils_CommentsAPI.server, testUtils_CommentsAPI.sitename, forumId ); try { myRequest.RequestPageWithFullURL(url); } catch { } Assert.IsTrue(myRequest.CurrentWebResponse.StatusCode == HttpStatusCode.OK, "Failed listing editor's picks. Got: " + myRequest.CurrentWebResponse.StatusCode + "\n" + myRequest.CurrentWebResponse.StatusDescription ); xml = myRequest.GetLastResponseAsXML(); myValidator = new DnaXmlValidator(xml.InnerXml, testUtils_CommentsAPI._schemaCommentForum); myValidator.Validate(); BBC.Dna.Api.CommentForum returnedForum = (BBC.Dna.Api.CommentForum)StringUtils.DeserializeObject(myRequest.GetLastResponseAsString(), typeof(BBC.Dna.Api.CommentForum)); Assert.IsTrue(returnedForum.commentList.TotalCount == 3); // the default sort is by creation date and the marking should be in order down this list Assert.IsTrue(returnedForum.commentList.comments[0].ID.ToString() == commentArray[index1], "First item does not match"); Assert.IsTrue(returnedForum.commentList.comments[1].ID.ToString() == commentArray[index2], "Second item does not match"); Assert.IsTrue(returnedForum.commentList.comments[2].ID.ToString() == commentArray[index3], "Third item does not match"); }
public void GetUserInfoWithUnknownDNAUserId() { Console.WriteLine("Before GetUserInfoWithUnknownDNAUserId"); int dnaUserId = 9999999; DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNotLoggedInUser(); request.AssertWebRequestFailure = false; try { string url = String.Format("http://" + _server + "/dna/api/users/UsersService.svc/V1/site/{0}/users/{1}?idtype=DNAUserId&format=xml", _sitename, dnaUserId); // now get the response request.RequestPageWithFullURL(url, null, "text/xml"); } catch (WebException) { } Assert.AreEqual(HttpStatusCode.NotFound, request.CurrentWebResponse.StatusCode); ErrorData errorData = (ErrorData)StringUtils.DeserializeObject(request.GetLastResponseAsXML().OuterXml, typeof(ErrorData)); Assert.AreEqual(ErrorType.UserNotFound.ToString(), errorData.Code); Console.WriteLine("After GetUserInfoWithUnknownDNAUserId"); }
public void Test3BannedUser() { // First make sure that the test user can make a complaint before we put the email in the banned emails list DnaTestURLRequest request = new DnaTestURLRequest("haveyoursay"); request.SetCurrentUserNotLoggedInUser(); request.RequestPage("UserComplaintPage?postid=" + Convert.ToString(_postId) + "&action=submit&complaintreason=libellous&complainttext=Complaint&[email protected]&skin=purexml"); XmlDocument xml = request.GetLastResponseAsXML(); // Check to make sure complaint was processed Assert.IsTrue(xml.SelectSingleNode("//H2G2/USERCOMPLAINT/@MODID") != null, "Complaint did not succeed"); // Now put the users email into the banned emails list for complaints IInputContext context = DnaMockery.CreateDatabaseInputContext(); using (IDnaDataReader reader = context.CreateDnaDataReader("AddEMailToBannedList")) { reader.AddParameter("Email", "*****@*****.**"); reader.AddParameter("SigninBanned", 0); reader.AddParameter("ComplaintBanned", 1); reader.AddParameter("EditorID", 6); reader.Execute(); Assert.IsTrue(reader.HasRows, "No rows came back from the AddEMailToBannedList storedprocedure"); Assert.IsTrue(reader.Read(), "Failed to read the first set of results from the AddEMailToBannedList storedprocedure"); Assert.IsTrue(reader.Exists("Duplicate"), "The Duplicate result field is not in the AddEMailToBannedList dataset"); Assert.IsFalse(reader.GetBoolean("Duplicate"), "The Duplicate result should be false!"); } // Now try to complain again request = new DnaTestURLRequest("haveyoursay"); request.SetCurrentUserNormal(); request.RequestPage("UserComplaintPage?postid=" + Convert.ToString(_postId) + "&action=submit&complaintreason=libellous&complainttext=Complaint&email=damnyoureyes72%[email protected]&skin=purexml"); xml = request.GetLastResponseAsXML(); // Check to make sure that complaint was not made. Assert.IsTrue(xml.SelectSingleNode("//H2G2/USERCOMPLAINT/@MODID") == null, "User is banned from complaining."); Assert.IsTrue(xml.SelectSingleNode("//H2G2/ERROR") != null, "User is banned from complaining."); }