ooni-probe-cli/nettests/im/whatsapp.go

61 lines
1.6 KiB
Go
Raw Normal View History

package im
import (
"github.com/measurement-kit/go-measurement-kit"
"github.com/ooni/probe-cli/nettests"
)
// WhatsApp test implementation
type WhatsApp struct {
}
// Run starts the test
func (h WhatsApp) Run(ctl *nettests.Controller) error {
mknt := mk.NewNettest("Whatsapp")
ctl.Init(mknt)
return mknt.Run()
}
2018-09-10 12:41:28 +02:00
// WhatsAppTestKeys for the test
type WhatsAppTestKeys struct {
RegistrationServerBlocking bool `json:"registration_server_blocking"`
WebBlocking bool `json:"whatsapp_web_blocking"`
EndpointsBlocking bool `json:"whatsapp_endpoints_blocking"`
IsAnomaly bool `json:"-"`
}
2018-09-10 12:41:28 +02:00
// GetTestKeys generates a summary for a test run
func (h WhatsApp) GetTestKeys(tk map[string]interface{}) (interface{}, error) {
var (
webBlocking bool
registrationBlocking bool
endpointsBlocking bool
)
var computeBlocking = func(key string) bool {
const blk = "blocked"
if tk[key] == nil {
return false
}
if tk[key].(string) == blk {
return true
}
return false
}
registrationBlocking = computeBlocking("registration_server_status")
webBlocking = computeBlocking("whatsapp_web_status")
endpointsBlocking = computeBlocking("whatsapp_endpoints_status")
2018-09-10 12:41:28 +02:00
return WhatsAppTestKeys{
RegistrationServerBlocking: registrationBlocking,
WebBlocking: webBlocking,
EndpointsBlocking: endpointsBlocking,
2018-09-10 12:41:28 +02:00
IsAnomaly: registrationBlocking || webBlocking || endpointsBlocking,
}, nil
}
// LogSummary writes the summary to the standard output
func (h WhatsApp) LogSummary(s string) error {
return nil
}