mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-09 07:15:15 +02:00
Add initial support of device posture checks (#1540)
This PR implements the following posture checks: * Agent minimum version allowed * OS minimum version allowed * Geo-location based on connection IP For the geo-based location, we rely on GeoLite2 databases which are free IP geolocation databases. MaxMind was tested and we provide a script that easily allows to download of all necessary files, see infrastructure_files/download-geolite2.sh. The OpenAPI spec should extensively cover the life cycle of current version posture checks.
This commit is contained in:
55
management/server/geolocation/geolocation_test.go
Normal file
55
management/server/geolocation/geolocation_test.go
Normal file
@ -0,0 +1,55 @@
|
||||
package geolocation
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/netbirdio/netbird/util"
|
||||
)
|
||||
|
||||
// from https://github.com/maxmind/MaxMind-DB/blob/main/test-data/GeoLite2-City-Test.mmdb
|
||||
var mmdbPath = "../testdata/GeoLite2-City-Test.mmdb"
|
||||
|
||||
func TestGeoLite_Lookup(t *testing.T) {
|
||||
tempDir := t.TempDir()
|
||||
filename := path.Join(tempDir, MMDBFileName)
|
||||
err := util.CopyFileContents(mmdbPath, filename)
|
||||
assert.NoError(t, err)
|
||||
defer func() {
|
||||
err := os.Remove(filename)
|
||||
if err != nil {
|
||||
t.Errorf("os.Remove: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
db, err := openDB(mmdbPath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
geo := &Geolocation{
|
||||
mux: sync.RWMutex{},
|
||||
db: db,
|
||||
stopCh: make(chan struct{}),
|
||||
}
|
||||
assert.NotNil(t, geo)
|
||||
defer func() {
|
||||
err = geo.Stop()
|
||||
if err != nil {
|
||||
t.Errorf("geo.Stop: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
record, err := geo.Lookup(net.ParseIP("89.160.20.128"))
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, record)
|
||||
assert.Equal(t, "SE", record.Country.ISOCode)
|
||||
assert.Equal(t, uint(2661886), record.Country.GeonameID)
|
||||
assert.Equal(t, "Linköping", record.City.Names.En)
|
||||
assert.Equal(t, uint(2694762), record.City.GeonameID)
|
||||
assert.Equal(t, "EU", record.Continent.Code)
|
||||
assert.Equal(t, uint(6255148), record.Continent.GeonameID)
|
||||
}
|
Reference in New Issue
Block a user