Esempio n. 1
0
        public void TestStart()
        {
            firewall = IPBanFirewallUtility.CreateFirewall(firewallAndOsType, "IPBanTest_");

            // clear all blocks
            firewall.BlockIPAddresses(new string[0]).Sync();
        }
Esempio n. 2
0
        public void TestStart()
        {
            firewall = IPBanFirewallUtility.CreateFirewall();
            Assert.AreNotEqual(typeof(IPBanMemoryFirewall), firewall.GetType());

            // clear all blocks
            firewall.Truncate();
        }
Esempio n. 3
0
 public void TestParseIP()
 {
     Assert.IsTrue(IPBanFirewallUtility.TryNormalizeIPAddress("1.1.1.1", out _));
     Assert.IsTrue(IPBanFirewallUtility.TryNormalizeIPAddress("1.1.1.1:8080", out _));
     Assert.IsTrue(IPBanFirewallUtility.TryNormalizeIPAddress("1.1.1.1/24", out _)); // fe80::c872:be03:5c94:4af2%8
     Assert.IsTrue(IPBanFirewallUtility.TryNormalizeIPAddress("fe80::c872:be03:5c94:4af2%8", out _));
     Assert.IsFalse(IPBanFirewallUtility.TryNormalizeIPAddress("a.1.1.1", out _));
 }
Esempio n. 4
0
        public void TestIPV4Conversion()
        {
            uint value = IPBanFirewallUtility.ParseIPV4("192.168.1.123");

            Assert.AreEqual(0xc0a8017b, value, "ParseIPV4 fail");
            string ip = value.ToIPAddress().ToString();

            Assert.AreEqual("192.168.1.123", ip, "IPV4ToString fail");
            value = IPBanFirewallUtility.ParseIPV4("192.168.0.0/24");
            Assert.AreEqual(0xc0a80000, value, "ParseIPV4 fail");
            ip = value.ToIPAddress().ToString();
            Assert.AreEqual("192.168.0.0", ip, "IPV4ToString fail");
        }
Esempio n. 5
0
        public void TestIPV4Conversion()
        {
            uint value = IPBanFirewallUtility.ParseIPV4("192.168.1.123");

            Assert.AreEqual(0x7b01a8c0, value, "ParseIPV4 fail");
            string ip = IPBanFirewallUtility.IPV4ToString(value);

            Assert.AreEqual("192.168.1.123", ip, "IPV4ToString fail");
            value = IPBanFirewallUtility.ParseIPV4("192.168.0.0/24");
            Assert.AreEqual(0x0000a8c0, value, "ParseIPV4 fail");
            ip = IPBanFirewallUtility.IPV4ToString(value);
            Assert.AreEqual("192.168.0.0", ip, "IPV4ToString fail");
        }
Esempio n. 6
0
        private static void TestFilterIPAddressRangesHelper(IPAddressRange[] expected, string message, IPAddressRange[] filter, params IPAddressRange[] ranges)
        {
            int index = 0;

            foreach (IPAddressRange range in IPBanFirewallUtility.FilterRanges(ranges, filter))
            {
                if (index >= expected.Length)
                {
                    Assert.Fail("Too many filtered results, expected max count of {0}", expected.Length - 1);
                }

                // nunit areequal is strange, it calls enumerators and other crap, why it doesn't just do .Equals is beyond me...
                IPAddressRange existing = expected[index++];
                IPAddressRange actual   = range;
                Assert.That(existing.Equals(actual), message);
            }
        }
Esempio n. 7
0
 public void TestIPV6()
 {
     string[] toBlock = new string[] { "fe80::c872:be03:5c94:4af2%8", "192.168.0.20" };
     firewall.BlockIPAddresses(null, toBlock).Sync();
     string[] bannedIP  = firewall.EnumerateBannedIPAddresses().ToArray();
     string[] bannedIP2 = firewall.EnumerateIPAddresses().Select(i => i.Begin.ToString()).ToArray();
     Assert.AreEqual(bannedIP.Length, bannedIP2.Length);
     for (int i = 0; i < bannedIP.Length; i++)
     {
         Assert.AreEqual(bannedIP[i], bannedIP2[i]);
     }
     foreach (string origIP in toBlock)
     {
         if (IPBanFirewallUtility.TryGetFirewallIPAddress(origIP, out string normalizedIP))
         {
             Assert.IsTrue(bannedIP.Contains(normalizedIP));
         }
         else
         {
             Assert.Fail("Bad ip: " + origIP);
         }
     }
 }
Esempio n. 8
0
        private static void TestPortRangeAllow(string expected, string message, params PortRange[] ranges)
        {
            string actual = IPBanFirewallUtility.GetPortRangeStringAllow(ranges);

            Assert.AreEqual(expected, actual, message ?? "Invalid port string");
        }