2021-04-03 19:57:21 +02:00
|
|
|
package tunnel
|
2021-02-02 12:05:47 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/internal/mockable"
|
|
|
|
)
|
|
|
|
|
2021-04-03 19:57:21 +02:00
|
|
|
func TestStartNoTunnel(t *testing.T) {
|
2021-02-02 12:05:47 +01:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel()
|
2021-04-03 20:12:56 +02:00
|
|
|
tunnel, err := Start(ctx, &Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
Name: "",
|
|
|
|
Session: &mockable.Session{
|
|
|
|
MockableLogger: log.Log,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if tunnel != nil {
|
|
|
|
t.Fatal("expected nil tunnel here")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 19:57:21 +02:00
|
|
|
func TestStartPsiphonTunnel(t *testing.T) {
|
2021-02-02 12:05:47 +01:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel()
|
2021-04-03 20:12:56 +02:00
|
|
|
tunnel, err := Start(ctx, &Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
Name: "psiphon",
|
|
|
|
Session: &mockable.Session{
|
|
|
|
MockableLogger: log.Log,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if !errors.Is(err, context.Canceled) {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
|
|
|
if tunnel != nil {
|
|
|
|
t.Fatal("expected nil tunnel here")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 19:57:21 +02:00
|
|
|
func TestStartTorTunnel(t *testing.T) {
|
2021-02-02 12:05:47 +01:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel()
|
2021-04-03 20:12:56 +02:00
|
|
|
tunnel, err := Start(ctx, &Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
Name: "tor",
|
|
|
|
Session: &mockable.Session{
|
|
|
|
MockableLogger: log.Log,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if !errors.Is(err, context.Canceled) {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
|
|
|
if tunnel != nil {
|
|
|
|
t.Fatal("expected nil tunnel here")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 19:57:21 +02:00
|
|
|
func TestStartInvalidTunnel(t *testing.T) {
|
2021-02-02 12:05:47 +01:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel()
|
2021-04-03 20:12:56 +02:00
|
|
|
tunnel, err := Start(ctx, &Config{
|
2021-02-02 12:05:47 +01:00
|
|
|
Name: "antani",
|
|
|
|
Session: &mockable.Session{
|
|
|
|
MockableLogger: log.Log,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err == nil || err.Error() != "unsupported tunnel" {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
|
|
|
t.Log(tunnel)
|
|
|
|
if tunnel != nil {
|
|
|
|
t.Fatal("expected nil tunnel here")
|
|
|
|
}
|
|
|
|
}
|