2021-04-05 18:25:43 +02:00
|
|
|
package urlgetter
|
2021-02-02 12:05:47 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
2021-06-22 00:12:03 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/mockable"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
2021-04-05 18:25:43 +02:00
|
|
|
func TestGetterHTTPSWithTunnelCannotCreateTempDir(t *testing.T) {
|
|
|
|
expected := errors.New("mocked error")
|
|
|
|
ctx := context.Background()
|
|
|
|
g := Getter{
|
|
|
|
Config: Config{
|
|
|
|
NoFollowRedirects: true, // reduce number of events
|
|
|
|
Tunnel: "fake",
|
2021-02-02 12:05:47 +01:00
|
|
|
},
|
2021-04-05 18:25:43 +02:00
|
|
|
Session: &mockable.Session{
|
|
|
|
MockableHTTPClient: http.DefaultClient,
|
|
|
|
MockableLogger: log.Log,
|
2021-02-02 12:05:47 +01:00
|
|
|
},
|
2021-04-05 18:25:43 +02:00
|
|
|
Target: "https://www.google.com",
|
|
|
|
testIOUtilTempDir: func(dir, pattern string) (string, error) {
|
|
|
|
return "", expected
|
2021-02-02 12:05:47 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
tk, err := g.Get(ctx)
|
2021-04-05 18:25:43 +02:00
|
|
|
if !errors.Is(err, expected) {
|
|
|
|
t.Fatal("not the error we expected", err)
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|
2021-04-05 18:25:43 +02:00
|
|
|
if tk.Agent != "agent" {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the Agent we expected")
|
|
|
|
}
|
|
|
|
if tk.BootstrapTime != 0 {
|
|
|
|
t.Fatal("not the BootstrapTime we expected")
|
|
|
|
}
|
2021-04-05 18:25:43 +02:00
|
|
|
if tk.FailedOperation == nil || *tk.FailedOperation != "top_level" {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the FailedOperation we expected")
|
|
|
|
}
|
2021-04-05 18:25:43 +02:00
|
|
|
if tk.Failure == nil || *tk.Failure != "unknown_failure: mocked error" {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the Failure we expected")
|
|
|
|
}
|
|
|
|
if len(tk.NetworkEvents) != 0 {
|
|
|
|
t.Fatal("not the NetworkEvents we expected")
|
|
|
|
}
|
|
|
|
if len(tk.Queries) != 0 {
|
|
|
|
t.Fatal("not the Queries we expected")
|
|
|
|
}
|
|
|
|
if len(tk.TCPConnect) != 0 {
|
|
|
|
t.Fatal("not the TCPConnect we expected")
|
|
|
|
}
|
|
|
|
if len(tk.Requests) != 0 {
|
|
|
|
t.Fatal("not the Requests we expected")
|
|
|
|
}
|
|
|
|
if tk.SOCKSProxy != "" {
|
|
|
|
t.Fatal("not the SOCKSProxy we expected")
|
|
|
|
}
|
|
|
|
if len(tk.TLSHandshakes) != 0 {
|
|
|
|
t.Fatal("not the TLSHandshakes we expected")
|
|
|
|
}
|
2021-04-05 18:25:43 +02:00
|
|
|
if tk.Tunnel != "fake" {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the Tunnel we expected")
|
|
|
|
}
|
|
|
|
if tk.HTTPResponseStatus != 0 {
|
|
|
|
t.Fatal("not the HTTPResponseStatus we expected")
|
|
|
|
}
|
2021-04-05 18:25:43 +02:00
|
|
|
if len(tk.HTTPResponseBody) != 0 {
|
2021-02-02 12:05:47 +01:00
|
|
|
t.Fatal("not the HTTPResponseBody we expected")
|
|
|
|
}
|
|
|
|
}
|