storj/satellite/geoip/maxmind_test.go
Márton Elek ceb7b7375c satellite/geoip: exclude nodes with represented_contry from geofencing
Change-Id: I80b8e5d98f46559b158a26c47fff0586b97aff79
2023-08-14 12:36:33 +00:00

60 lines
1.2 KiB
Go

// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information
package geoip
import (
"os"
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/storj/location"
)
func TestToCountryCode(t *testing.T) {
require.Equal(t, location.Germany, toCountryCode(&ipInfo{
Country: country{
IsoCode: "DE",
},
}))
require.Equal(t, location.Germany, toCountryCode(&ipInfo{
Country: country{
IsoCode: "DE",
},
RepresentedCountry: country{
IsoCode: "DE",
},
}))
require.Equal(t, location.None, toCountryCode(&ipInfo{
Country: country{
IsoCode: "DE",
},
RepresentedCountry: country{
IsoCode: "US",
},
}))
}
func TestMaxmind(t *testing.T) {
maxmindDB := os.Getenv("TEST_MAXMIND_DB")
if maxmindDB == "" {
t.Skip("Optional test")
}
db, err := OpenMaxmindDB(maxmindDB)
require.NoError(t, err)
// these assertions are based on the db from 2023-08-04. Can be different with different DB.
code, err := db.LookupISOCountryCode("62.112.192.4:80")
require.NoError(t, err)
require.Equal(t, location.Hungary, code)
code, err = db.LookupISOCountryCode("178.76.189.106:28967")
require.NoError(t, err)
require.Equal(t, location.None, code)
}