feat: 1.4.3 Tor lists and classification, egress provider and peer allowlist
Release / Publish tags (push) Successful in 17s
Release / Plan (reuse the published image?) (push) Successful in 6s
Release / ci (push) Successful in 59s
Release / Build image (amd64) (push) Successful in 24s
Release / Build image (arm64) (push) Successful in 1m29s
CI / Format and vet (push) Successful in 26s
CI / Tests (Linux, race detector) (push) Successful in 33s
CI / Dependency audit (push) Successful in 33s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 4s
Release / Publish tags (push) Successful in 17s
Release / Plan (reuse the published image?) (push) Successful in 6s
Release / ci (push) Successful in 59s
Release / Build image (amd64) (push) Successful in 24s
Release / Build image (arm64) (push) Successful in 1m29s
CI / Format and vet (push) Successful in 26s
CI / Tests (Linux, race detector) (push) Successful in 33s
CI / Dependency audit (push) Successful in 33s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 4s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec46fb94ff
commit
045ed53e43
15 files changed
+584
-25
No files matched your search
@@ -0,0 +1,110 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/netip"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/intel"
|
||||
)
|
||||
|
||||
func TestParseTorLists(t *testing.T) {
|
||||
got := ParseTorExitList(strings.NewReader("1.2.3.4\n# c\nlixo\n2001:db8::1 # x\n999.1.1.1\n::ffff:5.6.7.8\n"))
|
||||
if len(got) != 3 || got[2].String() != "5.6.7.8" {
|
||||
t.Fatalf("exits: %v", got)
|
||||
}
|
||||
js := `{"relays":[{"or_addresses":["10.1.1.1:9001","[2001:db8::2]:443","junk"],"exit_addresses":["10.1.1.2"]},{"or_addresses":[]}]}`
|
||||
a, err := ParseOnionoo(strings.NewReader(js))
|
||||
if err != nil || len(a) != 3 || a[1].String() != "2001:db8::2" {
|
||||
t.Fatalf("onionoo: %v %v", a, err)
|
||||
}
|
||||
if _, err := ParseOnionoo(strings.NewReader("<html>")); err == nil {
|
||||
t.Fatal("garbage must fail")
|
||||
}
|
||||
// the size limit truncates the input: broken JSON, an error
|
||||
if _, err := ParseOnionoo(strings.NewReader(`{"relays":[{"or_addresses":["1.1.1.1:1"]}` + strings.Repeat(" ", maxTorList+10) + `]}`)); err == nil {
|
||||
t.Fatal("oversize must fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRefreshTorListsCache(t *testing.T) {
|
||||
hits := 0
|
||||
fail := false
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
hits++
|
||||
if fail || r.Header.Get("User-Agent") != "urutau" {
|
||||
http.Error(w, "x", 500)
|
||||
return
|
||||
}
|
||||
if r.URL.Path == "/exit" {
|
||||
w.Write([]byte("198.51.100.1\n"))
|
||||
return
|
||||
}
|
||||
w.Write([]byte(`{"relays":[{"or_addresses":["198.51.100.2:9001"]}]}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
defer torLists.setManual(nil)
|
||||
defer torLists.setAuto([]netip.Addr{}, []netip.Addr{})
|
||||
dir := filepath.Join(t.TempDir(), "tor")
|
||||
log := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
||||
ctx := context.Background()
|
||||
refreshTorLists(ctx, dir, srv.URL+"/exit", srv.URL+"/relays", time.Hour, log)
|
||||
if !intel.IsTorExit(netip.MustParseAddr("198.51.100.1")) || !intel.IsTorRelay(netip.MustParseAddr("198.51.100.2")) || hits != 2 {
|
||||
t.Fatalf("lists not loaded, hits=%d", hits)
|
||||
}
|
||||
refreshTorLists(ctx, dir, srv.URL+"/exit", srv.URL+"/relays", time.Hour, log) // fresh cache: no download
|
||||
if hits != 2 {
|
||||
t.Fatalf("cache ignored: %d", hits)
|
||||
}
|
||||
torLists.setAuto([]netip.Addr{}, []netip.Addr{})
|
||||
fail = true
|
||||
refreshTorLists(ctx, dir, srv.URL+"/exit", srv.URL+"/relays", 0, log) // stale + failing: the cache serves
|
||||
if !intel.IsTorExit(netip.MustParseAddr("198.51.100.1")) || !intel.IsTorRelay(netip.MustParseAddr("198.51.100.2")) {
|
||||
t.Fatal("fallback to cache failed")
|
||||
}
|
||||
// the manual list coexists
|
||||
torLists.setManual([]netip.Addr{netip.MustParseAddr("203.0.113.9")})
|
||||
if !intel.IsTorExit(netip.MustParseAddr("203.0.113.9")) || !intel.IsTorExit(netip.MustParseAddr("198.51.100.1")) {
|
||||
t.Fatal("manual + auto merge failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetTypeTorEntry(t *testing.T) {
|
||||
a := netip.MustParseAddr("198.51.100.5")
|
||||
intel.SetTorExits([]netip.Addr{a})
|
||||
defer intel.SetTorExits(nil)
|
||||
if typ, _ := intel.NetTypeIP(a, 0, "", ""); typ != "tor" {
|
||||
t.Fatal(typ)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEgressOwnAllowAndProvider(t *testing.T) {
|
||||
if got := providerASNs("31898, AS47583,x", nil); len(got) != 2 || got[0] != "AS31898" || got[1] != "AS47583" {
|
||||
t.Fatalf("%v", got)
|
||||
}
|
||||
ps := ownPublicPrefixes()
|
||||
for _, p := range ps {
|
||||
if p.Addr().IsPrivate() || p.Addr().IsLoopback() {
|
||||
t.Fatal(p)
|
||||
}
|
||||
}
|
||||
// the peer has no URUTAU_PEERS: URUTAU_TRUSTED carries both servers, and a
|
||||
// bad item does not discard the others
|
||||
al := egressAllow(Config{Trusted: "136.248.78.83,lixo,195.200.0.252/32"})
|
||||
for _, ipS := range []string{"136.248.78.83", "195.200.0.252"} {
|
||||
ok := false
|
||||
for _, p := range al {
|
||||
ok = ok || p.Contains(netip.MustParseAddr(ipS))
|
||||
}
|
||||
if !ok {
|
||||
t.Fatal("not allowed: ", ipS)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user