-
Notifications
You must be signed in to change notification settings - Fork 2
/
resolver_test.go
55 lines (47 loc) · 1.16 KB
/
resolver_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package hnsquery
import (
"context"
"fmt"
lru "github.com/hashicorp/golang-lru"
"github.com/imperviousinc/hnsquery/dnssec"
"github.com/miekg/dns"
"testing"
)
func TestNewResolver(t *testing.T) {
c, _ := lru.New(100)
called := false
r := &Resolver{
TrustAnchorFunc: func(ctx context.Context, cut string) (*dnssec.Zone, bool, error) {
if called {
t.Fatal("should only be called once")
return nil, false, nil
}
called = true
if cut == "." {
return nil, false, fmt.Errorf("failed")
}
if cut == "proofofconcept." {
z, err := dnssec.NewZone("proofofconcept.", nil)
return z, true, err
}
return nil, false, nil
},
zoneCuts: c,
exchangeTest: func(ctx context.Context, msg *dns.Msg) (*dns.Msg, error) {
t.Fatal("insecure zone shouldn't call exchange")
return nil, nil
},
}
_, err := r.Query(context.Background(), "_443._tcp.proofofconcept.", dns.TypeTLSA)
if err != nil {
t.Fatal(err)
}
_, err = r.getTrustAnchor(context.Background(), "proofofconcept.")
if err != nil {
t.Fatal(err)
}
_, err = r.Query(context.Background(), "_443._tcp.proofofconcept.", dns.TypeTLSA)
if err != nil {
t.Fatal(err)
}
}