MVP of a signal messenger test (#230)
* MVP of a signal messenger test * Add minimal signal test unit tests * Add Signal test to the im nettest group * Add test for https://sfu.voip.signal.org/ * Fix bug in client-side determination of blocking status * Add uptime.signal.org to the test targets * Add more tests * Check for invalid CA being passed * Check that the update function works as expected * Update internal/engine/experiment/signal/signal_test.go Co-authored-by: Simone Basso <bassosimone@gmail.com> * fix: back out URL we shouldn't have changed When merging probe-engine into probe-cli, we changed too many URLs and some of them should not have been changed. I noticed this during the review of Signal and I choose to add this commit to revert such changes. While there, make sure the URL of the experiment is OK. * fix(signal): reach 100% of coverage Just so that we can focus on areas of the codebase where we need more coverage, let us avoid missing an easy line to test. Co-authored-by: Simone Basso <bassosimone@gmail.com>
This commit is contained in:
parent
772de83a06
commit
5e5cfa72e7
13 changed files with 363 additions and 9 deletions
129
internal/engine/experiment/signal/signal_test.go
Normal file
129
internal/engine/experiment/signal/signal_test.go
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
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/internal/mockable"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
|
||||
)
|
||||
|
||||
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 := errorx.FailureEOFError
|
||||
return &s
|
||||
})(),
|
||||
},
|
||||
})
|
||||
if tk.SignalBackendStatus != "blocked" {
|
||||
t.Fatal("SignalBackendStatus should be blocked")
|
||||
}
|
||||
if *tk.SignalBackendFailure != errorx.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")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue