Exemplo n.º 1
0
        public void TestBasicFilterMatch()
        {
            IEnumerable <FilterMatch> result = null;

            result = FilterUtility.Match("Test Data");
            Assert.IsFalse(result.Any());

            result = FilterUtility.Match("I have this new site, check it: evildomain.evil. Tell me if you like it");
            Assert.IsTrue(result.Any());
            Assert.AreEqual(2, result.First().Filter.ID);

            //Test casing
            result = FilterUtility.Match("I have this new site, check it: EVilDOmAiN.evIL. Tell me if you like it");
            Assert.IsTrue(result.Any());
            Assert.AreEqual(2, result.First().Filter.ID);

            var multipleViolations = "Check out my super awesome content [https://www.google.com/some-made-up-markdown-url/](https://www.google.com/url?q=http%3A%2F%2Fwww.evildomain.evil%2F%3Ftrack%3Dvoat%26keyword%3Dsome%2Bkey%2Bword%26charset%3Dutf-8). Do you like?";

            //should return only first match
            result = FilterUtility.Match(multipleViolations);
            Assert.IsTrue(result.Any());
            Assert.AreEqual(3, result.First().Filter.ID);

            //see if match all returns both violations
            result = FilterUtility.Match(multipleViolations, true);
            Assert.AreEqual(2, result.Count());
        }
Exemplo n.º 2
0
        public void TestBadData()
        {
            IEnumerable <FilterMatch> result = null;

            result = FilterUtility.Match("");
            Assert.IsFalse(result.Any());

            result = FilterUtility.Match(null);
            Assert.IsFalse(result.Any());
        }
Exemplo n.º 3
0
        protected override RuleOutcome EvaluateRule(VoatRuleContext context)
        {
            UserSubmission submission = context.PropertyBag.UserSubmission;

            //Check if content matches spam filters
            IEnumerable <FilterMatch> result = null;

            switch (submission.Type)
            {
            case SubmissionType.Link:
                result = FilterUtility.Match(String.Concat(submission.Title, " ", submission.Url));
                break;

            case SubmissionType.Text:
                result = FilterUtility.Match(String.Concat(submission.Title, " ", submission.Content));
                break;
            }
            if (result.Any())
            {
                return(CreateOutcome(RuleResult.Denied, $"Submission does not pass filter: {result.First().Filter.Name}"));
            }

            return(Allowed);
        }