From e6ca5516415bfdf43b8604d3cb31e50b70cf5d51 Mon Sep 17 00:00:00 2001 From: Lukas Metzger Date: Fri, 13 Apr 2018 17:13:53 +0200 Subject: [PATCH] Removed SOA from records --- backend/src/operations/Domains.php | 5 ++-- backend/src/operations/Records.php | 6 +++-- backend/test/db.sql | 3 ++- backend/test/tests/domain-soa.js | 4 +-- backend/test/tests/records-crud.js | 28 +++++++++---------- backend/test/tests/records-get.js | 43 +++++++++++++++++------------- 6 files changed, 49 insertions(+), 40 deletions(-) diff --git a/backend/src/operations/Domains.php b/backend/src/operations/Domains.php index a5c089f..1450981 100644 --- a/backend/src/operations/Domains.php +++ b/backend/src/operations/Domains.php @@ -84,7 +84,8 @@ class Domains FROM domains D LEFT OUTER JOIN records R ON D.id = R.domain_id LEFT OUTER JOIN permissions P ON D.id = P.domain_id - WHERE (P.user_id=:userId OR :userIsAdmin) + WHERE (P.user_id=:userId OR :userIsAdmin) AND + (R.type <> \'SOA\' OR R.type IS NULL) GROUP BY D.id HAVING (D.name LIKE :nameQuery) AND @@ -223,7 +224,7 @@ class Domains $query = $this->db->prepare(' SELECT D.id,D.name,D.type,D.master,COUNT(R.domain_id) AS records FROM domains D LEFT OUTER JOIN records R ON D.id = R.domain_id - WHERE D.id=:id + WHERE D.id=:id AND (R.type <> \'SOA\' OR R.type IS NULL) GROUP BY D.id,D.name,D.type,D.master '); $query->bindValue(':id', $id, \PDO::PARAM_INT); diff --git a/backend/src/operations/Records.php b/backend/src/operations/Records.php index c288e3e..77a3f85 100644 --- a/backend/src/operations/Records.php +++ b/backend/src/operations/Records.php @@ -72,7 +72,8 @@ class Records (R.domain_id IN ' . $setDomains . ' OR :noDomainFilter) AND (R.name LIKE :queryName) AND (R.type IN ' . $setTypes . ' OR :noTypeFilter) AND - (R.content LIKE :queryContent) + (R.content LIKE :queryContent) AND + R.type <> \'SOA\' '); $query->bindValue(':userId', $userId, \PDO::PARAM_INT); @@ -107,7 +108,8 @@ class Records (R.domain_id IN ' . $setDomains . ' OR :noDomainFilter) AND (R.name LIKE :queryName) AND (R.type IN ' . $setTypes . ' OR :noTypeFilter) AND - (R.content LIKE :queryContent) + (R.content LIKE :queryContent) AND + R.type <> \'SOA\' GROUP BY R.id' . $ordStr . $pageStr); $query->bindValue(':userId', $userId, \PDO::PARAM_INT); diff --git a/backend/test/db.sql b/backend/test/db.sql index 8c66df2..b71dd74 100644 --- a/backend/test/db.sql +++ b/backend/test/db.sql @@ -143,7 +143,8 @@ INSERT INTO `records` (`id`, `domain_id`, `name`, `type`, `content`, `ttl`, `pri (1, 1, 'test.example.com', 'A', '12.34.56.78', 86400, 0, 1521645110, 0, NULL, 1), (2, 1, 'sdfdf.example.com', 'TXT', 'foo bar baz', 60, 10, 1522321931, 0, NULL, 1), (3, 1, 'foo.example.com', 'AAAA', '::1', 86400, 0, 1522321902, 0, NULL, 1), -(4, 3, 'foo.de', 'A', '9.8.7.6', 86400, 0, 1522321989, 0, NULL, 1); +(4, 3, 'foo.de', 'A', '9.8.7.6', 86400, 0, 1522321989, 0, NULL, 1), +(5, 1, 'example.com', 'SOA', 'ns1.example.com hostmaster.example.com 2018041300 3600 900 604800 86400', 86400, NULL, 1523629358, 0, NULL, 1); -- -------------------------------------------------------- diff --git a/backend/test/tests/domain-soa.js b/backend/test/tests/domain-soa.js index e76f7f3..1a4b8bb 100644 --- a/backend/test/tests/domain-soa.js +++ b/backend/test/tests/domain-soa.js @@ -50,7 +50,7 @@ test.run(async function () { //Getting soa data from master zone without soa should fail var res = await req({ - url: '/domains/1/soa', + url: '/domains/4/soa', method: 'get' }); @@ -58,7 +58,7 @@ test.run(async function () { //Getting soa data from slave zone should fail var res = await req({ - url: '/domains/1/soa', + url: '/domains/2/soa', method: 'get' }); diff --git a/backend/test/tests/records-crud.js b/backend/test/tests/records-crud.js index 11116f5..6338637 100644 --- a/backend/test/tests/records-crud.js +++ b/backend/test/tests/records-crud.js @@ -78,7 +78,7 @@ test.run(async function () { assert.equal(res.status, 201, 'Adding of record should succeed.'); assert.equal(res.data, { - id: 5, + id: 6, name: 'dns.example.com', type: 'A', content: '1.2.3.4', @@ -97,13 +97,13 @@ test.run(async function () { //Get created record var res = await req({ - url: '/records/5', + url: '/records/6', method: 'get' }); assert.equal(res.status, 200, 'Get of created record should succeed.'); assert.equal(res.data, { - id: 5, + id: 6, name: 'dns.example.com', type: 'A', content: '1.2.3.4', @@ -115,7 +115,7 @@ test.run(async function () { //Update record var res = await req({ - url: '/records/5', + url: '/records/6', method: 'put', data: { name: 'foo.example.com' @@ -126,13 +126,13 @@ test.run(async function () { //Get updated record var res = await req({ - url: '/records/5', + url: '/records/6', method: 'get' }); assert.equal(res.status, 200, 'Get updated record should succeed.'); assert.equal(res.data, { - id: 5, + id: 6, name: 'foo.example.com', type: 'A', content: '1.2.3.4', @@ -151,7 +151,7 @@ test.run(async function () { //Delete existing record var res = await req({ - url: '/records/5', + url: '/records/6', method: 'delete' }); @@ -212,7 +212,7 @@ test.run(async function () { assert.equal(res.status, 201, 'Adding of record should succeed.'); assert.equal(res.data, { - id: 6, + id: 7, name: 'dns.example.com', type: 'A', content: '1.2.3.4', @@ -223,13 +223,13 @@ test.run(async function () { //Get created record var res = await req({ - url: '/records/6', + url: '/records/7', method: 'get' }); assert.equal(res.status, 200, 'Get of created record should succeed.'); assert.equal(res.data, { - id: 6, + id: 7, name: 'dns.example.com', type: 'A', content: '1.2.3.4', @@ -241,7 +241,7 @@ test.run(async function () { //Update record var res = await req({ - url: '/records/6', + url: '/records/7', method: 'put', data: { name: 'foo.example.com', @@ -253,13 +253,13 @@ test.run(async function () { //Get updated record var res = await req({ - url: '/records/6', + url: '/records/7', method: 'get' }); assert.equal(res.status, 200, 'Get updated record should succeed.'); assert.equal(res.data, { - id: 6, + id: 7, name: 'foo.example.com', type: 'A', content: '1.2.3.4', @@ -270,7 +270,7 @@ test.run(async function () { //Delete existing record var res = await req({ - url: '/records/6', + url: '/records/7', method: 'delete' }); diff --git a/backend/test/tests/records-get.js b/backend/test/tests/records-get.js index 83ca869..01b8c58 100644 --- a/backend/test/tests/records-get.js +++ b/backend/test/tests/records-get.js @@ -38,6 +38,8 @@ test.run(async function () { }); assert.equal(res.data.results, sortedData, 'Sort failed for ' + res.config.url); + + assert.equal(res.data.results.filter((i) => i.type === 'SOA').length, 0, 'No soa should be in records'); } //Test paging @@ -91,7 +93,8 @@ test.run(async function () { priority: 0, ttl: 86400, domain: 3 - }], 'Result fail for ' + res.config.url); + }, + ], 'Result fail for ' + res.config.url); //Type filter var res = await req({ @@ -126,24 +129,26 @@ test.run(async function () { }); assert.equal(res.status, 200, 'Status should be OK'); - assert.equal(res.data.results, [{ - id: 1, - name: 'test.example.com', - type: 'A', - content: '12.34.56.78', - priority: 0, - ttl: 86400, - domain: 1 - }, - { - id: 4, - name: 'foo.de', - type: 'A', - content: '9.8.7.6', - priority: 0, - ttl: 86400, - domain: 3 - }], 'Result fail for ' + res.config.url); + assert.equal(res.data.results, [ + { + id: 1, + name: 'test.example.com', + type: 'A', + content: '12.34.56.78', + priority: 0, + ttl: 86400, + domain: 1 + }, + { + id: 4, + name: 'foo.de', + type: 'A', + content: '9.8.7.6', + priority: 0, + ttl: 86400, + domain: 3 + } + ], 'Result fail for ' + res.config.url); }); await test('user', async function (assert, req) {