Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,50 @@ func TestLimitResolver(t *testing.T) {
t.Fatalf("expected %d, got %d", maxResolvedAddrs, len(addrs))
}
}

func FuzzResolver(f *testing.F) {
addrs := []string{
"/tcp/1234/dns6/example.com",
"/dns/example.com",
"/dnsaddr/example.com/tcp/123",
"/dnsaddr/example.com/tcp/789/http",
"/dnsaddr/matching.com/tcp/789/http",
"/dnsaddr/example.com/quic/quic/quic/quic",
"/dns4/example.com/udp/789/quic/dns6/example.com",
"/dns6/example.com/udp/1234/quic-v1",
"/quic/dns4/example.com/dns6/example.com/http",
}
resolves := []string{
"/tcp/123",
"/tcp/789/http",
"/tcp/1234/dns6/example.com",
"dnsaddr=/foobar",
"dnsaddr=/dns/example.com",
"dnsaddr=/dns/matching.com/tcp/456",
"dnsaddr=/dns/foobar",
}
for _, a := range addrs {
for _, b := range resolves {
ma.StringCast(a)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this?

f.Add(a, b)
}
}
f.Fuzz(func(t *testing.T, data, txt string) {
mock := &MockResolver{
IP: map[string][]net.IPAddr{
"example.com": {ip4a, ip4b, ip6a, ip6b},
},
TXT: map[string][]string{
"_dnsaddr.example.com": {txta, txtb, txt},
"_dnsaddr.matching.com": {txt, txtc, txtd, txte, "not a dnsaddr",
"dnsaddr=/foobar"},
Comment on lines +425 to +426
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dnsaddr=/foobar" is in the resolves list, so you don't need it here explicitly.

},
}
resolver := &Resolver{def: mock}
addr, err := ma.NewMultiaddr(data)
if err != nil {
return
}
resolver.Resolve(context.Background(), addr)
})
}
3 changes: 3 additions & 0 deletions testdata/fuzz/FuzzResolver/a7a3289acbd32019
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go test fuzz v1
string("/dnsaddr/matching.com/tcp/0")
string("dnsaddr=/tcp/0")
Loading