Add result summary support for IM tests

This commit is contained in:
Arturo Filastò 2018-03-23 15:22:58 +01:00
parent 98e95b8b7e
commit e56ce73006
4 changed files with 114 additions and 11 deletions

View File

@ -34,7 +34,8 @@ type MiddleboxSummary struct {
// IMSummary is the summary for the im tests
type IMSummary struct {
Detected bool
Tested uint
Blocked uint
}
// WebsitesSummary is the summary for the websites test
@ -148,7 +149,47 @@ var NettestGroups = map[string]NettestGroup{
im.WhatsApp{},
},
Summary: func(m database.SummaryMap) (string, error) {
return "{}", nil
var (
err error
waSummary im.WhatsAppSummary
tgSummary im.TelegramSummary
fbSummary im.FacebookMessengerSummary
summary IMSummary
)
err = json.Unmarshal([]byte(m["Whatsapp"][0]), &waSummary)
if err != nil {
log.WithError(err).Error("failed to unmarshal whatsapp summary")
return "", err
}
err = json.Unmarshal([]byte(m["Telegram"][0]), &tgSummary)
if err != nil {
log.WithError(err).Error("failed to unmarshal telegram summary")
return "", err
}
err = json.Unmarshal([]byte(m["FacebookMessenger"][0]), &fbSummary)
if err != nil {
log.WithError(err).Error("failed to unmarshal facebook summary")
return "", err
}
// XXX it could actually be that some are not tested when the
// configuration is changed.
summary.Tested = 3
summary.Blocked = 0
if fbSummary.Blocked == true {
summary.Blocked++
}
if tgSummary.Blocked == true {
summary.Blocked++
}
if waSummary.Blocked == true {
summary.Blocked++
}
summaryBytes, err := json.Marshal(summary)
if err != nil {
return "", err
}
return string(summaryBytes), nil
},
},
}

View File

@ -20,13 +20,31 @@ func (h FacebookMessenger) Run(ctl *nettests.Controller) error {
type FacebookMessengerSummary struct {
DNSBlocking bool
TCPBlocking bool
Blocked bool
}
// Summary generates a summary for a test run
func (h FacebookMessenger) Summary(tk map[string]interface{}) interface{} {
var (
dnsBlocking bool
tcpBlocking bool
)
if tk["facebook_dns_blocking"] == nil {
dnsBlocking = false
} else {
dnsBlocking = tk["facebook_dns_blocking"].(bool)
}
if tk["facebook_tcp_blocking"] == nil {
tcpBlocking = false
} else {
tcpBlocking = tk["facebook_tcp_blocking"].(bool)
}
return FacebookMessengerSummary{
DNSBlocking: tk["facebook_dns_blocking"].(bool),
TCPBlocking: tk["facebook_tcp_blocking"].(bool),
DNSBlocking: dnsBlocking,
TCPBlocking: tcpBlocking,
Blocked: dnsBlocking || tcpBlocking,
}
}

View File

@ -21,14 +21,38 @@ type TelegramSummary struct {
HTTPBlocking bool
TCPBlocking bool
WebBlocking bool
Blocked bool
}
// Summary generates a summary for a test run
func (h Telegram) Summary(tk map[string]interface{}) interface{} {
var (
tcpBlocking bool
httpBlocking bool
webBlocking bool
)
if tk["telegram_tcp_blocking"] == nil {
tcpBlocking = false
} else {
tcpBlocking = tk["telegram_tcp_blocking"].(bool)
}
if tk["telegram_http_blocking"] == nil {
httpBlocking = false
} else {
httpBlocking = tk["telegram_http_blocking"].(bool)
}
if tk["telegram_web_status"] == nil {
webBlocking = false
} else {
webBlocking = tk["telegram_web_status"].(string) == "blocked"
}
return TelegramSummary{
TCPBlocking: tk["telegram_tcp_blocking"].(bool) == true,
HTTPBlocking: tk["telegram_http_blocking"].(bool) == true,
WebBlocking: tk["telegram_web_status"].(string) == "blocked",
TCPBlocking: tcpBlocking,
HTTPBlocking: httpBlocking,
WebBlocking: webBlocking,
Blocked: webBlocking || httpBlocking || tcpBlocking,
}
}

View File

@ -21,16 +21,36 @@ type WhatsAppSummary struct {
RegistrationServerBlocking bool
WebBlocking bool
EndpointsBlocking bool
Blocked bool
}
// Summary generates a summary for a test run
func (h WhatsApp) Summary(tk map[string]interface{}) interface{} {
const blk = "blocked"
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")
return WhatsAppSummary{
RegistrationServerBlocking: tk["registration_server_status"].(string) == blk,
WebBlocking: tk["whatsapp_web_status"].(string) == blk,
EndpointsBlocking: tk["whatsapp_endpoints_status"].(string) == blk,
RegistrationServerBlocking: registrationBlocking,
WebBlocking: webBlocking,
EndpointsBlocking: endpointsBlocking,
Blocked: registrationBlocking || webBlocking || endpointsBlocking,
}
}