Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth 4.9 API: when querying with rrset_name, respect it for comments too #14675

Open
wants to merge 1 commit into
base: rel/auth-4.9.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 9 additions & 7 deletions pdns/ws-auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -445,21 +445,21 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons
vector<DNSResourceRecord> records;
vector<Comment> comments;

QType qType = QType::ANY;
DNSName qName;

// load all records + sort
{
DNSResourceRecord resourceRecord;
if (req->getvars.count("rrset_name") == 0) {
domainInfo.backend->list(zonename, static_cast<int>(domainInfo.id), true); // incl. disabled
}
else {
QType qType;
if (req->getvars.count("rrset_type") == 0) {
qType = QType::ANY;
}
else {
qName = DNSName(req->getvars["rrset_name"]);
if (req->getvars.count("rrset_type") != 0) {
qType = req->getvars["rrset_type"];
}
domainInfo.backend->lookup(qType, DNSName(req->getvars["rrset_name"]), static_cast<int>(domainInfo.id));
domainInfo.backend->lookup(qType, qName, static_cast<int>(domainInfo.id));
}
while (domainInfo.backend->get(resourceRecord)) {
if (resourceRecord.qtype.getCode() == 0) {
Expand All @@ -483,7 +483,9 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons
Comment comment;
domainInfo.backend->listComments(domainInfo.id);
while (domainInfo.backend->getComment(comment)) {
comments.push_back(comment);
if ((qName.empty() || comment.qname == qName) && (qType == QType::ANY || comment.qtype == qType)) {
comments.push_back(comment);
}
}
sort(comments.begin(), comments.end(), [](const Comment& rrA, const Comment& rrB) {
/* if you ever want to update this comparison function,
Expand Down
22 changes: 18 additions & 4 deletions regression-tests.api/test_Zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,7 @@ def test_zone_delete(self):

def test_zone_comment_create(self):
name, payload, zone = self.create_zone()
rrset = {
rrset1 = {
'changetype': 'replace',
'name': name,
'type': 'NS',
Expand All @@ -1951,7 +1951,19 @@ def test_zone_comment_create(self):
}
]
}
payload = {'rrsets': [rrset]}
rrset2 = {
'changetype': 'replace',
'name': name,
'type': 'SOA',
'ttl': 3600,
'comments': [
{
'account': 'test3',
'content': 'this should not show up later'
}
]
}
payload = {'rrsets': [rrset1, rrset2]}
r = self.session.patch(
self.url("/api/v1/servers/localhost/zones/" + name),
data=json.dumps(payload),
Expand All @@ -1963,13 +1975,15 @@ def test_zone_comment_create(self):
self.assert_success(r)
# make sure the comments have been set, and that the NS
# records are still present
data = self.get_zone(name)
data = self.get_zone(name, rrset_name=name, rrset_type="NS")
serverset = get_rrset(data, name, 'NS')
print(serverset)
self.assertNotEqual(serverset['records'], [])
self.assertNotEqual(serverset['comments'], [])
# verify that modified_at has been set by pdns
self.assertNotEqual([c for c in serverset['comments']][0]['modified_at'], 0)
# verify that unrelated comments do not leak into the result
self.assertEqual(get_rrset(data, name, 'SOA'), None)
# verify that TTL is correct (regression test)
self.assertEqual(serverset['ttl'], 3600)

Expand Down Expand Up @@ -1997,7 +2011,7 @@ def test_zone_comment_delete(self):

@unittest.skipIf(is_auth_lmdb(), "No comments in LMDB")
def test_zone_comment_out_of_range_modified_at(self):
# Test if comments on an rrset stay intact if the rrset is replaced
# Test if a modified_at outside of the 32 bit range throws an error
name, payload, zone = self.create_zone()
rrset = {
'changetype': 'replace',
Expand Down