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); }
public void Check_should_identify_safe_urls() { // Arrange var sut = new SimpleRegexUrlChecker(new[] { @"^.*jpe082ver\.info.*$", @"^.*ntfl-promo2017\.info.*$" }); var url = "http://www.safe.info/test"; // Act var result = sut.Check(url); // Assert Assert.AreEqual(url, result.Url); Assert.IsTrue(result.IsSafe); Assert.AreEqual(ThreatType.NoThreat, result.ThreatType); }
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); }