2020-02-07 22:15:37 +00:00
|
|
|
package tor
|
2020-02-06 00:42:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-15 22:35:41 +00:00
|
|
|
"git.openprivacy.ca/openprivacy/log"
|
2022-01-10 20:51:21 +00:00
|
|
|
path "path/filepath"
|
2020-02-06 00:42:32 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getStatusCallback(progChan chan int) func(int, string) {
|
|
|
|
return func(prog int, status string) {
|
|
|
|
fmt.Printf("%v %v\n", prog, status)
|
|
|
|
progChan <- prog
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTorProvider(t *testing.T) {
|
|
|
|
progChan := make(chan int)
|
2020-10-15 22:35:41 +00:00
|
|
|
log.SetLevel(log.LevelDebug)
|
|
|
|
torpath := path.Join("..", "tmp/tor")
|
2022-01-10 20:51:21 +00:00
|
|
|
|
|
|
|
NewTorrc().WithControlPort(9051).WithHashedPassword("examplehashedpassword").Build(path.Join("..", "testing", "tor", "torrc"))
|
|
|
|
|
2020-10-15 22:35:41 +00:00
|
|
|
log.Debugf("setting tor path %v", torpath)
|
|
|
|
acn, err := NewTorACNWithAuth(path.Join("../testing/"), torpath, 9051, HashedPasswordAuthenticator{"examplehashedpassword"})
|
2020-02-06 00:42:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
acn.SetStatusCallback(getStatusCallback(progChan))
|
|
|
|
|
|
|
|
progress := 0
|
|
|
|
for progress < 100 {
|
|
|
|
progress = <-progChan
|
2020-10-15 22:35:41 +00:00
|
|
|
t.Logf("progress: %v", progress)
|
2020-02-06 00:42:32 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 18:53:44 +00:00
|
|
|
acn.Restart()
|
|
|
|
|
|
|
|
progress = 0
|
|
|
|
for progress < 100 {
|
|
|
|
progress = <-progChan
|
|
|
|
t.Logf("progress: %v", progress)
|
|
|
|
}
|
|
|
|
|
2021-04-13 20:39:33 +00:00
|
|
|
// Should skip without blocking...
|
|
|
|
acn.Restart()
|
|
|
|
acn.Restart()
|
|
|
|
acn.Restart()
|
|
|
|
|
2020-02-06 00:42:32 +00:00
|
|
|
acn.Close()
|
|
|
|
}
|