Test suite expects static Config not depending on input

This commit is contained in:
ooni noob 2022-11-21 14:13:41 +01:00
parent 9783e3bb47
commit c95fb894f0

View File

@ -8,7 +8,6 @@ import (
"net" "net"
"net/smtp" "net/smtp"
"net/url" "net/url"
"strconv"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
@ -26,9 +25,6 @@ var (
// errInvalidScheme indicates that the scheme is invalid // errInvalidScheme indicates that the scheme is invalid
errInvalidScheme = errors.New("scheme must be smtp(s)") errInvalidScheme = errors.New("scheme must be smtp(s)")
// errInvalidPort indicates that the port provided could not be parsed as an int
errInvalidPort = errors.New("Port number is not a valid integer")
) )
const ( const (
@ -37,14 +33,16 @@ const (
) )
// Config contains the experiment config. // Config contains the experiment config.
type Config struct { type Config struct{}
type RuntimeConfig struct {
host string host string
port string port string
forced_tls bool forced_tls bool
noop_count uint8 noop_count uint8
} }
func config(input model.MeasurementTarget) (*Config, error) { func config(input model.MeasurementTarget) (*RuntimeConfig, error) {
if input == "" { if input == "" {
// TODO: static input data (eg. gmail/riseup..) // TODO: static input data (eg. gmail/riseup..)
return nil, errNoInputProvided return nil, errNoInputProvided
@ -68,16 +66,11 @@ func config(input model.MeasurementTarget) (*Config, error) {
port = "465" port = "465"
} }
} else { } else {
// Check that requested port is a valid integer // Valid port is checked by URL parsing
_, err := strconv.Atoi(parsed.Port())
if err != nil {
return nil, errInvalidPort
} else {
port = parsed.Port() port = parsed.Port()
} }
}
valid_config := Config{ valid_config := RuntimeConfig{
host: parsed.Hostname(), host: parsed.Hostname(),
forced_tls: parsed.Scheme == "smtps", forced_tls: parsed.Scheme == "smtps",
port: port, port: port,
@ -321,7 +314,6 @@ func (m Measurer) Run(
ctx context.Context, sess model.ExperimentSession, ctx context.Context, sess model.ExperimentSession,
measurement *model.Measurement, callbacks model.ExperimentCallbacks, measurement *model.Measurement, callbacks model.ExperimentCallbacks,
) error { ) error {
log := sess.Logger() log := sess.Logger()
trace := measurexlite.NewTrace(0, measurement.MeasurementStartTimeSaved) trace := measurexlite.NewTrace(0, measurement.MeasurementStartTimeSaved)
@ -372,7 +364,7 @@ func (m Measurer) Run(
} }
// Try EHLO + NoOps // Try EHLO + NoOps
if !tcp_session.smtp("localhost", 10) { if !tcp_session.smtp("localhost", config.noop_count) {
continue continue
} }
} else { } else {
@ -386,7 +378,7 @@ func (m Measurer) Run(
continue continue
} }
if !tcp_session.smtp("localhost", 10) { if !tcp_session.smtp("localhost", config.noop_count) {
continue continue
} }
} }