mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-07 05:59:06 +02:00
Merge remote-tracking branch 'origin/revert/component-types' into revert/component-types
This commit is contained in:
@@ -30,12 +30,17 @@ func TestGetPostureChecks(t *testing.T) {
|
|||||||
"GeoLocationCheck":{"Locations":[{"CountryCode":"US","CityName":"Harker Heights"}],"Action":"allow"},
|
"GeoLocationCheck":{"Locations":[{"CountryCode":"US","CityName":"Harker Heights"}],"Action":"allow"},
|
||||||
"PeerNetworkRangeCheck":{"Action":"allow","Ranges":["0.0.0.0/0"]}}')`)
|
"PeerNetworkRangeCheck":{"Action":"allow","Ranges":["0.0.0.0/0"]}}')`)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
_, err = pgstore.Pool.Query(ctx,
|
||||||
|
`insert into posture_checks (id, account_id, public_id, checks)
|
||||||
|
VALUES('posturecheck-3','account-1','posturecheck-3-public', null)`)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
postureChecks, idToPublicIDIdx, err := networkmap_pgsql.GetPostureChecksViaPgxConnection(ctx, conn(t, ctx), "account-1")
|
postureChecks, idToPublicIDIdx, err := networkmap_pgsql.GetPostureChecksViaPgxConnection(ctx, conn(t, ctx), "account-1")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, idToPublicIDIdx, map[string]string{
|
assert.Equal(t, idToPublicIDIdx, map[string]string{
|
||||||
"posturecheck-1": "posturecheck-1-public",
|
"posturecheck-1": "posturecheck-1-public",
|
||||||
"posturecheck-2": "posturecheck-2-public",
|
"posturecheck-2": "posturecheck-2-public",
|
||||||
|
"posturecheck-3": "posturecheck-3-public",
|
||||||
})
|
})
|
||||||
assert.Contains(t, postureChecks, nmdata.PostureChecks{
|
assert.Contains(t, postureChecks, nmdata.PostureChecks{
|
||||||
ID: "posturecheck-1",
|
ID: "posturecheck-1",
|
||||||
@@ -53,4 +58,6 @@ func TestGetPostureChecks(t *testing.T) {
|
|||||||
GeoLocationCheck: &nmdata.GeoLocationCheck{Locations: []nmdata.GeoLocation{{CountryCode: "US", CityName: "Harker Heights"}}, Action: "allow"},
|
GeoLocationCheck: &nmdata.GeoLocationCheck{Locations: []nmdata.GeoLocation{{CountryCode: "US", CityName: "Harker Heights"}}, Action: "allow"},
|
||||||
PeerNetworkRangeCheck: &nmdata.PeerNetworkRangeCheck{Action: "allow", Ranges: []netip.Prefix{netip.MustParsePrefix("0.0.0.0/0")}},
|
PeerNetworkRangeCheck: &nmdata.PeerNetworkRangeCheck{Action: "allow", Ranges: []netip.Prefix{netip.MustParsePrefix("0.0.0.0/0")}},
|
||||||
}})
|
}})
|
||||||
|
assert.Contains(t, postureChecks, nmdata.PostureChecks{
|
||||||
|
ID: "posturecheck-3"})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package networkmap_pgsql
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/netip"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
networkmap_pgsql "github.com/netbirdio/netbird/management/internals/network_map_db/pgsql"
|
||||||
|
"github.com/netbirdio/netbird/shared/management/domain"
|
||||||
|
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetRoutes(t *testing.T) {
|
||||||
|
ctx := context.TODO()
|
||||||
|
|
||||||
|
_, err := pgstore.Pool.Query(ctx,
|
||||||
|
`insert into routes (id, account_id, public_id, network, domains, keep_route, net_id, description,
|
||||||
|
peer, peer_groups, network_type, masquerade, metric, enabled,
|
||||||
|
groups, access_control_groups, skip_auto_apply)
|
||||||
|
VALUES('route-1','account-1','route-1-public','"172.0.0.0/16"','["test-1.com"]',true,'route-1-net-id','route-1',
|
||||||
|
'peer-id-1','["group-one-resource-id"]',1,true,9999,true,
|
||||||
|
'["group-one-resource-id"]','["group-one-resource-id"]',false)`)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
_, err = pgstore.Pool.Query(ctx,
|
||||||
|
`insert into routes (id, account_id, public_id, network, domains, keep_route, net_id, description,
|
||||||
|
peer, peer_groups, network_type, masquerade, metric, enabled,
|
||||||
|
groups, access_control_groups, skip_auto_apply)
|
||||||
|
VALUES('route-2','account-1','route-2-public','"172.10.0.0/16"','["test-1.com","test-2.com"]',true,'route-2-net-id','route-2',
|
||||||
|
'peer-id-2','["group-two-resources-id"]',1,true,9999,true,
|
||||||
|
'["group-two-resources-id"]','["group-two-resources-id"]',false)`)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
_, err = pgstore.Pool.Query(ctx,
|
||||||
|
`insert into routes (id, account_id, public_id, network, domains, keep_route, net_id, description,
|
||||||
|
peer, peer_groups, network_type, masquerade, metric, enabled,
|
||||||
|
groups, access_control_groups, skip_auto_apply)
|
||||||
|
VALUES('route-3','account-1','route-3-public',null,null,null,null,'route-3',
|
||||||
|
null,null,null,null,null,null,null,null,null)`)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
routes, err := networkmap_pgsql.GetRoutesViaPgxConnection(ctx, conn(t, ctx), "account-1")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Contains(t, routes, nmdata.Route{
|
||||||
|
ID: "route-1",
|
||||||
|
AccountID: "account-1",
|
||||||
|
PublicID: "route-1-public",
|
||||||
|
Network: netip.MustParsePrefix("172.0.0.0/16"),
|
||||||
|
Domains: domain.List{"test-1.com"},
|
||||||
|
KeepRoute: true,
|
||||||
|
NetID: "route-1-net-id",
|
||||||
|
Description: "route-1",
|
||||||
|
Peer: "peer-id-1",
|
||||||
|
PeerID: "peer-id-1",
|
||||||
|
PeerGroups: []string{"group-one-resource-id"},
|
||||||
|
NetworkType: 1,
|
||||||
|
Masquerade: true,
|
||||||
|
Metric: 9999,
|
||||||
|
Enabled: true,
|
||||||
|
Groups: []string{"group-one-resource-id"},
|
||||||
|
AccessControlGroups: []string{"group-one-resource-id"},
|
||||||
|
SkipAutoApply: false,
|
||||||
|
})
|
||||||
|
assert.Contains(t, routes, nmdata.Route{
|
||||||
|
ID: "route-2",
|
||||||
|
AccountID: "account-1",
|
||||||
|
PublicID: "route-2-public",
|
||||||
|
Network: netip.MustParsePrefix("172.10.0.0/16"),
|
||||||
|
Domains: domain.List{"test-1.com", "test-2.com"},
|
||||||
|
KeepRoute: true,
|
||||||
|
NetID: "route-2-net-id",
|
||||||
|
Description: "route-2",
|
||||||
|
Peer: "peer-id-2",
|
||||||
|
PeerID: "peer-id-2",
|
||||||
|
PeerGroups: []string{"group-two-resources-id"},
|
||||||
|
NetworkType: 1,
|
||||||
|
Masquerade: true,
|
||||||
|
Metric: 9999,
|
||||||
|
Enabled: true,
|
||||||
|
Groups: []string{"group-two-resources-id"},
|
||||||
|
AccessControlGroups: []string{"group-two-resources-id"},
|
||||||
|
SkipAutoApply: false,
|
||||||
|
})
|
||||||
|
assert.Contains(t, routes, nmdata.Route{
|
||||||
|
ID: "route-3",
|
||||||
|
AccountID: "account-1",
|
||||||
|
PublicID: "route-3-public",
|
||||||
|
Description: "route-3",
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user