From 4ad1212acf86a1096b3608134730cd73efbff76c Mon Sep 17 00:00:00 2001 From: Vittorio Parrella Date: Wed, 25 Sep 2024 22:57:38 +0200 Subject: [PATCH] feature: force proxy preference on linux to false --- workers/client/client.go | 8 ++- workers/client/client_network_linux_test.go | 16 ++--- workers/client/client_test.go | 68 ++++++++++++++------- 3 files changed, 58 insertions(+), 34 deletions(-) diff --git a/workers/client/client.go b/workers/client/client.go index f8dd2bf..93ec509 100644 --- a/workers/client/client.go +++ b/workers/client/client.go @@ -276,9 +276,11 @@ func validateConfiguration() { configuration.AssertParamNumeric("auto-redirected interfaces", len(clientAdditional.RedirectedInterfaces), 0, 256) - if runtime.GOOS != "windows" { - logger.Info("Platform forced prefer_proxy to true\n") - configGeneral.PreferProxy = true + switch runtime.GOOS { + case "linux": + logger.Info("Platform forced prefer_proxy to false\n") + configGeneral.PreferProxy = false + break } // validation ok diff --git a/workers/client/client_network_linux_test.go b/workers/client/client_network_linux_test.go index d8a29a8..5e9ad37 100644 --- a/workers/client/client_network_linux_test.go +++ b/workers/client/client_network_linux_test.go @@ -100,7 +100,7 @@ func (s *ClientNetworkSuite) TestGetAddressPortFromHost_Invalid() { } func (s *ClientNetworkSuite) TestInitialCheckConnection_PreferProxy() { - s.T().Skipf("Proxy set on linux not implemented yet") + s.T().Skipf("Proxy set not supported on linux") return validateConfiguration() @@ -122,7 +122,7 @@ func (s *ClientNetworkSuite) TestInitialCheckConnection_PreferProxy() { } func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferDiverterKeepRedirect() { - s.T().Skipf("Proxy set on linux not implemented yet") + s.T().Skipf("Proxy set not supported on linux") return var calledInit = false @@ -148,7 +148,7 @@ func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferDiverterKeepRedirec } func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferDiverterSwitchToProxy() { - s.T().Skipf("Proxy set on linux not implemented yet") + s.T().Skipf("Proxy set not supported on linux") return var calledInit = false @@ -181,7 +181,7 @@ func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferDiverterSwitchToPro } func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferDiverterExhausted() { - s.T().Skipf("Proxy set on linux not implemented yet") + s.T().Skipf("Proxy set not supported on linux") return monkey.Patch(gateway.SetSystemProxy, func(active bool) { @@ -206,7 +206,7 @@ func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferDiverterExhausted() } func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferProxyKeepRedirect() { - s.T().Skipf("Proxy set on linux not implemented yet") + s.T().Skipf("Proxy set not supported on linux") return validateConfiguration() @@ -233,7 +233,7 @@ func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferProxyKeepRedirect() } func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferProxySwitchToProxy_OK() { - s.T().Skipf("Proxy set on linux not implemented yet") + s.T().Skipf("Proxy set not supported on linux") return validateConfiguration() @@ -263,7 +263,7 @@ func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferProxySwitchToProxy_ } func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferProxySwitchToProxy_Fail() { - s.T().Skipf("Proxy set on linux not implemented yet") + s.T().Skipf("Proxy set not supported on linux") return validateConfiguration() @@ -293,7 +293,7 @@ func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferProxySwitchToProxy_ } func (s *ClientNetworkSuite) TestFailedCheckConnection_PreferProxyExhausted() { - s.T().Skipf("Proxy set on linux not implemented yet") + s.T().Skipf("Proxy set not supported on linux") return validateConfiguration() diff --git a/workers/client/client_test.go b/workers/client/client_test.go index 0fc168e..5d72243 100644 --- a/workers/client/client_test.go +++ b/workers/client/client_test.go @@ -15,7 +15,6 @@ import ( "github.com/parvit/qpep/shared/configuration" "github.com/parvit/qpep/shared/errors" "github.com/parvit/qpep/shared/protocol" - "github.com/parvit/qpep/windivert" "github.com/parvit/qpep/workers/gateway" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" @@ -350,41 +349,45 @@ func (s *ClientSuite) TestStopProxy() { } func (s *ClientSuite) TestInitDiverter() { - if runtime.GOOS != "windows" { - assert.False(s.T(), initDiverter()) - return - } - monkey.Patch(windivert.InitializeWinDivertEngine, func(string, string, int, int, int, int64, []int) int { - return windivert.DIVERT_OK + redirected = false + monkey.Patch(gateway.SetConnectionDiverter, func(active bool, _ string, _ string, _ int, _ int, _ int, _ int64, _ []int) bool { + assert.True(s.T(), active) + redirected = true + return true }) assert.True(s.T(), initDiverter()) + assert.True(s.T(), redirected) } func (s *ClientSuite) TestInitDiverter_Fail() { - if runtime.GOOS != "windows" { - assert.False(s.T(), initDiverter()) - return - } - monkey.Patch(windivert.InitializeWinDivertEngine, func(string, string, int, int, int, int64, []int) int { - return windivert.DIVERT_ERROR_ALREADY_INIT + redirected = true + monkey.Patch(gateway.SetConnectionDiverter, func(active bool, _ string, _ string, _ int, _ int, _ int, _ int64, _ []int) bool { + assert.True(s.T(), active) + redirected = false + return false }) assert.False(s.T(), initDiverter()) + assert.False(s.T(), redirected) } func (s *ClientSuite) TestStopDiverter() { - if runtime.GOOS != "windows" { - assert.False(s.T(), initDiverter()) - return - } - monkey.Patch(windivert.CloseWinDivertEngine, func() int { - return windivert.DIVERT_OK + redirected = true + monkey.Patch(gateway.SetConnectionDiverter, func(active bool, _ string, _ string, _ int, _ int, _ int, _ int64, _ []int) bool { + assert.False(s.T(), active) + redirected = false + return false }) stopDiverter() assert.False(s.T(), redirected) } -func (s *ClientSuite) TestInitialCheckConnection() { - configuration.QPepConfig.General.PreferProxy = false +func (s *ClientSuite) TestInitialCheckConnection_Proxy() { + if runtime.GOOS == "linux" { + s.T().Skipf("Proxy set not supported on linux") + return + } + + configuration.QPepConfig.General.PreferProxy = true validateConfiguration() monkey.Patch(gateway.SetSystemProxy, func(active bool) { @@ -395,12 +398,31 @@ func (s *ClientSuite) TestInitialCheckConnection() { assert.False(s.T(), gateway.UsingProxy) initialCheckConnection() - assert.False(s.T(), gateway.UsingProxy) - assert.Nil(s.T(), gateway.ProxyAddress) + assert.True(s.T(), gateway.UsingProxy) + assert.NotNil(s.T(), gateway.ProxyAddress) + + assert.False(s.T(), redirected) +} + +func (s *ClientSuite) TestInitialCheckConnection_Diverter() { + configuration.QPepConfig.General.PreferProxy = false + validateConfiguration() + if runtime.GOOS == "linux" { + assert.False(s.T(), configuration.QPepConfig.General.PreferProxy) + } + + redirected = false + monkey.Patch(initDiverter, func() bool { + redirected = true + return true + }) + assert.False(s.T(), gateway.UsingProxy) initialCheckConnection() assert.False(s.T(), gateway.UsingProxy) assert.Nil(s.T(), gateway.ProxyAddress) + + assert.True(s.T(), redirected) } func (s *ClientSuite) TestGatewayStatusCheck() {