From 0c745e7691113898c23c13d8958912c6e3ebb212 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 13 Jan 2022 13:43:27 -0800 Subject: [PATCH] Adding Tests for GetInfo --- tor/torProvider.go | 4 ++++ tor/torProvider_test.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tor/torProvider.go b/tor/torProvider.go index a69254b..a43fe32 100644 --- a/tor/torProvider.go +++ b/tor/torProvider.go @@ -114,6 +114,10 @@ func (tp *torProvider) GetInfo(onion string) (map[string]string, error) { } } + if cirucitID == "" { + return nil, errors.New("could not find circuit") + } + var hops []string for _, circuit := range circuits { if circuit.Key == "circuit-status" { diff --git a/tor/torProvider_test.go b/tor/torProvider_test.go index e7104a1..1630bf4 100644 --- a/tor/torProvider_test.go +++ b/tor/torProvider_test.go @@ -43,6 +43,29 @@ func TestTorProvider(t *testing.T) { t.Logf("progress: %v", progress) } + // Test opening the OP Server + _, _, err = acn.Open("isbr2t6bflul2zyi6hjtnuezb2xvfr42svzjg2q3gyqfgg3wmnrbkkqd") + + if err == nil { + info, err := acn.GetInfo("isbr2t6bflul2zyi6hjtnuezb2xvfr42svzjg2q3gyqfgg3wmnrbkkqd") + if err != nil { + t.Fatalf("could not find info for OP server %v", err) + } + cinfo, exists := info["circuit"] + if !exists { + t.Fatalf("could not find circuit info for OP server %v", err) + } + t.Logf("Found Cicurit Info %v", cinfo) + + _, err = acn.GetInfo("not_a_real_onion") + if err == nil { + t.Fatalf("GetInfo for non existant onion should have errored") + } + + } else { + t.Fatalf("could not connect to OP server %v", err) + } + // Should skip without blocking... acn.Restart() acn.Restart()