Exemple #1
0
        public void CheckAsync_should_identify_dangerous_urls()
        {
            // Arrange
            var sut = new SimpleRegexUrlChecker(new[]
            {
                @"^.*jpe082ver\.info.*$",
                @"^.*ntfl-promo2017.info.*$"
            });
            var url1 = "http://www.jpe082ver.info/test";
            var url2 = "https://antfl-promo2017.info";

            // Act
            var result1 = sut.CheckAsync(url1).Result;

            // Assert
            Assert.AreEqual(url1, result1.Url);
            Assert.AreEqual(ThreatType.Unknow, result1.ThreatType);
            Assert.IsFalse(result1.IsSafe);

            // Act
            var result2 = sut.CheckAsync(url2).Result;

            // Assert
            Assert.AreEqual(url2, result2.Url);
            Assert.AreEqual(ThreatType.Unknow, result2.ThreatType);
            Assert.IsFalse(result2.IsSafe);
        }
Exemple #2
0
        public void SimpleRegexRulesHttpUpdater_should_update_rules_reading_remote_file_real_request()
        {
            // Arrange
            var realUrl = "https://raw.githubusercontent.com/MakingSense/safe-browsing/resources/links-blacklist.txt";
            var rules   = new SimpleRegexRules();
            var sut     = new SimpleRegexRulesHttpUpdater(realUrl, rules);

            Assert.IsFalse(rules.Blacklist.Any());

            // Act
            sut.UpdateAsync().Wait();

            // Assert
            Assert.IsTrue(rules.Blacklist.Any());
        }
Exemple #3
0
        public void SimpleRegexUrlChecker_should_respond_to_rules_updating()
        {
            // Arrange
            var rules = new SimpleRegexRules();
            var sut   = new SimpleRegexUrlChecker(rules);
            var url   = "http://www.jpe082ver.info/test";

            Assert.IsTrue(sut.Check(url).IsSafe);

            // Act
            rules.Update(new[] { new Regex(@"^.*jpe082ver\.info.*$") });
            var result = sut.Check(url);

            // Assert
            Assert.AreEqual(url, result.Url);
            Assert.AreEqual(ThreatType.Unknow, result.ThreatType);
            Assert.IsFalse(result.IsSafe);
        }
Exemple #4
0
        public void SimpleRegexRulesHttpUpdater_should_read_all_remote_lines()
        {
            // Arrange
            var anyUrl     = "http://example.com/links-blacklist.txt";
            var httpClient = new HttpClientDouble();

            httpClient.Setup_GetString("0\r\n  1  \n2\r\n3");
            var sut = new SimpleRegexRulesHttpUpdater(anyUrl, httpClient);

            Assert.IsFalse(sut.Rules.Blacklist.Any());

            // Act
            sut.UpdateAsync().Wait();

            // Assert
            Assert.IsTrue(sut.Rules.Blacklist.Any());
            Assert.AreEqual(4, sut.Rules.Blacklist.Count);
            Assert.AreEqual("0", sut.Rules.Blacklist[0].ToString());
            Assert.AreEqual("1", sut.Rules.Blacklist[1].ToString());
            Assert.AreEqual("2", sut.Rules.Blacklist[2].ToString());
            Assert.AreEqual("3", sut.Rules.Blacklist[3].ToString());
        }