fix(tunnel): pass /absolute/path/to/tor to cretz/bine (#323)

* fix(tunnel): pass /absolute/path/to/tor to cretz/bine

It seems cretz/bine is not aware of https://blog.golang.org/path-security
for now. I am planning to send over a diff for that later today.

In the meanwhile, do the right thing here, and make sure that we obtain
the absolute path to the tor binary before we continue.

This work is part of https://github.com/ooni/probe-engine/issues/283.

* fix tests when tor is not installed
This commit is contained in:
Simone Basso 2021-05-04 08:14:25 +02:00 committed by GitHub
commit a9b3a3b3a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 136 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"strings"
"syscall"
"testing"
"github.com/cretz/bine/control"
@ -77,12 +78,30 @@ func TestTorWithEmptyTunnelDir(t *testing.T) {
}
}
func TestTorBinaryNotFoundFailure(t *testing.T) {
ctx := context.Background()
tun, err := torStart(ctx, &Config{
Session: &mockable.Session{},
TorBinary: "/nonexistent/directory/tor",
TunnelDir: "testdata",
})
if !errors.Is(err, syscall.ENOENT) {
t.Fatal("not the error we expected", err)
}
if tun != nil {
t.Fatal("expected nil tunnel here")
}
}
func TestTorStartFailure(t *testing.T) {
expected := errors.New("mocked error")
ctx := context.Background()
tun, err := torStart(ctx, &Config{
Session: &mockable.Session{},
TunnelDir: "testdata",
testExecabsLookPath: func(name string) (string, error) {
return "/usr/local/bin/tor", nil
},
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
return nil, expected
},
@ -101,6 +120,9 @@ func TestTorEnableNetworkFailure(t *testing.T) {
tun, err := torStart(ctx, &Config{
Session: &mockable.Session{},
TunnelDir: "testdata",
testExecabsLookPath: func(name string) (string, error) {
return "/usr/local/bin/tor", nil
},
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
return &tor.Tor{}, nil
},
@ -122,6 +144,9 @@ func TestTorGetInfoFailure(t *testing.T) {
tun, err := torStart(ctx, &Config{
Session: &mockable.Session{},
TunnelDir: "testdata",
testExecabsLookPath: func(name string) (string, error) {
return "/usr/local/bin/tor", nil
},
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
return &tor.Tor{}, nil
},
@ -145,6 +170,9 @@ func TestTorGetInfoInvalidNumberOfKeys(t *testing.T) {
tun, err := torStart(ctx, &Config{
Session: &mockable.Session{},
TunnelDir: "testdata",
testExecabsLookPath: func(name string) (string, error) {
return "/usr/local/bin/tor", nil
},
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
return &tor.Tor{}, nil
},
@ -168,6 +196,9 @@ func TestTorGetInfoInvalidKey(t *testing.T) {
tun, err := torStart(ctx, &Config{
Session: &mockable.Session{},
TunnelDir: "testdata",
testExecabsLookPath: func(name string) (string, error) {
return "/usr/local/bin/tor", nil
},
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
return &tor.Tor{}, nil
},
@ -191,6 +222,9 @@ func TestTorGetInfoInvalidProxyType(t *testing.T) {
tun, err := torStart(ctx, &Config{
Session: &mockable.Session{},
TunnelDir: "testdata",
testExecabsLookPath: func(name string) (string, error) {
return "/usr/local/bin/tor", nil
},
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
return &tor.Tor{}, nil
},
@ -214,6 +248,9 @@ func TestTorUnsupportedProxy(t *testing.T) {
tun, err := torStart(ctx, &Config{
Session: &mockable.Session{},
TunnelDir: "testdata",
testExecabsLookPath: func(name string) (string, error) {
return "/usr/local/bin/tor", nil
},
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
return &tor.Tor{}, nil
},