示例#1
0
        public static void VerifyCIDR(this SubnetDirectory <string> directory, string cidr, string tag)
        {
            var tokens = cidr.Split('/');

            Assert.Equal(2, tokens.Length);
            var ip     = IPAddress.Parse(tokens[0]);
            var length = int.Parse(tokens[1]);

            Assert.Equal(tokens[0], ip.ToString());
            var claims = IPAssertions.FromPrefix(tag, ip, length);

            directory.AssertClaims(claims);
        }
示例#2
0
        public async Task CreateSubnetDirectory_AndTestIPs()
        {
            var sources = new SourceDefinition[] {
                new SourceDefinition {
                    Schema     = SchemaAwsIPRangesFromFile,
                    Parameters = new Dictionary <string, object>()
                    {
                        { "Tag", "aws" },
                        { "File", GlobFor("aws-ip-ranges*.json") },
                    }
                },
                new SourceDefinition {
                    Schema     = SchemaAzureIPRangesFromFile,
                    Parameters = new Dictionary <string, object>()
                    {
                        { "Tag", "azure" },
                        { "File", GlobFor("ServiceTags_Public*.json") },
                    }
                },
                new SourceDefinition {
                    Schema     = SchemaIPPrefixesListFromFile,
                    Parameters = new Dictionary <string, object>()
                    {
                        { "Tag", "gcp" },
                        { "File", GlobFor("gcp-ip-ranges*.txt") },
                    }
                },
            };
            var otherRules = IPAssertions.Of(null, "0.0.0.0", "1.1.1.1", "255.255.255.255", "127.0.0.1", "8.34.0.0", "8.34.205.12", "34.101.0.0", "34.23.0.0", "8.34.255.255");
            var directory  = new SubnetDirectory <string>();

            foreach (var source in sources)
            {
                await _parsers[source.Schema](source.Parameters, (cidr, tag) => directory.TryAddSubnet(cidr, tag, out var unused));
            }
            if (directory.Lookup is IntPrefixTree <string> )
            {
                var lookup = directory.Lookup as IntPrefixTree <string>;
                AssertTreeStructureCorrectness(lookup.Root);
            }
            var sw = new Stopwatch();

            sw.Start();
            foreach (var source in sources)
            {
                await _parsers[source.Schema](source.Parameters, (cidr, tag) => directory.VerifyCIDR(cidr, tag));
            }
            directory.AssertClaims(otherRules);
            sw.Stop();
            _output.WriteLine($"Checked {RowCounts} rows, time elapsed: {sw.ElapsedMilliseconds}");
        }