public void Parse_SingleIPv6()
        {
            string input = "::1";

            var whitelist = Whitelist.Parse(input);

            Assert.IsTrue(whitelist.Match(IPAddress.Parse("::1")));
        }
        public void Parse_NoPartialMatch()
        {
            string input = "ocalhos";

            var whitelist = Whitelist.Parse(input);

            Assert.IsFalse(whitelist.Match(IPAddress.Parse("127.0.0.1")));
        }
        public void Parse_Empty()
        {
            string input = "";

            var whitelist = Whitelist.Parse(input);

            Assert.IsFalse(whitelist.Match(IPAddress.Parse("127.0.0.1")));
        }
        public void Parse_IpGlob()
        {
            string input = "127.0.0.*";

            var whitelist = Whitelist.Parse(input);

            Assert.IsTrue(whitelist.Match(IPAddress.Parse("127.0.0.1")));
        }
        public void Parse_NoRegex()
        {
            string input = "[^\\.]+.google";

            var whitelist = Whitelist.Parse(input);

            Assert.IsFalse(whitelist.Match(IPAddress.Parse("8.8.8.8")));
        }
        public void Parse_TrailingComment()
        {
            string input = "127.0.0.1 # Allow localhost";

            var whitelist = Whitelist.Parse(input);

            Assert.IsTrue(whitelist.Match(IPAddress.Parse("127.0.0.1")));
        }
        public void Parse_Glob()
        {
            string input = "*.google";

            var whitelist = Whitelist.Parse(input);

            Assert.IsTrue(whitelist.Match(IPAddress.Parse("8.8.8.8")));
        }
        public void Parse_Whitespace()
        {
            string input = "\n \t 127.0.0.1 \t \n";

            var whitelist = Whitelist.Parse(input);

            Assert.IsTrue(whitelist.Match(IPAddress.Parse("127.0.0.1")));
        }
        public void Parse_Duplicate()
        {
            string input = "127.0.0.1\n127.0.0.1";

            var whitelist = Whitelist.Parse(input);

            Assert.IsTrue(whitelist.Match(IPAddress.Parse("127.0.0.1")));
        }
        public void Parse_WindowsNewlines()
        {
            string input = "127.0.0.1\r\n127.0.0.2";

            var whitelist = Whitelist.Parse(input);

            Assert.IsTrue(whitelist.Match(IPAddress.Parse("127.0.0.1")));
            Assert.IsTrue(whitelist.Match(IPAddress.Parse("127.0.0.2")));
        }
        public async Task UseWhitelist_NoMatch()
        {
            var whitelist = Whitelist.Parse("");

            var builder = new WebHostBuilder().Configure(app =>
            {
                app.UseWhitelist(async() => whitelist);
            });

            using (var server = new TestServer(builder))
            {
                var context = await server.SendAsync(spoofIp);

                Assert.AreEqual(403, context.Response.StatusCode);
            }
        }
        public async Task UseWhitelist_Repeated()
        {
            int count = 0;

            var whitelist = Whitelist.Parse("");

            var builder = new WebHostBuilder().Configure(app =>
            {
                app.UseWhitelist(async() =>
                {
                    count++;
                    return(whitelist);
                });
            });

            using (var server = new TestServer(builder))
            {
                await server.SendAsync(spoofIp);

                await server.SendAsync(spoofIp);
            }

            Assert.AreEqual(2, count);
        }