Skip to content

Commit

Permalink
JSON API: uppercase types
Browse files Browse the repository at this point in the history
We never promised that types can be in lowercase, but given we're
interpreting them as TYPE0 instead of flat-out failing, let's be nicer.
  • Loading branch information
zeha committed Jan 25, 2015
1 parent cc59bce commit b53ef2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pdns/ws-auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ static void gatherRecords(const Value& container, vector<DNSResourceRecord>& new
for (SizeType idx = 0; idx < records.Size(); ++idx) {
const Value& record = records[idx];
rr.qname = stringFromJson(record, "name");
rr.qtype = stringFromJson(record, "type");
rr.qtype = toUpper(stringFromJson(record, "type"));
rr.content = stringFromJson(record, "content");
rr.auth = 1;
rr.ttl = intFromJson(record, "ttl");
Expand Down Expand Up @@ -429,7 +429,7 @@ static void gatherComments(const Value& container, vector<Comment>& new_comments
Comment c;
if (use_name_type_from_container) {
c.qname = stringFromJson(container, "name");
c.qtype = stringFromJson(container, "type");
c.qtype = toUpper(stringFromJson(container, "type"));
}

time_t now = time(0);
Expand All @@ -439,7 +439,7 @@ static void gatherComments(const Value& container, vector<Comment>& new_comments
const Value& comment = comments[idx];
if (!use_name_type_from_container) {
c.qname = stringFromJson(comment, "name");
c.qtype = stringFromJson(comment, "type");
c.qtype = toUpper(stringFromJson(comment, "type"));
}
c.modified_at = intFromJson(comment, "modified_at", now);
c.content = stringFromJson(comment, "content");
Expand Down Expand Up @@ -920,7 +920,7 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) {
string qname, changetype;
QType qtype;
qname = stringFromJson(rrset, "name");
qtype = stringFromJson(rrset, "type");
qtype = toUpper(stringFromJson(rrset, "type"));
changetype = toUpper(stringFromJson(rrset, "changetype"));

if (!iends_with(qname, dotsuffix) && !pdns_iequals(qname, zonename))
Expand Down
9 changes: 6 additions & 3 deletions regression-tests.api/test_Zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ def test_create_zone_with_comments(self):
comments = [
{
'name': name,
'type': 'SOA',
'type': 'soa', # test uppercasing of type, too.
'account': 'test1',
'content': 'blah blah',
'modified_at': 11112,
}
]
payload, data = self.create_zone(name=name, comments=comments)
comments[0]['type'] = comments[0]['type'].upper()
# check our comment has appeared
self.assertEquals(data['comments'], comments)

Expand All @@ -110,13 +111,14 @@ def test_create_zone_with_custom_soa(self):
records = [
{
"name": name,
"type": "SOA",
'type': 'soa', # test uppercasing of type, too.
"ttl": 3600,
"content": "ns1.example.net testmaster@example.net 10 10800 3600 604800 3600",
"disabled": False
}
]
payload, data = self.create_zone(name=name, records=records)
records[0]['type'] = records[0]['type'].upper()
self.assertEquals([r for r in data['records'] if r['type'] == records[0]['type']], records)

def test_create_zone_trailing_dot(self):
Expand Down Expand Up @@ -430,7 +432,7 @@ def test_zone_rr_update(self):
rrset = {
'changetype': 'replace',
'name': name,
'type': 'NS',
'type': 'ns',
'records': [
{
"name": name,
Expand All @@ -456,6 +458,7 @@ def test_zone_rr_update(self):
self.assert_success_json(r)
# verify that (only) the new record is there
r = self.session.get(self.url("/servers/localhost/zones/" + name))
rrset['type'] = rrset['type'].upper()
data = r.json()['records']
recs = [rec for rec in data if rec['type'] == rrset['type'] and rec['name'] == rrset['name']]
self.assertEquals(recs, rrset['records'])
Expand Down

0 comments on commit b53ef2e

Please sign in to comment.