cli: add support for passing proxy command line parameter (#981)

This implements the bare minimum needed to have circumvention proxy support in OONI Probe CLI.

The reference issue is https://github.com/ooni/probe/issues/1955. (Most of that issue is implemented, save for the fact that currently we do not have support for `http` and `https` proxies.)

While there, add to `Makefile` a rule for correctly building `ooniprobe` and `miniooni` for "this system" (i.e., the default `GOOS` and `GOARCH` on a system), because we needed this for testing this patch and we needed to figure out the commands instead.
This commit is contained in:
Arturo Filastò
2022-11-15 09:55:05 +01:00
committed by GitHub
parent 9750032639
commit d6def35286
6 changed files with 66 additions and 5 deletions
+11 -2
View File
@@ -4,6 +4,7 @@ import (
"context"
_ "embed" // because we embed a file
"io/ioutil"
"net/url"
"os"
"os/signal"
"syscall"
@@ -62,6 +63,7 @@ type Probe struct {
softwareName string
softwareVersion string
proxyURL *url.URL
}
// SetIsBatch sets the value of isBatch.
@@ -124,7 +126,7 @@ func (p *Probe) ListenForSignals() {
// MaybeListenForStdinClosed will treat any error on stdin just
// like SIGTERM if and only if
//
// os.Getenv("OONI_STDIN_EOF_IMPLIES_SIGTERM") == "true"
// os.Getenv("OONI_STDIN_EOF_IMPLIES_SIGTERM") == "true"
//
// When this feature is enabled, a collateral effect is that we swallow
// whatever is passed to us on the standard input.
@@ -151,7 +153,7 @@ func (p *Probe) MaybeListenForStdinClosed() {
}
// Init the OONI manager
func (p *Probe) Init(softwareName, softwareVersion string) error {
func (p *Probe) Init(softwareName, softwareVersion, proxy string) error {
var err error
if err = MaybeInitializeHome(p.home); err != nil {
@@ -197,6 +199,12 @@ func (p *Probe) Init(softwareName, softwareVersion string) error {
p.softwareName = softwareName
p.softwareVersion = softwareVersion
if proxy != "" {
p.proxyURL, err = url.Parse(proxy)
if err != nil {
return errors.Wrap(err, "invalid proxy URL")
}
}
return nil
}
@@ -228,6 +236,7 @@ func (p *Probe) NewSession(ctx context.Context, runType model.RunType) (*engine.
SoftwareVersion: p.softwareVersion,
TempDir: p.tempDir,
TunnelDir: p.tunnelDir,
ProxyURL: p.proxyURL,
})
}
+1 -1
View File
@@ -17,7 +17,7 @@ func TestInit(t *testing.T) {
probe := NewProbe("", ooniHome)
swName := "ooniprobe-cli-tests"
swVersion := "3.0.0-alpha"
if err := probe.Init(swName, swVersion); err != nil {
if err := probe.Init(swName, swVersion, ""); err != nil {
t.Error(err)
t.Fatal("failed to init the context")
}