-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server/proxy: allow customizing the DNS server (#3)
- Loading branch information
Showing
5 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package proxy | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/armon/go-socks5" | ||
) | ||
|
||
func TestCustomDNSServer(t *testing.T) { | ||
t.Parallel() | ||
dns := customDNSResolver{ServerIPs: []string{"1.1.1.1"}} | ||
_, ip, err := dns.Resolve(context.Background(), "google.com") | ||
if err != nil { | ||
t.Fatalf("unable to resolve with custom resolver: %v", err) | ||
} else if len(ip) == 0 { | ||
t.Fatalf("got zero ip: %s", ip) | ||
} | ||
} | ||
|
||
func TestCustomDNSServerMultiple(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Start with an invalid DNS server to ensure we try the second, valid one. | ||
dns := customDNSResolver{ServerIPs: []string{"127.127.127.127", "1.1.1.1"}} | ||
_, ip, err := dns.Resolve(context.Background(), "google.com") | ||
if err != nil { | ||
t.Fatalf("unable to resolve with custom resolver: %v", err) | ||
} else if len(ip) == 0 { | ||
t.Fatalf("got zero ip: %s", ip) | ||
} | ||
} | ||
|
||
func TestCustomDNSServerFallback(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Start with an invalid DNS server to ensure we try the fallback | ||
dns := customDNSResolver{ServerIPs: []string{"127.127.127.127"}, Fallback: socks5.DNSResolver{}} | ||
_, ip, err := dns.Resolve(context.Background(), "google.com") | ||
if err != nil { | ||
t.Fatalf("unable to resolve with custom resolver: %v", err) | ||
} else if len(ip) == 0 { | ||
t.Fatalf("got zero ip: %s", ip) | ||
} | ||
} |