Ejemplo n.º 1
0
        private void VerifySubscriber(Set set, string userName, int expectedCount, bool exists = true)
        {
            //check data
            using (var db = new Voat.Data.Models.VoatDataContext())
            {
                var dbSet = db.SubverseSet.FirstOrDefault(x => x.Name == set.Name && x.UserName == set.UserName && x.Type == (int)set.Type);
                Assert.IsNotNull(dbSet, "Can not find set as created");
                Assert.AreEqual(expectedCount, dbSet.SubscriberCount, "Subscriber Count Off on set");

                var subscription = db.SubverseSetSubscription.FirstOrDefault(x => x.SubverseSetID == dbSet.ID && x.UserName == userName);
                if (exists)
                {
                    Assert.IsNotNull(subscription, "Expecting a subscription but couldn't find it");
                }
                else
                {
                    Assert.IsNull(subscription, "Expecting to not find a subscription, but found one");
                }

                var count = db.SubverseSetSubscription.Count(x => x.SubverseSetID == dbSet.ID);
                Assert.AreEqual(expectedCount, count, "SubverseSetSubscription record entries are off from expected count");
            }
        }
Ejemplo n.º 2
0
        public async Task Bug_Trap_Positive_ContributionPoints_Removed()
        {
            //Test that when a user deletes comments and submissions with positive points, that the points are reset
            var altList       = new[] { "UnitTestUser10", "UnitTestUser11", "UnitTestUser12", "UnitTestUser13", "UnitTestUser14", "UnitTestUser15" };
            var primaryUser   = "******";
            var currentUser   = TestHelper.SetPrincipal(primaryUser);
            var cmdSubmission = new CreateSubmissionCommand(new Domain.Models.UserSubmission()
            {
                Title = "Test Positive SCP Removed upon Delete", Content = "Does this get removed?", Subverse = "unit"
            }).SetUserContext(currentUser);
            var subResponse = await cmdSubmission.Execute();

            VoatAssert.IsValid(subResponse);
            var submissionID = subResponse.Response.ID;

            var cmdComment      = new CreateCommentCommand(submissionID, null, "This is my manipulation comment. Upvote. Go.").SetUserContext(currentUser);
            var commentResponse = await cmdComment.Execute();

            VoatAssert.IsValid(commentResponse);
            var commentID = commentResponse.Response.ID;

            var vote = new Func <int, Domain.Models.ContentType, string[], Task>(async(id, contentType, users) => {
                foreach (string user in users)
                {
                    var userIdentity = TestHelper.SetPrincipal(user);
                    switch (contentType)
                    {
                    case Domain.Models.ContentType.Comment:

                        var c  = new CommentVoteCommand(id, 1, Guid.NewGuid().ToString()).SetUserContext(userIdentity);
                        var cr = await c.Execute();
                        VoatAssert.IsValid(cr);

                        break;

                    case Domain.Models.ContentType.Submission:

                        var s  = new SubmissionVoteCommand(id, 1, Guid.NewGuid().ToString()).SetUserContext(userIdentity);
                        var sr = await s.Execute();
                        VoatAssert.IsValid(sr);
                        break;
                    }
                }
            });

            await vote(commentID, Domain.Models.ContentType.Comment, altList);

            var deleteComment         = new DeleteCommentCommand(commentID).SetUserContext(currentUser);
            var deleteCommentResponse = await deleteComment.Execute();

            VoatAssert.IsValid(deleteCommentResponse);
            //verify ups where reset
            using (var context = new Voat.Data.Models.VoatDataContext())
            {
                var votes = context.CommentVoteTracker.Where(x => x.CommentID == commentID);
                Assert.AreEqual(altList.Length, votes.Count());
                var anyInvalid = votes.Any(x => x.VoteValue != 0);
                Assert.IsFalse(anyInvalid, "Found comment votes with a non-zero vote value");
            }


            await vote(submissionID, Domain.Models.ContentType.Submission, altList);

            var deleteSubmission         = new DeleteSubmissionCommand(submissionID).SetUserContext(currentUser);
            var deleteSubmissionResponse = await deleteSubmission.Execute();

            VoatAssert.IsValid(deleteSubmissionResponse);
            //verify ups where reset
            using (var context = new Voat.Data.Models.VoatDataContext())
            {
                var votes = context.SubmissionVoteTracker.Where(x => x.SubmissionID == submissionID);
                Assert.AreEqual(altList.Length + 1, votes.Count()); //author has a vote
                var anyInvalid = votes.Any(x => x.VoteValue != 0);
                Assert.IsFalse(anyInvalid, "Found submission votes with a non-zero vote value");
            }
        }
