public void DeleteComment_Owner() { //Assert.Inconclusive("Complete this test"); var user = TestHelper.SetPrincipal("TestUser01"); var cmdcreate = new CreateCommentCommand(1, null, "This is my data too you know").SetUserContext(user); var c = cmdcreate.Execute().Result; VoatAssert.IsValid(c); int id = c.Response.ID; var cmd = new DeleteCommentCommand(id).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r); //verify using (var db = new VoatDataContext()) { var comment = db.Comment.FirstOrDefault(x => x.ID == id); Assert.AreEqual(true, comment.IsDeleted); Assert.AreNotEqual(c.Response.Content, comment.Content); //Ensure content is replaced in moderator deletion Assert.IsTrue(comment.Content.StartsWith("Deleted by")); Assert.AreEqual(comment.FormattedContent, Formatting.FormatMessage(comment.Content)); } }
public void TestRestrictionGrouping() { var r = new Voat.Data.Models.VoteRestriction() { ID = 1, //GroupName = "Default", Type = typeof(ContributionCountRestriction).Name, Data = (new ContributionCountRestriction() { ContentType = (ContentTypeRestriction)(Domain.Models.ContentType.Comment | Domain.Models.ContentType.Submission), Duration = TimeSpan.FromDays(180), Subverse = "unit", MinimumCount = 1, EndDate = DateTime.UtcNow }).Serialize(), VoteID = 1 }; var constructed = (IVoteRestriction)VoteItem.Deserialize <VoteItem>(r.Data); var user = TestHelper.SetPrincipal(USERNAMES.User500CCP); var outcome = constructed.Evaluate(user); VoatAssert.IsValid(outcome); var restrictionSet = new VoteRestrictionSet(); restrictionSet.Populate(new Voat.Data.Models.VoteRestriction[] { r }); var eval = restrictionSet.Evaluate(user); Assert.IsTrue(eval.IsValid); }
public void TestNegativeSCPSubmission() { var userName = "******"; //Create user TestDataInitializer.CreateUser(userName, DateTime.UtcNow.AddDays(-450)); //Add submission with negatives directly to db using (var context = new VoatDataContext()) { var s = context.Submission.Add(new Submission() { CreationDate = DateTime.UtcNow.AddHours(-12), Subverse = SUBVERSES.Unit, Title = "Test Negative SCP", Url = "https://www.youtube.com/watch?v=pnbJEg9r1o8", Type = 2, UpCount = 2, DownCount = 13, UserName = userName }); context.SaveChanges(); } var user = TestHelper.SetPrincipal(userName); var userSubmission = new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "Le Censorship!", Content = "Will this work?" }; var cmd = new CreateSubmissionCommand(userSubmission).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r); }
public async Task AllowSubmittingDeletedLink() { var user = TestHelper.SetPrincipal("UnitTestUser31"); var cmd = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "I need to think of better titles but I don't want to get in trouble", Url = "http://i.deleted.this.on/purpose.jpg" }).SetUserContext(user); var r = await cmd.Execute(); VoatAssert.IsValid(r); var id = r.Response.ID; var cmd2 = new DeleteSubmissionCommand(id).SetUserContext(user); var r2 = await cmd2.Execute(); VoatAssert.IsValid(r); cmd = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "Hello Man - Longer because of Rules", Url = "http://i.deleted.this.on/purpose.jpg" }).SetUserContext(user); r = await cmd.Execute(); VoatAssert.IsValid(r); }
public void Edit_Submission_Title_Content() { var user = TestHelper.SetPrincipal("anon"); var x = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Anon, Title = "xxxxxxxxxxxx", Content = "xxxxxxxxxxxx" }).SetUserContext(user); var s = x.Execute().Result; Assert.IsNotNull(s, "Response is null"); Assert.IsTrue(s.Success, s.Message); var cmd = new EditSubmissionCommand(s.Response.ID, new Domain.Models.UserSubmission() { Title = "yyyyyyyyyyyy", Content = "yyyyyyyyyyyy" }).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r, message: "Edit Submission failed to return true: " + r.Message); using (var repo = new Voat.Data.Repository()) { var submission = repo.GetSubmission(s.Response.ID); Assert.IsNotNull(submission, "Can't find submission from repo"); Assert.AreEqual("yyyyyyyyyyyy", submission.Title); Assert.AreEqual("yyyyyyyyyyyy", submission.Content); } //Assert.Inconclusive(); }
public async Task DeleteComment_Moderator() { //Assert.Inconclusive("Complete this test"); var content = "This is my data too you know 2"; var user = TestHelper.SetPrincipal("TestUser01"); var cmdcreate = new CreateCommentCommand(1, null, content).SetUserContext(user); var c = cmdcreate.Execute().Result; VoatAssert.IsValid(c); int id = c.Response.ID; //switch to mod of sub user = TestHelper.SetPrincipal(USERNAMES.Unit); var cmd = new DeleteCommentCommand(id, "This is spam").SetUserContext(user); var r = await cmd.Execute(); VoatAssert.IsValid(r); //verify using (var db = new VoatDataContext()) { var comment = db.Comment.FirstOrDefault(x => x.ID == id); Assert.AreEqual(true, comment.IsDeleted); //Content should remain unchanged in mod deletion Assert.AreEqual(comment.Content, content); Assert.AreEqual(comment.FormattedContent, Formatting.FormatMessage(content)); } }
public async Task CreateSet_Test() { var userName = "******"; var user = TestHelper.SetPrincipal(userName); var set = new Set() { Name = "HolyHell", Title = "Some Title", Type = SetType.Normal, UserName = userName }; var cmd = new UpdateSetCommand(set).SetUserContext(user); var result = await cmd.Execute(); VoatAssert.IsValid(result); Assert.AreNotEqual(0, result.Response.ID); var setID = result.Response.ID; VerifySubscriber(set, userName, 1); //Subscribe another user userName = "******"; user = TestHelper.SetPrincipal(userName); var subCmd = new SubscribeCommand(new DomainReference(DomainType.Set, set.Name, set.UserName), SubscriptionAction.Subscribe).SetUserContext(user); var subResult = await subCmd.Execute(); VoatAssert.IsValid(result); VerifySubscriber(set, userName, 2); //unsub user subCmd = new SubscribeCommand(new DomainReference(DomainType.Set, set.Name, set.UserName), SubscriptionAction.Unsubscribe).SetUserContext(user); subResult = await subCmd.Execute(); VoatAssert.IsValid(result); VerifySubscriber(set, userName, 1, false); }
public async Task DeleteSubmission_Moderator() { var user = TestHelper.SetPrincipal("TestUser13"); var cmd = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "This is a title", Content = "This is content a mod would hate" }).SetUserContext(user); var r = await cmd.Execute(); VoatAssert.IsValid(r); Assert.IsNotNull(r.Response, "Expecting a non null response"); Assert.AreNotEqual(0, r.Response.ID); user = TestHelper.SetPrincipal(USERNAMES.Unit); var d = new DeleteSubmissionCommand(r.Response.ID, "This is content I hate").SetUserContext(user); var r2 = await d.Execute(); VoatAssert.IsValid(r2); //verify using (var db = new Voat.Data.Repository(user)) { var s = db.GetSubmission(r.Response.ID); Assert.AreEqual(true, s.IsDeleted); //Content should remain unchanged in mod deletion Assert.AreEqual(s.Content, r.Response.Content); Assert.AreEqual(s.FormattedContent, r.Response.FormattedContent); //Assert.IsTrue(s.Content.StartsWith("Deleted by")); //Assert.AreEqual(s.FormattedContent, Utilities.Formatting.FormatMessage(s.Content)); } }
public async Task UpdateUserPreferences() { var userName = "******"; var bio = Guid.NewGuid().ToString(); var user = TestHelper.SetPrincipal(userName); var q = new QueryUserPreferences(userName).SetUserContext(user); var prefs = await q.ExecuteAsync(); Assert.IsNotNull(prefs, "Pref query returned null"); Assert.AreNotEqual(prefs.Bio, bio, "Bio returned unexpected data"); var cmd = new UpdateUserPreferencesCommand(new Domain.Models.UserPreferenceUpdate() { Bio = bio }).SetUserContext(user); var r = await cmd.Execute(); VoatAssert.IsValid(r); q = new QueryUserPreferences(userName).SetUserContext(user); prefs = await q.ExecuteAsync(); Assert.IsNotNull(prefs, "Pref requery returned null"); Assert.AreEqual(prefs.Bio, bio, "Bio not updated"); }
public async Task UserData_Information_SubscriptionTests() { //ensure users with no subscriptions don't error out var noSubUserName = "******"; TestDataInitializer.CreateUser(noSubUserName); var userData = new Domain.UserData(noSubUserName); //var userData = new Domain.UserData(noSubUserName); Assert.AreEqual(0, userData.SubverseSubscriptions.Count()); Assert.AreEqual(false, userData.HasSubscriptions()); Assert.AreEqual(false, userData.HasSubscriptions(DomainType.Subverse)); //test subscription var subUserName = "******"; TestDataInitializer.CreateUser(subUserName); var user = TestHelper.SetPrincipal(subUserName); var cmd = new SubscribeCommand(new DomainReference(DomainType.Subverse, SUBVERSES.Unit), Domain.Models.SubscriptionAction.Subscribe).SetUserContext(user); var x = await cmd.Execute(); VoatAssert.IsValid(x); userData = new Domain.UserData(subUserName); Assert.AreEqual(1, userData.SubverseSubscriptions.Count()); Assert.AreEqual(SUBVERSES.Unit, userData.SubverseSubscriptions.First()); Assert.AreEqual(true, userData.HasSubscriptions()); Assert.AreEqual(true, userData.HasSubscriptions(DomainType.Subverse)); Assert.AreEqual(true, userData.IsUserSubverseSubscriber(SUBVERSES.Unit)); }
public async Task SendBadRecipientInfo_CheckExists() { var id = Guid.NewGuid().ToString(); var sender = USERNAMES.User100CCP; var user = TestHelper.SetPrincipal(sender); var cmd = new SendMessageCommand(new Domain.Models.SendMessage() { Recipient = "Do you like chocolate", Message = id, Subject = "All That Matters" }, false, true).SetUserContext(user); var response = await cmd.Execute(); VoatAssert.IsValid(response, Status.Error); Assert.AreNotEqual("Comment points too low to send messages. Need at least 10 CCP.", response.Message); using (var db = new VoatDataContext()) { var count = (from x in db.Message where x.Content == id select x).Count(); Assert.AreEqual(0, count, "Expecting no messages to make it through"); } }
public async Task SendPrivateMessageFromSubverse() { var id = Guid.NewGuid().ToString(); var sender = "unit"; var recipient = USERNAMES.User100CCP; var user = TestHelper.SetPrincipal(sender); var message = new Domain.Models.SendMessage() { Sender = $"v/{sender}", Recipient = recipient, Subject = id, Message = id }; var cmd = new SendMessageCommand(message).SetUserContext(user); var r = await cmd.Execute(); VoatAssert.IsValid(r); using (var db = new VoatDataContext()) { var record = (from x in db.Message where x.Sender == sender && x.SenderType == (int)Domain.Models.IdentityType.Subverse && x.Recipient == recipient && x.RecipientType == (int)Domain.Models.IdentityType.User && x.Title == id && x.Content == id select x).FirstOrDefault(); Assert.IsNotNull(record, "Can not find message in database"); } }
public async Task CreateComment_Anon() { string userName = "******"; var user = TestHelper.SetPrincipal(userName); var cmd = new CreateCommentCommand(2, null, "This is my data").SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c); Assert.AreNotEqual(0, c.Response.ID); Assert.AreEqual(true, c.Response.IsAnonymized); Assert.AreNotEqual(cmd.Content, c.Response.FormattedContent); //verify in db using (var db = new Voat.Data.Repository(user)) { var comment = await db.GetComment(c.Response.ID); Assert.IsNotNull(comment, "Couldn't find comment in db", c.Response.ID); Assert.AreEqual(c.Response.ID, comment.ID); Assert.AreEqual(comment.ID.ToString(), comment.UserName); Assert.AreEqual(c.Response.Content, comment.Content); Assert.IsTrue(comment.IsAnonymized); Assert.AreEqual(c.Response.IsAnonymized, comment.IsAnonymized); } base.VerifyCommentIsProtected(c.Response.SubmissionID.Value, c.Response.ID, userName); }
public async Task Submission_Length_Validations() { var user = TestHelper.SetPrincipal("TestUser20"); var createCmd = new CreateSubmissionCommand( new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "Can you hear me now?".RepeatUntil(201), Content = null }).SetUserContext(user); var r = await createCmd.Execute(); VoatAssert.IsValid(r, Status.Invalid); createCmd = new CreateSubmissionCommand( new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "Can you hear me now?", Content = "Great!".RepeatUntil(10001) }).SetUserContext(user); r = await createCmd.Execute(); VoatAssert.IsValid(r, Status.Invalid); Assert.IsTrue(r.ValidationErrors.Any(x => x.MemberNames.Any(m => m.IsEqual("content")))); createCmd = new CreateSubmissionCommand( new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "Can you hear me now?", Content = "Great!" }).SetUserContext(user); r = await createCmd.Execute(); VoatAssert.IsValid(r); var editCmd = new EditSubmissionCommand(r.Response.ID, new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "Can you hear me now?", Content = "Great!".RepeatUntil(10001), }).SetUserContext(user); r = await editCmd.Execute(); VoatAssert.IsValid(r, Status.Invalid); //editCmd = new EditSubmissionCommand(r.Response.ID, new Domain.Models.UserSubmission() //{ // Subverse = SUBVERSES.Unit, // Title = "Can you hear me now?", // Content = "Great!".RepeatUntil(10001), //}).SetUserContext(user); //r = await createCmd.Execute(); //VoatAssert.IsValid(r, Status.Denied); }
public void CreateComment_WithGloballyBannedUser() { var user = TestHelper.SetPrincipal("BannedGlobally"); var cmd = new CreateCommentCommand(1, null, "This is my data").SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c, Status.Denied, "User should be banned from commenting"); }
public void CreateComment_Empty() { var user = TestHelper.SetPrincipal("TestUser12"); var cmd = new CreateCommentCommand(1, null, " ").SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c, Status.Denied); Assert.AreEqual("Empty comments not allowed", c.Message); }
public void CreateComment_BannedDomain_NoProtocol() { var user = TestHelper.SetPrincipal("TestUser02"); var cmd = new CreateCommentCommand(1, null, "[Check out this killer website](//fleddit.com/f/3hen3k/Look_at_this_cat_just_Looook_awww)!").SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c, Status.Denied); Assert.AreEqual("Comment contains banned domains", c.Message); }
public static Domain.Models.Comment CreateComment(string userName, int submissionID, string content, int?parentCommentID = null) { var user = TestHelper.SetPrincipal(userName); var cmd = new CreateCommentCommand(submissionID, parentCommentID, content).SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c); Assert.AreNotEqual(0, c.Response.ID); return(c.Response); }
public static Domain.Models.Submission CreateSubmission(string userName, Domain.Models.UserSubmission submission) { var user = TestHelper.SetPrincipal(userName); var cmd = new CreateSubmissionCommand(submission).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r); Assert.AreNotEqual(0, r.Response.ID); return(r.Response); }
public void PreventSubverseBannedUsers() { var user = TestHelper.SetPrincipal("BannedFromVUnit"); var userSubmission = new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = Guid.NewGuid().ToString(), Url = "http://www.SuperAwesomeDomainName.com/images/feelsgoodman.jpg" }; var cmd = new CreateSubmissionCommand(userSubmission).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r, Status.Denied); Assert.AreEqual(r.Message, $"User is banned from v/{userSubmission.Subverse}"); }
public void LongUrl_Bug() { var user = TestHelper.SetPrincipal("TestUser09"); var cmd = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Whatever, Title = "Long Url Bug", Url = "http://kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk.com/" }).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r, Status.Success); //Assert.AreNotEqual(0, r.Response.ID); }
public void PreventPartialUrlTitlePosts_Bug() { var user = TestHelper.SetPrincipal("TestUser09"); var cmd = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Whatever, Title = "speedtesting", Url = "http://beta.speedtesting.net/" }).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r, Status.Success); //Assert.AreNotEqual(0, r.Response.ID); }
public void PreventShortTitlePosts() { var user = TestHelper.SetPrincipal("TestUser02"); var cmd = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "What", Url = "http://www.hellogoodbye.com/images/feelsgoodman.jpg" }).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r, Status.Invalid); Assert.AreEqual(r.Message, $"A title must be between {VoatSettings.Instance.MinimumTitleLength} and {VoatSettings.Instance.MaximumTitleLength} characters"); }
public void PreventGlobalBannedUsers() { var user = TestHelper.SetPrincipal("BannedGlobally"); var userSubmission = new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = Guid.NewGuid().ToString(), Url = "http://www.SendhelpImStuckInUnitTests.com/images/feelsgoodman.jpg" }; var cmd = new CreateSubmissionCommand(userSubmission).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r, Status.Denied); Assert.AreEqual(r.Message, "User is globally banned"); }
public void PreventPostingToDisabledSub() { var user = TestHelper.SetPrincipal("TestUser06"); var userSubmission = new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Disabled, Title = "I am not paying attention", Content = "Why was this sub disabled?" }; var cmd = new CreateSubmissionCommand(userSubmission).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r, Status.Denied); Assert.AreEqual("Subverse is disabled", r.Message); }
public void PreventUserFromPostingCompromisedTitle1() { var user = TestHelper.SetPrincipal("TestUser01"); var userSubmission = new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Whatever, Title = "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000", Content = "cookies" }; var cmd = new CreateSubmissionCommand(userSubmission).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r, Status.Denied); Assert.AreEqual(r.Message, "Submission title can not contain Unicode or unprintable characters"); }
public void CreateSubmissionTrapJSInUrl() { var user = TestHelper.SetPrincipal("TestUser06"); var cmd = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Whatever, Title = "This is a title", Url = "javascript:alert('arst');" }).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r, Status.Invalid); Assert.AreEqual(r.Message, "The url you are trying to submit is invalid"); }
public void PreventUserFromPostingToAuthorizedOnlySubverses() { var user = TestHelper.SetPrincipal("TestUser09"); var userSubmission = new Domain.Models.UserSubmission() { Subverse = SUBVERSES.AuthorizedOnly, Title = Guid.NewGuid().ToString(), Url = "http://www.digit.com/images/feelsgoodman.jpg" }; var cmd = new CreateSubmissionCommand(userSubmission).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r, Status.Denied); Assert.AreEqual(r.Message, "You are not authorized to submit links or start discussions in this subverse. Please contact subverse moderators for authorization"); }
public async Task SendPrivateMessage() { var id = Guid.NewGuid().ToString(); var sender = USERNAMES.User100CCP; var recipient = USERNAMES.Anon; var user = TestHelper.SetPrincipal(sender); var message = new Domain.Models.SendMessage() { //Sender = User.Identity.Name, Recipient = recipient, Subject = id, Message = id }; var cmd = new SendMessageCommand(message).SetUserContext(user); var response = await cmd.Execute(); VoatAssert.IsValid(response); using (var db = new VoatDataContext()) { var record = (from x in db.Message where x.Recipient == recipient && x.Sender == sender && x.Title == id && x.Content == id && x.Subverse == null && x.CommentID == null && x.SubmissionID == null && x.Type == (int)Domain.Models.MessageType.Sent //&& x.Direction == (int)Domain.Models.MessageDirection.OutBound select x).FirstOrDefault(); Assert.IsNotNull(record, "Can not find outbound in database"); record = (from x in db.Message where x.Recipient == recipient && x.Sender == sender && x.Title == id && x.Content == id && x.Subverse == null && x.CommentID == null && x.SubmissionID == null && x.Type == (int)Domain.Models.MessageType.Private //&& x.Direction == (int)Domain.Models.MessageDirection.InBound select x).FirstOrDefault(); Assert.IsNotNull(record, "Can not find inbound in database"); } }
public async Task MentionUser_Anon_NoBlock_Test() { string user1 = "UnitTestUser11"; string user2 = "UnitTestUser12"; var user = TestHelper.SetPrincipal(user1); //Submission var anonSubmission = TestHelper.ContentCreation.CreateSubmission(user1, new Domain.Models.UserSubmission() { Title = $"I'm harrassing @{user2}!", Content = GetMethodName(true), Subverse = SUBVERSES.Anon }); Assert.IsNotNull(anonSubmission, "Couldn't create test submission"); Assert.AreNotEqual(0, anonSubmission.ID, "Doesn't appear we have a valid submission id"); Thread.Sleep(2000); using (var db = new VoatDataContext()) { var count = db.Message.Where(x => x.Sender == user1 && x.Recipient == user2 && x.SubmissionID == anonSubmission.ID && x.IsAnonymized == true && x.Type == (int)Domain.Models.MessageType.SubmissionMention ).Count(); Assert.AreEqual(1, count, "Where is the harassment submission message!?!?!?"); } //Comment string mentionTwiceContent = $"Hello @{user2}, I am mentioning you in an anon thread because I want to make you feel scared"; var cmd = new CreateCommentCommand(anonSubmission.ID, null, mentionTwiceContent).SetUserContext(user); var result = await cmd.Execute(); VoatAssert.IsValid(result); using (var db = new VoatDataContext()) { var count = db.Message.Where(x => x.Sender == user1 && x.Recipient == user2 && x.CommentID == result.Response.ID && x.IsAnonymized == true && x.Type == (int)Domain.Models.MessageType.CommentMention ).Count(); Assert.AreEqual(1, count, "Where is the harassment comment message!?!?!?"); } }