From: Peter van Dijk Date: Thu, 14 Dec 2023 20:38:06 +0000 (+0100) Subject: auth: set catalog field in gsql getAllDomains X-Git-Tag: dnsdist-1.9.0-rc1~28^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0a3c1f00ab3f45beff8e05a5c1ed3309b908fad;p=thirdparty%2Fpdns.git auth: set catalog field in gsql getAllDomains --- diff --git a/modules/gmysqlbackend/gmysqlbackend.cc b/modules/gmysqlbackend/gmysqlbackend.cc index cd3d62595d..869f819db2 100644 --- a/modules/gmysqlbackend/gmysqlbackend.cc +++ b/modules/gmysqlbackend/gmysqlbackend.cc @@ -159,7 +159,7 @@ public: declare(suffix, "delete-tsig-key-query", "", "delete from tsigkeys where name=?"); declare(suffix, "get-tsig-keys-query", "", "select name,algorithm, secret from tsigkeys"); - declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR ?"); + declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account, domains.catalog from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR ?"); declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=?"); declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (?, ?, ?, ?, ?, ?)"); diff --git a/modules/godbcbackend/godbcbackend.cc b/modules/godbcbackend/godbcbackend.cc index f34e8beb11..83123d8b03 100644 --- a/modules/godbcbackend/godbcbackend.cc +++ b/modules/godbcbackend/godbcbackend.cc @@ -142,7 +142,7 @@ public: declare(suffix, "delete-tsig-key-query", "", "delete from tsigkeys where name=?"); declare(suffix, "get-tsig-keys-query", "", "select name,algorithm, secret from tsigkeys"); - declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR records.disabled=?"); + declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account, domains.catalog from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR records.disabled=?"); declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=?"); declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (?, ?, ?, ?, ?, ?)"); diff --git a/modules/gpgsqlbackend/gpgsqlbackend.cc b/modules/gpgsqlbackend/gpgsqlbackend.cc index c343855b16..f69828aeaf 100644 --- a/modules/gpgsqlbackend/gpgsqlbackend.cc +++ b/modules/gpgsqlbackend/gpgsqlbackend.cc @@ -166,7 +166,7 @@ public: declare(suffix, "delete-tsig-key-query", "", "delete from tsigkeys where name=$1"); declare(suffix, "get-tsig-keys-query", "", "select name,algorithm, secret from tsigkeys"); - declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=false OR $1"); + declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account, domains.catalog from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=false OR $1"); declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=$1"); declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES ($1, $2, $3, $4, $5, $6)"); diff --git a/modules/gsqlite3backend/gsqlite3backend.cc b/modules/gsqlite3backend/gsqlite3backend.cc index b67f4f0e59..829213d6c8 100644 --- a/modules/gsqlite3backend/gsqlite3backend.cc +++ b/modules/gsqlite3backend/gsqlite3backend.cc @@ -152,7 +152,7 @@ public: declare(suffix, "delete-tsig-key-query", "", "delete from tsigkeys where name=:key_name"); declare(suffix, "get-tsig-keys-query", "", "select name,algorithm, secret from tsigkeys"); - declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR :include_disabled"); + declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account, domains.catalog from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR :include_disabled"); declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=:domain_id"); declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (:domain_id, :qname, :qtype, :modified_at, :account, :content)"); diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index fcc5cc85d4..e746dd3763 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -1754,11 +1754,12 @@ void GSQLBackend::getAllDomains(vector* domains, bool getSerial, boo SSqlStatement::row_t row; while (d_getAllDomainsQuery_stmt->hasNextRow()) { d_getAllDomainsQuery_stmt->nextRow(row); - ASSERT_ROW_COLUMNS("get-all-domains-query", row, 8); + ASSERT_ROW_COLUMNS("get-all-domains-query", row, 9); DomainInfo di; pdns::checked_stoi_into(di.id, row[0]); try { di.zone = DNSName(row[1]); + di.catalog = (!row[8].empty() ? DNSName(row[8]) : DNSName()); } catch (...) { continue; } diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index 45ec5cee95..d769859896 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -90,7 +90,7 @@ class Zones(ApiTestCase): print(example_com) required_fields = ['id', 'url', 'name', 'kind'] if is_auth(): - required_fields = required_fields + ['masters', 'last_check', 'notified_serial', 'serial', 'account'] + required_fields = required_fields + ['masters', 'last_check', 'notified_serial', 'serial', 'account', 'catalog'] if dnssec: required_fields = required_fields = ['dnssec', 'edited_serial'] self.assertNotEqual(example_com['serial'], 0) @@ -237,6 +237,15 @@ class AuthZones(ApiTestCase, AuthZonesHelperMixin): if k in payload: self.assertEqual(data[k], payload[k]) + # check that the catalog is reflected in the /zones output (#13633) + r = self.session.get(self.url("/api/v1/servers/localhost/zones")) + self.assert_success_json(r) + domains = r.json() + domain = [domain for domain in domains if domain['name'] == name] + self.assertEqual(len(domain), 1) + domain = domain[0] + self.assertEqual(domain["catalog"], "catalog.invalid.") + def test_create_zone_with_account(self): # soa_edit_api wins over serial name, payload, data = self.create_zone(account='anaccount', serial=10, kind='Master') diff --git a/regression-tests/backends/godbc_sqlite3-master b/regression-tests/backends/godbc_sqlite3-master index 1a6074a357..0c6f3eab8a 100644 --- a/regression-tests/backends/godbc_sqlite3-master +++ b/regression-tests/backends/godbc_sqlite3-master @@ -30,7 +30,7 @@ godbc-delete-rrset-query=delete from records where domain_id=? and name=? and ty godbc-delete-tsig-key-query=delete from tsigkeys where name=? godbc-delete-zone-query=delete from records where domain_id=? godbc-get-all-domain-metadata-query=select kind,content from domains, domainmetadata where domainmetadata.domain_id=domains.id and name=? -godbc-get-all-domains-query=select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR ? +godbc-get-all-domains-query=select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account, domains.catalog from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR ? godbc-get-domain-metadata-query=select content from domains, domainmetadata where domainmetadata.domain_id=domains.id and name=? and domainmetadata.kind=? godbc-get-last-inserted-key-id-query=select last_insert_rowid() godbc-get-order-after-query=select min(ordername) from records where disabled=0 and ordername > ? and domain_id=? and ordername is not null