Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func mockQueryUpdate(t *testing.T, qname string, qtype uint16) (*dns.Msg, error)

func newResolver(t *testing.T) (res *Resolver) {
resolver, _ := NewResolver("./testdata/resolv.conf")

resolver.queryFn = func(qname string, qtype uint16) (*dns.Msg, error) {
msg := &dns.Msg{}
if isMockQuery == false {
Expand Down
20 changes: 20 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package goresolver

import (
"os"
"testing"
"time"
)

// TestMain sets a fixed current time so that DNSSEC signatures in
// archived fixture data remain valid during the tests.
func TestMain(m *testing.M) {
nowFunc = func() time.Time {
// 15 March 2019 00:00:00 UTC is within the validity period of
// all RRSIG records used in the fixture data.
return time.Date(2019, 3, 15, 0, 0, 0, 0, time.UTC)
}
code := m.Run()
nowFunc = time.Now
os.Exit(code)
}
7 changes: 6 additions & 1 deletion signedzone.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import (
"time"
)

// nowFunc returns the current time. It is a variable so
// tests can override it to ensure deterministic behaviour
// with archived DNS fixture data.
var nowFunc = time.Now

// SignedZone represents a DNSSEC-enabled zone, its DNSKEY and DS records
type SignedZone struct {
zone string
Expand Down Expand Up @@ -50,7 +55,7 @@ func (z SignedZone) verifyRRSIG(signedRRset *RRSet) (err error) {
return err
}

if !signedRRset.rrSig.ValidityPeriod(time.Now()) {
if !signedRRset.rrSig.ValidityPeriod(nowFunc()) {
log.Println("invalid validity period", err)
return ErrRrsigValidityPeriod
}
Expand Down
Loading