fix: move preventMistakes in InputLoader
This fixes an issue where URLs provided with --input are not accepted by the preventMistakes filter. The filter itself needs to execute _only_ on URLs returned by the checkIn API, rather than on URLs returned by the InputLoader, which may instead be user provided. Reference issue: https://github.com/ooni/probe/issues/1435
This commit is contained in:
parent
6306c09963
commit
818bf2cba5
4 changed files with 150 additions and 103 deletions
|
|
@ -407,3 +407,90 @@ func TestInputLoaderCheckInSuccessWithSomeURLs(t *testing.T) {
|
|||
t.Fatal(diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreventMistakesWithCategories(t *testing.T) {
|
||||
input := []model.URLInfo{{
|
||||
CategoryCode: "NEWS",
|
||||
URL: "https://repubblica.it/",
|
||||
CountryCode: "IT",
|
||||
}, {
|
||||
CategoryCode: "HACK",
|
||||
URL: "https://2600.com",
|
||||
CountryCode: "XX",
|
||||
}, {
|
||||
CategoryCode: "FILE",
|
||||
URL: "https://addons.mozilla.org/",
|
||||
CountryCode: "XX",
|
||||
}}
|
||||
desired := []model.URLInfo{{
|
||||
CategoryCode: "NEWS",
|
||||
URL: "https://repubblica.it/",
|
||||
CountryCode: "IT",
|
||||
}, {
|
||||
CategoryCode: "FILE",
|
||||
URL: "https://addons.mozilla.org/",
|
||||
CountryCode: "XX",
|
||||
}}
|
||||
il := &InputLoader{}
|
||||
output := il.preventMistakes(input, []string{"NEWS", "FILE"})
|
||||
if diff := cmp.Diff(desired, output); diff != "" {
|
||||
t.Fatal(diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreventMistakesWithoutCategoriesAndNil(t *testing.T) {
|
||||
input := []model.URLInfo{{
|
||||
CategoryCode: "NEWS",
|
||||
URL: "https://repubblica.it/",
|
||||
CountryCode: "IT",
|
||||
}, {
|
||||
CategoryCode: "HACK",
|
||||
URL: "https://2600.com",
|
||||
CountryCode: "XX",
|
||||
}, {
|
||||
CategoryCode: "FILE",
|
||||
URL: "https://addons.mozilla.org/",
|
||||
CountryCode: "XX",
|
||||
}}
|
||||
il := &InputLoader{}
|
||||
output := il.preventMistakes(input, nil)
|
||||
if diff := cmp.Diff(input, output); diff != "" {
|
||||
t.Fatal(diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreventMistakesWithoutCategoriesAndEmpty(t *testing.T) {
|
||||
input := []model.URLInfo{{
|
||||
CategoryCode: "NEWS",
|
||||
URL: "https://repubblica.it/",
|
||||
CountryCode: "IT",
|
||||
}, {
|
||||
CategoryCode: "HACK",
|
||||
URL: "https://2600.com",
|
||||
CountryCode: "XX",
|
||||
}, {
|
||||
CategoryCode: "FILE",
|
||||
URL: "https://addons.mozilla.org/",
|
||||
CountryCode: "XX",
|
||||
}}
|
||||
il := &InputLoader{}
|
||||
output := il.preventMistakes(input, []string{})
|
||||
if diff := cmp.Diff(input, output); diff != "" {
|
||||
t.Fatal(diff)
|
||||
}
|
||||
}
|
||||
|
||||
// InputLoaderFakeLogger is a fake InputLoaderLogger.
|
||||
type InputLoaderFakeLogger struct{}
|
||||
|
||||
// Warnf implements InputLoaderLogger.Warnf
|
||||
func (ilfl *InputLoaderFakeLogger) Warnf(format string, v ...interface{}) {}
|
||||
|
||||
func TestInputLoaderLoggerWorksAsIntended(t *testing.T) {
|
||||
logger := &InputLoaderFakeLogger{}
|
||||
inputLoader := &InputLoader{Logger: logger}
|
||||
out := inputLoader.logger()
|
||||
if out != logger {
|
||||
t.Fatal("logger not working as intended")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue