Skip to content

Commit

Permalink
lint/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phillip-stephens committed Dec 16, 2024
1 parent 2882d83 commit 6b6e93d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/zdns/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ func (r *Resolver) LookupAllNameserversIterative(q *Question, rootNameServers []
currentLayerNameServers = append(currentLayerNameServers, newNameServers...)
break
}
if len(newNameServers) == 0 {
// we have no more nameservers to query, error
return &retv, trace, StatusError, errors.Errorf("no nameservers found for layer %s", currentLayer)
}
currentLayerNameServers = newNameServers
currentLayer = newLayer
}
Expand Down
46 changes: 42 additions & 4 deletions src/zdns/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1532,9 +1532,6 @@ func TestAllNsLookupOneNsThreeLevels(t *testing.T) {
exampleNSServerIP := "3.3.3.3"
exampleNameAAnswer := "4.4.4.4"

//ns1 := &config.ExternalNameServersV4[0]
//ipv4_1 := "127.0.0.2"

mockResults[nameAndIP{name: exampleName, IP: rootServerIP + ":53"}] = SingleQueryResult{
Authorities: []interface{}{
Answer{
Expand Down Expand Up @@ -1597,6 +1594,7 @@ func TestAllNsLookupOneNsThreeLevels(t *testing.T) {
{
Status: StatusNoError,
Nameserver: rootServer,
Type: "NS",
Res: SingleQueryResult{
Authorities: []interface{}{
Answer{
Expand Down Expand Up @@ -1624,6 +1622,7 @@ func TestAllNsLookupOneNsThreeLevels(t *testing.T) {
"com": {
{
Status: StatusNoError,
Type: "NS",
Nameserver: comServer,
Res: SingleQueryResult{
Authorities: []interface{}{
Expand Down Expand Up @@ -1652,6 +1651,24 @@ func TestAllNsLookupOneNsThreeLevels(t *testing.T) {
"example.com": {
{
Status: StatusNoError,
Type: "NS",
Nameserver: exampleNSServer,
Res: SingleQueryResult{
Answers: []interface{}{
Answer{
TTL: 3600,
Type: "A",
RrType: dns.TypeA,
Class: "IN",
Name: "example.com.",
Answer: "4.4.4.4",
},
},
},
},
{
Status: StatusNoError,
Type: "A",
Nameserver: exampleNSServer,
Res: SingleQueryResult{
Answers: []interface{}{
Expand Down Expand Up @@ -1780,6 +1797,7 @@ func TestAllNsLookupErrorInOne(t *testing.T) {
".": {
{
Status: StatusNoError,
Type: "NS",
Nameserver: rootServer,
Res: SingleQueryResult{
Authorities: []interface{}{
Expand Down Expand Up @@ -1824,11 +1842,13 @@ func TestAllNsLookupErrorInOne(t *testing.T) {
"com": {
{
Status: StatusServFail,
Type: "NS",
Nameserver: comServerA,
Res: SingleQueryResult{},
},
{
Status: StatusNoError,
Type: "NS",
Nameserver: comServerB,
Res: SingleQueryResult{
Authorities: []interface{}{
Expand Down Expand Up @@ -1857,6 +1877,24 @@ func TestAllNsLookupErrorInOne(t *testing.T) {
"example.com": {
{
Status: StatusNoError,
Type: "NS",
Nameserver: exampleNSServer,
Res: SingleQueryResult{
Answers: []interface{}{
Answer{
TTL: 3600,
Type: "A",
RrType: dns.TypeA,
Class: "IN",
Name: "example.com.",
Answer: exampleNameAAnswer,
},
},
},
},
{
Status: StatusNoError,
Type: "A",
Nameserver: exampleNSServer,
Res: SingleQueryResult{
Answers: []interface{}{
Expand Down Expand Up @@ -1900,7 +1938,7 @@ func TestAllNsLookupNXDomain(t *testing.T) {
res, _, status, err := resolver.LookupAllNameserversIterative(&q, []NameServer{*ns1})

expectedResponse := map[string][]ExtendedResult{
".": {{Status: StatusNXDomain}},
".": {{Status: StatusNXDomain, Type: "NS"}},
}
if !reflect.DeepEqual(res.LayeredResponses, expectedResponse) {
t.Errorf("Expected %v, Received %v", expectedResponse, res.LayeredResponses)
Expand Down

0 comments on commit 6b6e93d

Please sign in to comment.