@@ -124,11 +124,10 @@ func TestLookupTXT(t *testing.T) {
124
124
})
125
125
defer resolver .Close ()
126
126
127
- r , err := NewResolver ("" )
127
+ r , err := NewResolver (resolver . URL )
128
128
if err != nil {
129
129
t .Fatal ("resolver cannot be initialised" )
130
130
}
131
- r .url = resolver .URL
132
131
133
132
txt , err := r .LookupTXT (context .Background (), domain )
134
133
if err != nil {
@@ -156,11 +155,10 @@ func TestLookupCache(t *testing.T) {
156
155
defer resolver .Close ()
157
156
158
157
const cacheTTL = time .Second
159
- r , err := NewResolver ("" , WithMaxCacheTTL (cacheTTL ))
158
+ r , err := NewResolver (resolver . URL , WithMaxCacheTTL (cacheTTL ))
160
159
if err != nil {
161
160
t .Fatal ("resolver cannot be initialised" )
162
161
}
163
- r .url = resolver .URL
164
162
165
163
txt , err := r .LookupTXT (context .Background (), domain )
166
164
if err != nil {
@@ -190,6 +188,34 @@ func TestLookupCache(t *testing.T) {
190
188
}
191
189
}
192
190
191
+ func TestCleartextRemoteEndpoint (t * testing.T ) {
192
+ // use remote endpoint over http and not https
193
+ _ , err := NewResolver ("http://cloudflare-dns.com/dns-query" )
194
+ if err == nil {
195
+ t .Fatal ("using remote DoH endpoint over unencrypted http:// expected should produce error, but expected error was not returned" )
196
+ }
197
+ }
198
+
199
+ func TestCleartextLocalhostEndpoint (t * testing.T ) {
200
+ testCases := []struct { hostname string }{
201
+ {hostname : "localhost" },
202
+ {hostname : "localhost:8080" },
203
+ {hostname : "127.0.0.1" },
204
+ {hostname : "127.0.0.1:8080" },
205
+ {hostname : "[::1]" },
206
+ {hostname : "[::1]:8080" },
207
+ }
208
+ for _ , tc := range testCases {
209
+ t .Run (tc .hostname , func (t * testing.T ) {
210
+ // use local endpoint over http and not https
211
+ _ , err := NewResolver ("http://" + tc .hostname + "/dns-query" )
212
+ if err != nil {
213
+ t .Fatalf ("using %q DoH endpoint over unencrypted http:// expected to work, but unexpected error was returned instead" , tc .hostname )
214
+ }
215
+ })
216
+ }
217
+ }
218
+
193
219
func sameIPs (a , b []net.IPAddr ) bool {
194
220
if len (a ) != len (b ) {
195
221
return false
0 commit comments