Add result summary support for IM tests
This commit is contained in:
parent
98e95b8b7e
commit
e56ce73006
@ -34,7 +34,8 @@ type MiddleboxSummary struct {
|
|||||||
|
|
||||||
// IMSummary is the summary for the im tests
|
// IMSummary is the summary for the im tests
|
||||||
type IMSummary struct {
|
type IMSummary struct {
|
||||||
Detected bool
|
Tested uint
|
||||||
|
Blocked uint
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebsitesSummary is the summary for the websites test
|
// WebsitesSummary is the summary for the websites test
|
||||||
@ -148,7 +149,47 @@ var NettestGroups = map[string]NettestGroup{
|
|||||||
im.WhatsApp{},
|
im.WhatsApp{},
|
||||||
},
|
},
|
||||||
Summary: func(m database.SummaryMap) (string, error) {
|
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
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,31 @@ func (h FacebookMessenger) Run(ctl *nettests.Controller) error {
|
|||||||
type FacebookMessengerSummary struct {
|
type FacebookMessengerSummary struct {
|
||||||
DNSBlocking bool
|
DNSBlocking bool
|
||||||
TCPBlocking bool
|
TCPBlocking bool
|
||||||
|
Blocked bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Summary generates a summary for a test run
|
// Summary generates a summary for a test run
|
||||||
func (h FacebookMessenger) Summary(tk map[string]interface{}) interface{} {
|
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{
|
return FacebookMessengerSummary{
|
||||||
DNSBlocking: tk["facebook_dns_blocking"].(bool),
|
DNSBlocking: dnsBlocking,
|
||||||
TCPBlocking: tk["facebook_tcp_blocking"].(bool),
|
TCPBlocking: tcpBlocking,
|
||||||
|
Blocked: dnsBlocking || tcpBlocking,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,14 +21,38 @@ type TelegramSummary struct {
|
|||||||
HTTPBlocking bool
|
HTTPBlocking bool
|
||||||
TCPBlocking bool
|
TCPBlocking bool
|
||||||
WebBlocking bool
|
WebBlocking bool
|
||||||
|
Blocked bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Summary generates a summary for a test run
|
// Summary generates a summary for a test run
|
||||||
func (h Telegram) Summary(tk map[string]interface{}) interface{} {
|
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{
|
return TelegramSummary{
|
||||||
TCPBlocking: tk["telegram_tcp_blocking"].(bool) == true,
|
TCPBlocking: tcpBlocking,
|
||||||
HTTPBlocking: tk["telegram_http_blocking"].(bool) == true,
|
HTTPBlocking: httpBlocking,
|
||||||
WebBlocking: tk["telegram_web_status"].(string) == "blocked",
|
WebBlocking: webBlocking,
|
||||||
|
Blocked: webBlocking || httpBlocking || tcpBlocking,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,16 +21,36 @@ type WhatsAppSummary struct {
|
|||||||
RegistrationServerBlocking bool
|
RegistrationServerBlocking bool
|
||||||
WebBlocking bool
|
WebBlocking bool
|
||||||
EndpointsBlocking bool
|
EndpointsBlocking bool
|
||||||
|
Blocked bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Summary generates a summary for a test run
|
// Summary generates a summary for a test run
|
||||||
func (h WhatsApp) Summary(tk map[string]interface{}) interface{} {
|
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{
|
return WhatsAppSummary{
|
||||||
RegistrationServerBlocking: tk["registration_server_status"].(string) == blk,
|
RegistrationServerBlocking: registrationBlocking,
|
||||||
WebBlocking: tk["whatsapp_web_status"].(string) == blk,
|
WebBlocking: webBlocking,
|
||||||
EndpointsBlocking: tk["whatsapp_endpoints_status"].(string) == blk,
|
EndpointsBlocking: endpointsBlocking,
|
||||||
|
Blocked: registrationBlocking || webBlocking || endpointsBlocking,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user