2021-04-05 16:38:25 +02:00
|
|
|
package tunnel_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine"
|
2021-06-04 15:15:41 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/tunnel"
|
2021-05-04 08:14:25 +02:00
|
|
|
"golang.org/x/sys/execabs"
|
2021-04-05 16:38:25 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTorStartStop(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skip test in short mode")
|
|
|
|
}
|
2021-05-04 08:14:25 +02:00
|
|
|
torBinaryPath, err := execabs.LookPath("tor")
|
|
|
|
if err != nil {
|
|
|
|
t.Skip("missing precondition for the test: tor not in PATH")
|
2021-04-05 16:38:25 +02:00
|
|
|
}
|
|
|
|
tunnelDir, err := ioutil.TempDir("testdata", "tor")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
sess, err := engine.NewSession(ctx, engine.SessionConfig{
|
|
|
|
Logger: log.Log,
|
|
|
|
SoftwareName: "miniooni",
|
|
|
|
SoftwareVersion: "0.1.0-dev",
|
|
|
|
TunnelDir: tunnelDir,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
tunnel, err := tunnel.Start(context.Background(), &tunnel.Config{
|
|
|
|
Name: "tor",
|
|
|
|
Session: sess,
|
|
|
|
TorBinary: torBinaryPath,
|
|
|
|
TunnelDir: tunnelDir,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if tunnel.SOCKS5ProxyURL() == nil {
|
|
|
|
t.Fatal("expected non nil URL here")
|
|
|
|
}
|
|
|
|
if tunnel.BootstrapTime() <= 0 {
|
|
|
|
t.Fatal("expected positive bootstrap time here")
|
|
|
|
}
|
|
|
|
tunnel.Stop()
|
|
|
|
}
|