mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 09:47:49 +02:00
test windows
This commit is contained in:
parent
f45eb1a1da
commit
b5d8142705
@ -163,8 +163,6 @@ func TestAddExistAndRemoveRouteNonAndroid(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// MOCK_ADDR := "127.0.0.1"
|
|
||||||
|
|
||||||
for n, testCase := range testCases {
|
for n, testCase := range testCases {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
log.SetOutput(&buf)
|
log.SetOutput(&buf)
|
||||||
@ -183,16 +181,16 @@ func TestAddExistAndRemoveRouteNonAndroid(t *testing.T) {
|
|||||||
err = wgInterface.Create()
|
err = wgInterface.Create()
|
||||||
require.NoError(t, err, "should create testing wireguard interface")
|
require.NoError(t, err, "should create testing wireguard interface")
|
||||||
|
|
||||||
MOCK_ADDR := wgInterface.Address().IP.String()
|
MockAddr := wgInterface.Address().IP.String()
|
||||||
|
|
||||||
// Prepare the environment
|
// Prepare the environment
|
||||||
if testCase.preExistingPrefix.IsValid() {
|
if testCase.preExistingPrefix.IsValid() {
|
||||||
err := addToRouteTableIfNoExists(testCase.preExistingPrefix, MOCK_ADDR)
|
err := addToRouteTableIfNoExists(testCase.preExistingPrefix, MockAddr)
|
||||||
require.NoError(t, err, "should not return err when adding pre-existing route")
|
require.NoError(t, err, "should not return err when adding pre-existing route")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the route
|
// Add the route
|
||||||
err = addToRouteTableIfNoExists(testCase.prefix, MOCK_ADDR)
|
err = addToRouteTableIfNoExists(testCase.prefix, MockAddr)
|
||||||
require.NoError(t, err, "should not return err when adding route")
|
require.NoError(t, err, "should not return err when adding route")
|
||||||
|
|
||||||
if testCase.shouldAddRoute {
|
if testCase.shouldAddRoute {
|
||||||
@ -202,7 +200,7 @@ func TestAddExistAndRemoveRouteNonAndroid(t *testing.T) {
|
|||||||
require.True(t, ok, "route should exist")
|
require.True(t, ok, "route should exist")
|
||||||
|
|
||||||
// remove route again if added
|
// remove route again if added
|
||||||
err = removeFromRouteTableIfNonSystem(testCase.prefix, MOCK_ADDR)
|
err = removeFromRouteTableIfNonSystem(testCase.prefix, MockAddr)
|
||||||
require.NoError(t, err, "should not return err")
|
require.NoError(t, err, "should not return err")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
package routemanager
|
package routemanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
|
||||||
@ -14,12 +13,11 @@ import (
|
|||||||
type Win32_IP4RouteTable struct {
|
type Win32_IP4RouteTable struct {
|
||||||
Destination string
|
Destination string
|
||||||
Mask string
|
Mask string
|
||||||
NextHop string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func existsInRouteTable(prefix netip.Prefix) (bool, error) {
|
func existsInRouteTable(prefix netip.Prefix) (bool, error) {
|
||||||
var routes []Win32_IP4RouteTable
|
var routes []Win32_IP4RouteTable
|
||||||
query := "SELECT Destination, Mask, NextHop FROM Win32_IP4RouteTable"
|
query := "SELECT Destination, Mask FROM Win32_IP4RouteTable"
|
||||||
|
|
||||||
err := wmi.Query(query, &routes)
|
err := wmi.Query(query, &routes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -27,12 +25,11 @@ func existsInRouteTable(prefix netip.Prefix) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
fmt.Println(routes)
|
|
||||||
ip := net.ParseIP(route.Mask)
|
ip := net.ParseIP(route.Mask)
|
||||||
ip = ip.To4()
|
ip = ip.To4()
|
||||||
mask := net.IPv4Mask(ip[0], ip[1], ip[2], ip[3])
|
mask := net.IPv4Mask(ip[0], ip[1], ip[2], ip[3])
|
||||||
cidr, _ := mask.Size()
|
cidr, _ := mask.Size()
|
||||||
if route.Destination == prefix.Addr().String() && cidr == prefix.Bits() && false {
|
if route.Destination == prefix.Addr().String() && cidr == prefix.Bits() {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user