83440cf110
The legacy part for now is internal/errorsx. It will stay there until I figure out whether it also needs some extra bug fixing. The good part is now in internal/netxlite/errorsx and contains all the logic for mapping errors. We need to further improve upon this logic by writing more thorough integration tests for QUIC. We also need to copy the various dialer, conn, etc adapters that set errors. We will put them inside netxlite and we will generate errors in a way that is less crazy with respect to the major operation. (The idea is to always wrap, given that now we measure in an incremental way and we don't measure every operation together.) Part of https://github.com/ooni/probe/issues/1591
130 lines
3.1 KiB
Go
130 lines
3.1 KiB
Go
package signal_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/apex/log"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/experiment/signal"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/mockable"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
|
)
|
|
|
|
func TestNewExperimentMeasurer(t *testing.T) {
|
|
measurer := signal.NewExperimentMeasurer(signal.Config{})
|
|
if measurer.ExperimentName() != "signal" {
|
|
t.Fatal("unexpected name")
|
|
}
|
|
if measurer.ExperimentVersion() != "0.2.0" {
|
|
t.Fatal("unexpected version")
|
|
}
|
|
}
|
|
|
|
func TestGood(t *testing.T) {
|
|
measurer := signal.NewExperimentMeasurer(signal.Config{})
|
|
measurement := new(model.Measurement)
|
|
err := measurer.Run(
|
|
context.Background(),
|
|
&mockable.Session{
|
|
MockableLogger: log.Log,
|
|
},
|
|
measurement,
|
|
model.NewPrinterCallbacks(log.Log),
|
|
)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tk := measurement.TestKeys.(*signal.TestKeys)
|
|
if tk.Agent != "redirect" {
|
|
t.Fatal("unexpected Agent")
|
|
}
|
|
if tk.FailedOperation != nil {
|
|
t.Fatal("unexpected FailedOperation")
|
|
}
|
|
if tk.Failure != nil {
|
|
t.Fatal("unexpected Failure")
|
|
}
|
|
if len(tk.NetworkEvents) <= 0 {
|
|
t.Fatal("no NetworkEvents?!")
|
|
}
|
|
if len(tk.Queries) <= 0 {
|
|
t.Fatal("no Queries?!")
|
|
}
|
|
if len(tk.Requests) <= 0 {
|
|
t.Fatal("no Requests?!")
|
|
}
|
|
if len(tk.TCPConnect) <= 0 {
|
|
t.Fatal("no TCPConnect?!")
|
|
}
|
|
if len(tk.TLSHandshakes) <= 0 {
|
|
t.Fatal("no TLSHandshakes?!")
|
|
}
|
|
if tk.SignalBackendFailure != nil {
|
|
t.Fatal("unexpected SignalBackendFailure")
|
|
}
|
|
if tk.SignalBackendStatus != "ok" {
|
|
t.Fatal("unexpected SignalBackendStatus")
|
|
}
|
|
sk, err := measurer.GetSummaryKeys(measurement)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, ok := sk.(signal.SummaryKeys); !ok {
|
|
t.Fatal("invalid type for summary keys")
|
|
}
|
|
}
|
|
|
|
func TestUpdate(t *testing.T) {
|
|
tk := signal.NewTestKeys()
|
|
tk.Update(urlgetter.MultiOutput{
|
|
Input: urlgetter.MultiInput{
|
|
Config: urlgetter.Config{Method: "GET"},
|
|
Target: "https://textsecure-service.whispersystems.org/",
|
|
},
|
|
TestKeys: urlgetter.TestKeys{
|
|
Failure: (func() *string {
|
|
s := errorsx.FailureEOFError
|
|
return &s
|
|
})(),
|
|
},
|
|
})
|
|
if tk.SignalBackendStatus != "blocked" {
|
|
t.Fatal("SignalBackendStatus should be blocked")
|
|
}
|
|
if *tk.SignalBackendFailure != errorsx.FailureEOFError {
|
|
t.Fatal("invalid SignalBackendError")
|
|
}
|
|
}
|
|
|
|
func TestBadSignalCA(t *testing.T) {
|
|
measurer := signal.NewExperimentMeasurer(signal.Config{
|
|
SignalCA: "INVALIDCA",
|
|
})
|
|
measurement := new(model.Measurement)
|
|
err := measurer.Run(
|
|
context.Background(),
|
|
&mockable.Session{
|
|
MockableLogger: log.Log,
|
|
},
|
|
measurement,
|
|
model.NewPrinterCallbacks(log.Log),
|
|
)
|
|
if err.Error() != "AppendCertsFromPEM failed" {
|
|
t.Fatal("not the error we expected")
|
|
}
|
|
}
|
|
|
|
func TestGetSummaryInvalidType(t *testing.T) {
|
|
measurer := signal.Measurer{}
|
|
in := make(chan int)
|
|
out, err := measurer.GetSummaryKeys(&model.Measurement{TestKeys: in})
|
|
if err == nil || err.Error() != "invalid test keys type" {
|
|
t.Fatal("not the error we expected", err)
|
|
}
|
|
if out != nil {
|
|
t.Fatal("expected nil output here")
|
|
}
|
|
}
|