Skip to content

Commit

Permalink
Testing if socks5 proxy is runnning
Browse files Browse the repository at this point in the history
  • Loading branch information
mmiranda committed Dec 1, 2021
1 parent 8999129 commit 1b31681
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cfdtunnel/cfdtunnel_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package cfdtunnel

import (
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
"path"
"strings"
"testing"

"log"

"github.com/stretchr/testify/assert"
"golang.org/x/net/proxy"
"gopkg.in/ini.v1"
)

Expand Down Expand Up @@ -219,3 +223,25 @@ func TestNewTunnel(t *testing.T) {
assert.Equal(t, []string{"arg", "arg"}, tunnel.Args)

}

// TestSock5ProxyRunning launches the proxy tunnel and try to use it calling google.com
// If the result does not have "connection refused" we assume the proxy is running and responding
func TestSocks5ProxyRunning(t *testing.T) {
tunnelConfig := TunnelConfig{"foo.bar", "1234", nil}
cmd := tunnelConfig.startProxyTunnel()
dialSocksProxy, err := proxy.SOCKS5("tcp", "127.0.0.1:1234", nil, proxy.Direct)
if err != nil {
fmt.Println("Error connecting to proxy:", err)
}
tr := &http.Transport{Dial: dialSocksProxy.Dial}

// Create client
myClient := &http.Client{
Transport: tr,
}

_, err = myClient.Get("https://google.com")
commandKill(cmd)
assert.False(t, strings.Contains(err.Error(), "connect: connection refused"))

}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9
gopkg.in/ini.v1 v1.64.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9 h1:0qxwC5n+ttVOINCBeRHO0nq9X7uy8SDsPoi5OaCdIEI=
golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down

0 comments on commit 1b31681

Please sign in to comment.