diff --git a/testing/btest/Files/mmdb/.gitignore b/testing/btest/Files/mmdb/.gitignore new file mode 100644 index 0000000000..b4daca1937 --- /dev/null +++ b/testing/btest/Files/mmdb/.gitignore @@ -0,0 +1 @@ +testmmdb diff --git a/testing/btest/Files/mmdb/GeoLite2-ASN.mmdb b/testing/btest/Files/mmdb/GeoLite2-ASN.mmdb new file mode 100644 index 0000000000..65ade5917e Binary files /dev/null and b/testing/btest/Files/mmdb/GeoLite2-ASN.mmdb differ diff --git a/testing/btest/Files/mmdb/GeoLite2-City.mmdb b/testing/btest/Files/mmdb/GeoLite2-City.mmdb new file mode 100644 index 0000000000..2f375e3bd6 Binary files /dev/null and b/testing/btest/Files/mmdb/GeoLite2-City.mmdb differ diff --git a/testing/btest/Files/mmdb/README b/testing/btest/Files/mmdb/README new file mode 100644 index 0000000000..269a36c045 --- /dev/null +++ b/testing/btest/Files/mmdb/README @@ -0,0 +1,13 @@ +These .mmdb databases were created with the mmdbwriter from MaxMind [1] for +testing purposes. See the main.go file. They only contain information about +LBL's network ranges: + + 128.3.0.0/16 + 131.243.0.0/16 + +Rebuild with: + + go build + ./testmmdb + +[1] https://github.com/maxmind/mmdbwriter diff --git a/testing/btest/Files/mmdb/go.mod b/testing/btest/Files/mmdb/go.mod new file mode 100644 index 0000000000..5aa1c9679c --- /dev/null +++ b/testing/btest/Files/mmdb/go.mod @@ -0,0 +1,11 @@ +module testmmdb + +go 1.21.0 + +require github.com/maxmind/mmdbwriter v1.0.0 + +require ( + github.com/oschwald/maxminddb-golang v1.12.0 // indirect + go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d // indirect + golang.org/x/sys v0.10.0 // indirect +) diff --git a/testing/btest/Files/mmdb/go.sum b/testing/btest/Files/mmdb/go.sum new file mode 100644 index 0000000000..a7e4aa9667 --- /dev/null +++ b/testing/btest/Files/mmdb/go.sum @@ -0,0 +1,16 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/maxmind/mmdbwriter v1.0.0 h1:bieL4P6yaYaHvbtLSwnKtEvScUKKD6jcKaLiTM3WSMw= +github.com/maxmind/mmdbwriter v1.0.0/go.mod h1:noBMCUtyN5PUQ4H8ikkOvGSHhzhLok51fON2hcrpKj8= +github.com/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs= +github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d h1:ggxwEf5eu0l8v+87VhX1czFh8zJul3hK16Gmruxn7hw= +go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d/go.mod h1:tgPU4N2u9RByaTN3NC2p9xOzyFpte4jYwsIIRF7XlSc= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/testing/btest/Files/mmdb/main.go b/testing/btest/Files/mmdb/main.go new file mode 100644 index 0000000000..ecad3ea8db --- /dev/null +++ b/testing/btest/Files/mmdb/main.go @@ -0,0 +1,71 @@ +// Create test MaxMind DB database files containing information about +// just LBL's IPv4 ranges for testing. +package main + +import ( + "log" + "net" + "os" + + "github.com/maxmind/mmdbwriter" + "github.com/maxmind/mmdbwriter/mmdbtype" +) + +func writeDb(fname, name string, record mmdbtype.Map, nets ...*net.IPNet) { + writer, err := mmdbwriter.New( + mmdbwriter.Options{ + DatabaseType: name, + }, + ) + if err != nil { + log.Fatal(err) + } + + for _, n := range nets { + if err = writer.Insert(n, record); err != nil { + log.Fatal(err) + } + } + + fh, err := os.Create(fname) + if err != nil { + log.Fatal(err) + } + defer fh.Close() + + _, err = writer.WriteTo(fh) + if err != nil { + log.Fatal(err) + } +} + +func main() { + _, net1, _ := net.ParseCIDR("128.3.0.0/16") + _, net2, _ := net.ParseCIDR("131.243.0.0/16") + + // The ASN record. + asn_record := mmdbtype.Map{} + asn_record["autonomous_system_number"] = mmdbtype.Uint32(16) + asn_record["autonomous_system_organization"] = mmdbtype.String("Lawrence Berkeley National Laboratory") + writeDb("GeoLite2-ASN.mmdb", "My-ASN-DB", asn_record, net1, net2) + + // The Location record. + loc_record := mmdbtype.Map{ + "country": mmdbtype.Map{ + "iso_code": mmdbtype.String("US"), + "names": mmdbtype.Map{ + "en": mmdbtype.String("United States"), + }, + }, + "location": mmdbtype.Map{ + "latitude": mmdbtype.Float64(37.75100), + "longitude": mmdbtype.Float64(-97.822000), + }, + "city": mmdbtype.Map{ + "names": mmdbtype.Map{ + "en": mmdbtype.String("Berkeley"), + }, + }, + } + writeDb("GeoLite2-City.mmdb", "My-City-DB", loc_record, net1, net2) +}