Skip to content

Commit

Permalink
feature: force proxy preference on linux to false
Browse files Browse the repository at this point in the history
  • Loading branch information
parvit committed Sep 25, 2024
1 parent 488914c commit 4ad1212
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 34 deletions.
8 changes: 5 additions & 3 deletions workers/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions workers/client/client_network_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
68 changes: 45 additions & 23 deletions workers/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down

0 comments on commit 4ad1212

Please sign in to comment.