-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove MXLookup cache, add concept of caching lookups specific to a n…
…ameserver (#447) * add nameserver for cache * added basic cache unit tests * remove comments * use cache for both external/iterative lookups, vary whether to care about nses * added cache integration test for external lookups * remove mxlookup cache, use cache on external lookups specific to nameservers * added unit test, cleaned up lint errors * fix tests * commented cachedRetryingLookup * add details to print * adjusted constant to compare cached lookups * populate protocol/resolver on cache retrieval
- Loading branch information
1 parent
5dc707f
commit 6aa8a81
Showing
6 changed files
with
240 additions
and
56 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* ZDNS Copyright 2024 Regents of the University of Michigan | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
package zdns | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCheckForNonExistentKey(t *testing.T) { | ||
cache := Cache{} | ||
cache.Init(4096) | ||
_, found := cache.GetCachedResult(Question{1, 1, "google.com"}, nil, 0) | ||
assert.False(t, found, "Expected no cache entry") | ||
} | ||
|
||
func TestNoNameServerLookupSuccess(t *testing.T) { | ||
res := SingleQueryResult{ | ||
Answers: []interface{}{Answer{ | ||
TTL: 3600, | ||
RrType: 1, | ||
RrClass: 1, | ||
Name: "google.com.", | ||
Answer: "192.0.2.1", | ||
}}, | ||
Additional: nil, | ||
Authorities: nil, | ||
Protocol: "", | ||
Flags: DNSFlags{Authoritative: true}, | ||
} | ||
cache := Cache{} | ||
cache.Init(4096) | ||
cache.CacheUpdate(".", res, nil, 0, false) | ||
_, found := cache.GetCachedResult(Question{1, 1, "google.com."}, nil, 0) | ||
assert.True(t, found, "Expected cache entry") | ||
} | ||
|
||
func TestNoNameServerLookupForNamedNameServer(t *testing.T) { | ||
res := SingleQueryResult{ | ||
Answers: []interface{}{Answer{ | ||
TTL: 3600, | ||
RrType: 1, | ||
RrClass: 1, | ||
Name: "google.com.", | ||
Answer: "192.0.2.1", | ||
}}, | ||
Additional: nil, | ||
Authorities: nil, | ||
Protocol: "", | ||
Flags: DNSFlags{Authoritative: true}, | ||
} | ||
cache := Cache{} | ||
cache.Init(4096) | ||
cache.CacheUpdate(".", res, nil, 0, false) | ||
_, found := cache.GetCachedResult(Question{1, 1, "google.com."}, &NameServer{ | ||
IP: net.ParseIP("1.1.1.1"), | ||
Port: 53, | ||
}, 0) | ||
assert.False(t, found, "Cache has an answer from a generic nameserver, we wanted a specific one. Shouldn't be found.") | ||
} | ||
|
||
func TestNamedServerLookupForNonNamedNameServer(t *testing.T) { | ||
res := SingleQueryResult{ | ||
Answers: []interface{}{Answer{ | ||
TTL: 3600, | ||
RrType: 1, | ||
RrClass: 1, | ||
Name: "google.com.", | ||
Answer: "192.0.2.1", | ||
}}, | ||
Additional: nil, | ||
Authorities: nil, | ||
Protocol: "", | ||
Flags: DNSFlags{Authoritative: true}, | ||
} | ||
cache := Cache{} | ||
cache.Init(4096) | ||
cache.CacheUpdate(".", res, &NameServer{ | ||
IP: net.ParseIP("1.1.1.1"), | ||
Port: 53, | ||
}, 0, false) | ||
_, found := cache.GetCachedResult(Question{1, 1, "google.com."}, nil, 0) | ||
assert.False(t, found, "Cache has an answer from a named nameserver, we wanted a generic one. Shouldn't be found.") | ||
} | ||
|
||
func TestNamedServerLookupForNamedNameServer(t *testing.T) { | ||
res := SingleQueryResult{ | ||
Answers: []interface{}{Answer{ | ||
TTL: 3600, | ||
RrType: 1, | ||
RrClass: 1, | ||
Name: "google.com.", | ||
Answer: "192.0.2.1", | ||
}}, | ||
Additional: nil, | ||
Authorities: nil, | ||
Protocol: "", | ||
Flags: DNSFlags{Authoritative: true}, | ||
} | ||
cache := Cache{} | ||
cache.Init(4096) | ||
cache.CacheUpdate(".", res, &NameServer{ | ||
IP: net.ParseIP("1.1.1.1"), | ||
Port: 53, | ||
}, 0, false) | ||
_, found := cache.GetCachedResult(Question{1, 1, "google.com."}, &NameServer{ | ||
IP: net.ParseIP("1.1.1.1"), | ||
Port: 53, | ||
}, 0) | ||
assert.True(t, found, "Should be found") | ||
} | ||
|
||
func TestNoNameServerLookupNotAuthoritative(t *testing.T) { | ||
res := SingleQueryResult{ | ||
Answers: []interface{}{Answer{ | ||
TTL: 3600, | ||
RrType: 1, | ||
RrClass: 1, | ||
Name: "google.com.", | ||
Answer: "192.0.2.1", | ||
}}, | ||
Additional: nil, | ||
Authorities: nil, | ||
Protocol: "", | ||
Flags: DNSFlags{Authoritative: false}, | ||
} | ||
cache := Cache{} | ||
cache.Init(4096) | ||
cache.CacheUpdate(".", res, nil, 0, false) | ||
_, found := cache.GetCachedResult(Question{1, 1, "google.com."}, nil, 0) | ||
assert.False(t, found, "shouldn't cache non-authoritative answers") | ||
cache.CacheUpdate(".", res, nil, 0, true) | ||
_, found = cache.GetCachedResult(Question{1, 1, "google.com."}, nil, 0) | ||
assert.True(t, found, "should cache non-authoritative answers") | ||
} |
Oops, something went wrong.