feat: avoid safe options to be serialized into the measurement (#859)

Skip options that begin with the `Safe` prefix from appearing in the
serialization of a Measurement that will be submitted to the OONI
backend.

Fixes https://github.com/ooni/probe/issues/2214
This commit is contained in:
Ain Ghazal 2022-08-17 13:48:59 +02:00 committed by GitHub
commit d50a39ae92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 2 deletions

View file

@ -8,6 +8,7 @@ import (
"context"
"fmt"
"math/rand"
"strings"
"time"
"github.com/ooni/probe-cli/v3/internal/engine"
@ -183,9 +184,16 @@ func (ed *Experiment) newInputLoader(inputPolicy model.InputPolicy) inputLoader
}
// experimentOptionsToStringList convers the options to []string, which is
// the format with which we include them into a OONI Measurement
// the format with which we include them into a OONI Measurement. The resulting
// []string will skip any option that is named with a `Safe` prefix (case
// sensitive).
func experimentOptionsToStringList(options map[string]any) (out []string) {
// the prefix to skip inclusion in the string list
safeOptionPrefix := "Safe"
for key, value := range options {
if strings.HasPrefix(key, safeOptionPrefix) {
continue
}
out = append(out, fmt.Sprintf("%s=%v", key, value))
}
return