Make the testKeys extractions methods more robust
This commit is contained in:
parent
bc5fe7d8bf
commit
1879f8e961
9 changed files with 128 additions and 52 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package middlebox
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/measurement-kit/go-measurement-kit"
|
||||
"github.com/ooni/probe-cli/nettests"
|
||||
)
|
||||
|
|
@ -22,19 +24,21 @@ type HTTPHeaderFieldManipulationTestKeys struct {
|
|||
}
|
||||
|
||||
// GetTestKeys returns a projection of the tests keys needed for the views
|
||||
func (h HTTPHeaderFieldManipulation) GetTestKeys(tk map[string]interface{}) interface{} {
|
||||
tampering := false
|
||||
for _, v := range tk["tampering"].(map[string]interface{}) {
|
||||
func (h HTTPHeaderFieldManipulation) GetTestKeys(tk map[string]interface{}) (interface{}, error) {
|
||||
testKeys := HTTPHeaderFieldManipulationTestKeys{IsAnomaly: false}
|
||||
tampering, ok := tk["tampering"].(map[string]interface{})
|
||||
if !ok {
|
||||
return testKeys, errors.New("tampering testkey is invalid")
|
||||
}
|
||||
for _, v := range tampering {
|
||||
t, ok := v.(bool)
|
||||
// Ignore non booleans in the tampering map
|
||||
if ok && t == true {
|
||||
tampering = true
|
||||
testKeys.IsAnomaly = true
|
||||
}
|
||||
}
|
||||
|
||||
return HTTPHeaderFieldManipulationTestKeys{
|
||||
IsAnomaly: tampering,
|
||||
}
|
||||
return testKeys, nil
|
||||
}
|
||||
|
||||
// LogSummary writes the summary to the standard output
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package middlebox
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/measurement-kit/go-measurement-kit"
|
||||
"github.com/ooni/probe-cli/nettests"
|
||||
)
|
||||
|
|
@ -22,12 +24,16 @@ type HTTPInvalidRequestLineTestKeys struct {
|
|||
}
|
||||
|
||||
// GetTestKeys generates a summary for a test run
|
||||
func (h HTTPInvalidRequestLine) GetTestKeys(tk map[string]interface{}) interface{} {
|
||||
tampering := tk["tampering"].(bool)
|
||||
func (h HTTPInvalidRequestLine) GetTestKeys(tk map[string]interface{}) (interface{}, error) {
|
||||
testKeys := HTTPInvalidRequestLineTestKeys{IsAnomaly: false}
|
||||
|
||||
return HTTPInvalidRequestLineTestKeys{
|
||||
IsAnomaly: tampering,
|
||||
tampering, ok := tk["tampering"].(bool)
|
||||
if !ok {
|
||||
return testKeys, errors.New("tampering is not bool")
|
||||
}
|
||||
testKeys.IsAnomaly = tampering
|
||||
|
||||
return testKeys, nil
|
||||
}
|
||||
|
||||
// LogSummary writes the summary to the standard output
|
||||
|
|
|
|||
Loading…
Reference in a new issue