ooni-probe-cli/nettests/http_header_field_manipulation.go
Simone Basso b4934b1619
Use ooni/probe-engine 0.12.0+patches (#133)
* nettests/groups.go: remove redundant struct names

* go.mod go.sum: update deps except probe-engine

* Update to ooni/probe-engine@e768161f91

The API has changed. Methods that used to change bits of the session have
been removed. Now the session is more immutable than before.

As such, we need to completely fill the config before using it.

* Set IncludeCountry to always true

Co-authored-by: Arturo Filastò <arturo@filasto.net>
2020-06-04 11:19:38 +02:00

52 lines
1.3 KiB
Go

package nettests
import (
"errors"
)
// HTTPHeaderFieldManipulation test implementation
type HTTPHeaderFieldManipulation struct {
}
// Run starts the test
func (h HTTPHeaderFieldManipulation) Run(ctl *Controller) error {
builder, err := ctl.Session.NewExperimentBuilder(
"http_header_field_manipulation",
)
if err != nil {
return err
}
if err := builder.SetOptionString("LogLevel", "INFO"); err != nil {
return err
}
return ctl.Run(builder, []string{""})
}
// HTTPHeaderFieldManipulationTestKeys for the test
type HTTPHeaderFieldManipulationTestKeys struct {
IsAnomaly bool `json:"-"`
}
// GetTestKeys returns a projection of the tests keys needed for the views
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 {
testKeys.IsAnomaly = true
}
}
return testKeys, nil
}
// LogSummary writes the summary to the standard output
func (h HTTPHeaderFieldManipulation) LogSummary(s string) error {
return nil
}