Пример #1
0
        public void TestIpv4DefaultRoute()
        {
            var rule = new IPSubnetFilterRule("0.0.0.0", 0, IPFilterRuleType.Accept);

            Assert.True(rule.Matches(CreateIPEndPoint("91.114.240.43")));
            Assert.True(rule.Matches(CreateIPEndPoint("10.0.0.3")));
            Assert.True(rule.Matches(CreateIPEndPoint("192.168.93.2")));
        }
Пример #2
0
        public void TestIp4SubnetFilterRule()
        {
            var rule = new IPSubnetFilterRule("192.168.56.1", 24, IPFilterRuleType.Accept);

            for (int i = 0; i <= 255; i++)
            {
                Assert.True(rule.Matches(CreateIPEndPoint(string.Format("192.168.56.{0}", i))));
            }
            Assert.False(rule.Matches(CreateIPEndPoint("192.168.57.1")));

            rule = new IPSubnetFilterRule("91.114.240.1", 23, IPFilterRuleType.Accept);
            Assert.True(rule.Matches(CreateIPEndPoint("91.114.240.43")));
            Assert.True(rule.Matches(CreateIPEndPoint("91.114.240.255")));
            Assert.True(rule.Matches(CreateIPEndPoint("91.114.241.193")));
            Assert.True(rule.Matches(CreateIPEndPoint("91.114.241.254")));
            Assert.False(rule.Matches(CreateIPEndPoint("91.115.241.2")));
        }
Пример #3
0
        public void TestIp6SubnetFilterRule()
        {
            var rule = new IPSubnetFilterRule("2001:db8:abcd:0000::", 52, IPFilterRuleType.Accept);

            Assert.True(rule.RuleType == IPFilterRuleType.Accept);
            Assert.True(rule.Matches(CreateIPEndPoint("2001:db8:abcd:0000::1")));
            Assert.True(rule.Matches(CreateIPEndPoint("2001:db8:abcd:0fff:ffff:ffff:ffff:ffff")));
            Assert.False(rule.Matches(CreateIPEndPoint("2001:db8:abcd:1000::")));


            rule = new IPSubnetFilterRule("2001:db8:1234:c000::", 50, IPFilterRuleType.Reject);
            Assert.True(rule.RuleType == IPFilterRuleType.Reject);
            Assert.True(rule.Matches(CreateIPEndPoint("2001:db8:1234:c000::")));
            Assert.True(rule.Matches(CreateIPEndPoint("2001:db8:1234:ffff:ffff:ffff:1111:ffff")));
            Assert.True(rule.Matches(CreateIPEndPoint("2001:db8:1234:ffff:ffff:ffff:ffff:ffff")));
            Assert.False(rule.Matches(CreateIPEndPoint("2001:db8:1234:bfff:ffff:ffff:ffff:ffff")));
            Assert.False(rule.Matches(CreateIPEndPoint("2001:db8:1234:8000::")));
            Assert.False(rule.Matches(CreateIPEndPoint("2001:db7:1234:c000::")));
        }
Пример #4
0
        public void TestIpv6SubnetMaskCorrectlyHandlesIpv4()
        {
            var rule = new IPSubnetFilterRule("::", 0, IPFilterRuleType.Accept);

            Assert.False(rule.Matches(CreateIPEndPoint("91.114.240.43")));
        }
Пример #5
0
        public void TestIpv4SubnetMaskCorrectlyHandlesIpv6()
        {
            var rule = new IPSubnetFilterRule("0.0.0.0", 0, IPFilterRuleType.Accept);

            Assert.False(rule.Matches(CreateIPEndPoint("2001:db8:abcd:0000::1")));
        }