Ejemplo n.º 3
0
        private void VerifyDelete(Domain.Models.DeleteAccountOptions options)
        {
            using (var db = new Voat.Data.Models.VoatDataContext())
            {
                int count = 0;
                switch (options.Comments.Value)
                {
                case Domain.Models.DeleteOption.Anonymize:

                    count = db.Comment.Count(x => x.UserName.ToLower() == options.UserName && !x.IsAnonymized);
                    Assert.AreEqual(0, count, $"Comment {options.Comments.ToString()} setting found violations");

                    break;

                case Domain.Models.DeleteOption.Delete:

                    count = db.Comment.Count(x => x.UserName.ToLower() == options.UserName.ToLower() && !x.IsDeleted);
                    Assert.AreEqual(0, count, $"Comment {options.Comments.ToString()} setting found violations");
                    break;
                }

                var checkSubmissions = new Action <string, Domain.Models.SubmissionType, Domain.Models.DeleteOption>((userName, submissionType, deleteSetting) =>
                {
                    switch (deleteSetting)
                    {
                    case Domain.Models.DeleteOption.Anonymize:

                        count = db.Submission.Count(x => x.UserName.ToLower() == options.UserName.ToLower() && !x.IsAnonymized && x.Type == (int)submissionType);
                        Assert.AreEqual(0, count, $"{submissionType.ToString()} Submission {deleteSetting.ToString()} setting found violations");

                        break;

                    case Domain.Models.DeleteOption.Delete:

                        count = db.Submission.Count(x => x.UserName.ToLower() == options.UserName.ToLower() && !x.IsDeleted && x.Type == (int)submissionType);
                        Assert.AreEqual(0, count, $"{submissionType.ToString()} Submission {deleteSetting.ToString()} setting found violations");
                        break;
                    }
                });

                checkSubmissions(options.UserName, Domain.Models.SubmissionType.Text, options.TextSubmissions);
                checkSubmissions(options.UserName, Domain.Models.SubmissionType.Link, options.LinkSubmissions);

                //Check account VoatSettings.Instance.
                using (var userManager = VoatUserManager.Create())
                {
                    var userAccount = userManager.FindByName(options.UserName);

                    Assert.IsNotNull(userAccount, "Can't find user account using manager");
                    if (!String.IsNullOrEmpty(options.RecoveryEmailAddress))
                    {
                        //Verify recovery info
                        Assert.AreEqual(userAccount.Email, options.RecoveryEmailAddress);
                        Assert.IsNotNull(userAccount.LockoutEnd, "Lockout should be enabled");
                        Assert.IsTrue(userAccount.LockoutEnd.Value.Subtract(DateTime.UtcNow) >= TimeSpan.FromDays(89), "Lockout be set to roughly 90 days");
                    }
                    else
                    {
                        Assert.AreEqual(userAccount.Email, null);
                        Assert.IsNull(userAccount.LockoutEnd, "Lockout should not be enabled");
                    }



                    //Make sure password is reset
                    var passwordAccess = userManager.Find(options.UserName, options.CurrentPassword);
                    Assert.IsNull(passwordAccess, "Can access user account with old password");
                }
                var badgeToCheck = String.IsNullOrEmpty(options.RecoveryEmailAddress) ? "deleted" : "deleted2";
                Assert.AreEqual(1, db.UserBadge.Count(x => x.UserName == options.UserName && x.BadgeID == badgeToCheck), "Can not find delete badge");

                //Verify Bio and Avatar cleared
                var prefs = db.UserPreference.Where(x => x.UserName.ToLower() == options.UserName.ToLower()).ToList();
                foreach (var pref in prefs)
                {
                    Assert.AreEqual(null, pref.Avatar, "Avatar not cleared");
                    Assert.AreEqual(null, pref.Bio, "Bio not cleared");
                }
            }
        }