2019-12-02 16:57:55 +01:00
|
|
|
package nettests
|
2018-02-13 10:48:46 +01:00
|
|
|
|
|
|
|
import (
|
2020-11-30 15:39:25 +01:00
|
|
|
"context"
|
|
|
|
|
2018-09-07 12:55:27 +02:00
|
|
|
"github.com/apex/log"
|
2021-02-02 12:05:47 +01:00
|
|
|
engine "github.com/ooni/probe-cli/v3/internal/engine"
|
2022-01-03 13:53:23 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2018-02-13 10:48:46 +01:00
|
|
|
)
|
|
|
|
|
2021-12-03 16:10:55 +01:00
|
|
|
func (n WebConnectivity) lookupURLs(ctl *Controller, categories []string) ([]string, error) {
|
2021-03-29 20:00:50 +02:00
|
|
|
inputloader := &engine.InputLoader{
|
2022-01-03 13:53:23 +01:00
|
|
|
CheckInConfig: &model.OOAPICheckInConfig{
|
2021-03-30 11:59:29 +02:00
|
|
|
// Setting Charging and OnWiFi to true causes the CheckIn
|
|
|
|
// API to return to us as much URL as possible with the
|
|
|
|
// given RunType hint.
|
|
|
|
Charging: true,
|
|
|
|
OnWiFi: true,
|
|
|
|
RunType: ctl.RunType,
|
2022-01-03 13:53:23 +01:00
|
|
|
WebConnectivity: model.OOAPICheckInConfigWebConnectivity{
|
2021-03-29 18:46:26 +02:00
|
|
|
CategoryCodes: categories,
|
|
|
|
},
|
|
|
|
},
|
2021-12-03 16:10:55 +01:00
|
|
|
ExperimentName: "web_connectivity",
|
2022-08-17 10:57:03 +02:00
|
|
|
InputPolicy: model.InputOrQueryBackend,
|
2021-12-03 16:10:55 +01:00
|
|
|
Session: ctl.Session,
|
|
|
|
SourceFiles: ctl.InputFiles,
|
|
|
|
StaticInputs: ctl.Inputs,
|
2021-03-29 20:00:50 +02:00
|
|
|
}
|
2020-11-30 15:39:25 +01:00
|
|
|
testlist, err := inputloader.Load(context.Background())
|
2018-03-23 12:41:06 +01:00
|
|
|
if err != nil {
|
2021-12-03 16:10:55 +01:00
|
|
|
return nil, err
|
2018-03-23 12:41:06 +01:00
|
|
|
}
|
2021-12-03 16:10:55 +01:00
|
|
|
return ctl.BuildAndSetInputIdxMap(ctl.Probe.DB(), testlist)
|
2018-03-23 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
2018-02-13 10:48:46 +01:00
|
|
|
// WebConnectivity test implementation
|
2021-03-30 11:16:12 +02:00
|
|
|
type WebConnectivity struct{}
|
2018-02-13 10:48:46 +01:00
|
|
|
|
|
|
|
// Run starts the test
|
2019-12-02 16:57:55 +01:00
|
|
|
func (n WebConnectivity) Run(ctl *Controller) error {
|
2020-11-13 20:07:30 +01:00
|
|
|
log.Debugf("Enabled category codes are the following %v", ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes)
|
2021-12-03 16:10:55 +01:00
|
|
|
urls, err := n.lookupURLs(ctl, ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes)
|
2018-03-23 12:41:06 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-12-03 16:10:55 +01:00
|
|
|
builder, err := ctl.Session.NewExperimentBuilder("web_connectivity")
|
2019-10-28 14:05:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctl.Run(builder, urls)
|
2018-02-13 10:48:46 +01:00
|
|
|
}
|