2018-03-21 12:18:45 +01:00
|
|
|
package middlebox
|
|
|
|
|
|
|
|
import (
|
2018-09-27 11:40:57 +02:00
|
|
|
"errors"
|
|
|
|
|
2018-03-21 12:18:45 +01:00
|
|
|
"github.com/measurement-kit/go-measurement-kit"
|
2018-05-03 14:59:55 +02:00
|
|
|
"github.com/ooni/probe-cli/nettests"
|
2018-03-21 12:18:45 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// HTTPHeaderFieldManipulation test implementation
|
|
|
|
type HTTPHeaderFieldManipulation struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run starts the test
|
|
|
|
func (h HTTPHeaderFieldManipulation) Run(ctl *nettests.Controller) error {
|
|
|
|
mknt := mk.NewNettest("HttpHeaderFieldManipulation")
|
|
|
|
ctl.Init(mknt)
|
|
|
|
return mknt.Run()
|
|
|
|
}
|
|
|
|
|
2018-09-10 12:41:28 +02:00
|
|
|
// HTTPHeaderFieldManipulationTestKeys for the test
|
|
|
|
type HTTPHeaderFieldManipulationTestKeys struct {
|
|
|
|
IsAnomaly bool `json:"-"`
|
2018-03-21 12:18:45 +01:00
|
|
|
}
|
|
|
|
|
2018-09-10 12:41:28 +02:00
|
|
|
// GetTestKeys returns a projection of the tests keys needed for the views
|
2018-09-27 11:40:57 +02:00
|
|
|
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 {
|
2018-03-21 12:18:45 +01:00
|
|
|
t, ok := v.(bool)
|
|
|
|
// Ignore non booleans in the tampering map
|
|
|
|
if ok && t == true {
|
2018-09-27 11:40:57 +02:00
|
|
|
testKeys.IsAnomaly = true
|
2018-03-21 12:18:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-27 11:40:57 +02:00
|
|
|
return testKeys, nil
|
2018-03-21 12:18:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// LogSummary writes the summary to the standard output
|
|
|
|
func (h HTTPHeaderFieldManipulation) LogSummary(s string) error {
|
|
|
|
return nil
|
|
|
|
}
|