Kill Tor once the unit tests have finsihed
the build was successful Details

This commit is contained in:
Sarah Jamie Lewis 2020-06-29 13:25:26 -07:00
parent a8d31e2adb
commit 3888ece4d3
3 changed files with 14 additions and 3 deletions

View File

@ -35,6 +35,7 @@ pipeline:
- ./tmp/tor -f ./testing/torrc - ./tmp/tor -f ./testing/torrc
- sleep 15 - sleep 15
- sh testing/tests.sh - sh testing/tests.sh
- pkill -9 tor
integration-tests: integration-tests:
when: when:
repo: openprivacy/connectivity repo: openprivacy/connectivity

View File

@ -10,7 +10,9 @@ import (
func TestLaunchTor(t *testing.T) { func TestLaunchTor(t *testing.T) {
log.SetLevel(log.LevelDebug) log.SetLevel(log.LevelDebug)
err := tor.GenerateTorrc("examplehashedpassword", "../tmp/torrc") // Create the tor data directory if it doesn't already exist..
os.MkdirAll("../tmp/data/tor", 0700)
err := tor.GenerateTorrc("examplehashedpassword", "../tmp/data/tor/torrc")
if err != nil { if err != nil {
t.Fatalf("failed to create torrc file: %v", err) t.Fatalf("failed to create torrc file: %v", err)

View File

@ -3,6 +3,7 @@ package tor
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"git.openprivacy.ca/openprivacy/connectivity" "git.openprivacy.ca/openprivacy/connectivity"
"git.openprivacy.ca/openprivacy/log" "git.openprivacy.ca/openprivacy/log"
"github.com/cretz/bine/control" "github.com/cretz/bine/control"
@ -282,9 +283,16 @@ func startTor(appDirectory string, bundledTorPath string, controlPort int, authe
} }
} }
log.Debugf("launching system tor\n") log.Debugf("launching system tor\n")
// check if the torrc file is present where expected
if _, err := os.Stat(path.Join(dataDir, "torrc")); os.IsNotExist(err) {
log.Debugf("torrc file does not exist at %v", path.Join(dataDir, "torrc"))
return nil, fmt.Errorf("torrc file does not exist at %v", path.Join(dataDir, "torrc"))
}
// if not, try running system tor // if not, try running system tor
if checkCmdlineTorVersion("tor") { if checkCmdlineTorVersion("tor") {
t, err := tor.Start(nil, &tor.StartConf{EnableNetwork: true, DataDir: dataDir, TorrcFile: "torrc", DebugWriter: nil, ProcessCreator: newHideCmd("tor")}) t, err := tor.Start(nil, &tor.StartConf{EnableNetwork: true, DataDir: dataDir, TorrcFile: path.Join(dataDir, "torrc"), DebugWriter: nil, ProcessCreator: newHideCmd("tor")})
if err == nil { if err == nil {
tp.t = t tp.t = t
return tp, nil return tp, nil
@ -296,7 +304,7 @@ func startTor(appDirectory string, bundledTorPath string, controlPort int, authe
// try running bundledTor // try running bundledTor
if bundledTorPath != "" && checkCmdlineTorVersion(bundledTorPath) { if bundledTorPath != "" && checkCmdlineTorVersion(bundledTorPath) {
log.Debugln("using bundled tor '" + bundledTorPath + "'") log.Debugln("using bundled tor '" + bundledTorPath + "'")
t, err := tor.Start(nil, &tor.StartConf{EnableNetwork: true, DataDir: dataDir, TorrcFile: "torrc", ExePath: bundledTorPath, DebugWriter: nil, ProcessCreator: newHideCmd(bundledTorPath)}) t, err := tor.Start(nil, &tor.StartConf{EnableNetwork: true, DataDir: dataDir, TorrcFile: path.Join(dataDir, "torrc"), ExePath: bundledTorPath, DebugWriter: nil, ProcessCreator: newHideCmd(bundledTorPath)})
if err != nil { if err != nil {
log.Debugf("Error running bundled tor: %v\n", err) log.Debugf("Error running bundled tor: %v\n", err)
} }