From f97e8a5b3f2609db89b6072237b727dddc3614dc Mon Sep 17 00:00:00 2001 From: Qian Chen Date: Wed, 5 Jan 2022 21:27:46 -0800 Subject: [PATCH] Added tests. --- lib/zonefile-es.js | 30 +- lib/zonefile.js | 29 +- package.json | 7 +- specs/tests.js | 353 --------- test/test.js | 36 - test/zonefile_forward.json | 118 --- test/zonefile_forward.txt | 45 -- test/zonefile_forward_srv.json | 89 --- test/zonefile_forward_srv.txt | 22 - test/zonefile_reverse.json | 21 - test/zonefile_reverse_ipv6.json | 21 - tests/tests.js | 718 ++++++++++++++++++ {specs => tests}/zonefile_forward.json | 0 {specs => tests}/zonefile_forward.txt | 0 tests/zonefile_reverse_ipv4.json | 67 ++ .../zonefile_reverse_ipv4.txt | 4 +- tests/zonefile_reverse_ipv6.json | 37 + {test => tests}/zonefile_reverse_ipv6.txt | 4 +- 18 files changed, 886 insertions(+), 715 deletions(-) delete mode 100644 specs/tests.js delete mode 100644 test/test.js delete mode 100644 test/zonefile_forward.json delete mode 100644 test/zonefile_forward.txt delete mode 100644 test/zonefile_forward_srv.json delete mode 100644 test/zonefile_forward_srv.txt delete mode 100644 test/zonefile_reverse.json delete mode 100644 test/zonefile_reverse_ipv6.json create mode 100644 tests/tests.js rename {specs => tests}/zonefile_forward.json (100%) rename {specs => tests}/zonefile_forward.txt (100%) create mode 100644 tests/zonefile_reverse_ipv4.json rename test/zonefile_reverse.txt => tests/zonefile_reverse_ipv4.txt (83%) create mode 100644 tests/zonefile_reverse_ipv6.json rename {test => tests}/zonefile_reverse_ipv6.txt (83%) diff --git a/lib/zonefile-es.js b/lib/zonefile-es.js index 7824ba4..f7e1bc9 100644 --- a/lib/zonefile-es.js +++ b/lib/zonefile-es.js @@ -48,6 +48,21 @@ const defaultTemplate = `; Zone: {zone} `; +///////////////////////////////////////////////////////////////////////////////////// +// __ // +// / | // +// ______ ______ _______ ______ ______ ______ _$$ |_ ______ // +// / \ / \ / \ / \ / \ / \ / $$ | / \ // +// /$$$$$$ |/$$$$$$ |$$$$$$$ |/$$$$$$ |/$$$$$$ |$$$$$$ |$$$$$$/ /$$$$$$ | // +// $$ | $$ |$$ $$ |$$ | $$ |$$ $$ |$$ | $$/ / $$ | $$ | __ $$ $$ | // +// $$ \__$$ |$$$$$$$$/ $$ | $$ |$$$$$$$$/ $$ | /$$$$$$$ | $$ |/ |$$$$$$$$/ // +// $$ $$ |$$ |$$ | $$ |$$ |$$ | $$ $$ | $$ $$/ $$ | // +// $$$$$$$ | $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$$$$$$/ $$$$/ $$$$$$$/ // +// / \__$$ | // +// $$ $$/ // +// $$$$$$/ // +// // +///////////////////////////////////////////////////////////////////////////////////// export let generate = function (options, template) { const json = JSON.parse(JSON.stringify(options)); template = template || defaultTemplate; @@ -214,8 +229,19 @@ let processValues = function (options, template) { return template.replace('{time}', Math.round(Date.now() / 1000)); }; -////////////////////////////////////////////////////////////////////////////// - +//////////////////////////////////////////////////////// +// ______ ______ ______ _______ ______ // +// / \ / \ / \ / | / \ // +// /$$$$$$ | $$$$$$ |/$$$$$$ |/$$$$$$$/ /$$$$$$ | // +// $$ | $$ | / $$ |$$ | $$/ $$ \ $$ $$ | // +// $$ |__$$ |/$$$$$$$ |$$ | $$$$$$ |$$$$$$$$/ // +// $$ $$/ $$ $$ |$$ | / $$/ $$ | // +// $$$$$$$/ $$$$$$$/ $$/ $$$$$$$/ $$$$$$$/ // +// $$ | // +// $$ | // +// $$/ // +// // +//////////////////////////////////////////////////////// export let parse = function (text) { text = removeComments(text); text = flatten(text); diff --git a/lib/zonefile.js b/lib/zonefile.js index d7efc71..c450ea9 100644 --- a/lib/zonefile.js +++ b/lib/zonefile.js @@ -48,6 +48,21 @@ const defaultTemplate = `; Zone: {zone} `; +///////////////////////////////////////////////////////////////////////////////////// +// __ // +// / | // +// ______ ______ _______ ______ ______ ______ _$$ |_ ______ // +// / \ / \ / \ / \ / \ / \ / $$ | / \ // +// /$$$$$$ |/$$$$$$ |$$$$$$$ |/$$$$$$ |/$$$$$$ |$$$$$$ |$$$$$$/ /$$$$$$ | // +// $$ | $$ |$$ $$ |$$ | $$ |$$ $$ |$$ | $$/ / $$ | $$ | __ $$ $$ | // +// $$ \__$$ |$$$$$$$$/ $$ | $$ |$$$$$$$$/ $$ | /$$$$$$$ | $$ |/ |$$$$$$$$/ // +// $$ $$ |$$ |$$ | $$ |$$ |$$ | $$ $$ | $$ $$/ $$ | // +// $$$$$$$ | $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$$$$$$/ $$$$/ $$$$$$$/ // +// / \__$$ | // +// $$ $$/ // +// $$$$$$/ // +// // +///////////////////////////////////////////////////////////////////////////////////// let generate = function (options, template) { const json = JSON.parse(JSON.stringify(options)); template = template || defaultTemplate; @@ -214,8 +229,20 @@ let processValues = function (options, template) { return template.replace('{time}', Math.round(Date.now() / 1000)); }; -////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +// ______ ______ ______ _______ ______ // +// / \ / \ / \ / | / \ // +// /$$$$$$ | $$$$$$ |/$$$$$$ |/$$$$$$$/ /$$$$$$ | // +// $$ | $$ | / $$ |$$ | $$/ $$ \ $$ $$ | // +// $$ |__$$ |/$$$$$$$ |$$ | $$$$$$ |$$$$$$$$/ // +// $$ $$/ $$ $$ |$$ | / $$/ $$ | // +// $$$$$$$/ $$$$$$$/ $$/ $$$$$$$/ $$$$$$$/ // +// $$ | // +// $$ | // +// $$/ // +// // +//////////////////////////////////////////////////////// let parse = function (text) { text = removeComments(text); text = flatten(text); diff --git a/package.json b/package.json index bac5533..9532791 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "bin": { "zonefile": "./bin/zonefile" }, + "scripts": { + "test": "npx jasmine tests/tests.js" + }, "repository": { "type": "git", "url": "https://github.com/elgs/dns-zonefile.git" @@ -56,6 +59,6 @@ ], "devDependencies": { "deep-equal": "^2.0.5", - "jasmine": "^4.0.0" + "jasmine": "^4.0.1" } -} +} \ No newline at end of file diff --git a/specs/tests.js b/specs/tests.js deleted file mode 100644 index 4bb11f7..0000000 --- a/specs/tests.js +++ /dev/null @@ -1,353 +0,0 @@ -let fs = require('fs'); -let zonefile = require('../lib/zonefile.js'); -const deepEqual = require('deep-equal'); - -describe('forward parser', () => { - let parsed; - beforeEach(() => { - const text = fs.readFileSync(__dirname + '/zonefile_forward.txt', 'utf8'); - parsed = zonefile.parse(text); - }); - - it('should parse global info', () => { - expect(parsed['$origin']).toEqual('MYDOMAIN.COM.'); - expect(parsed['$ttl']).toEqual('3600'); - }); - - it('should parse soa records', () => { - const records = parsed['soa']; - expect(records?.['name']).toEqual('@'); - expect(records?.['minimum']).toEqual(86400); - expect(records?.['expire']).toEqual(604800); - expect(records?.['retry']).toEqual(600); - expect(records?.['refresh']).toEqual(3600); - expect(records?.['serial']).toEqual(1406291485); - expect(records?.['rname']).toEqual('HOSTMASTER.MYDOMAIN.COM.'); - expect(records?.['mname']).toEqual('NS1.NAMESERVER.NET.'); - }); - - it('should parse ns records', () => { - const records = parsed['ns']; - expect(records?.length).toEqual(2); - expect(records?.[0]?.['name']).toEqual('@'); - expect(records?.[0]?.['host']).toEqual('NS1.NAMESERVER.NET.'); - expect(records?.[1]?.['name']).toEqual('@'); - expect(records?.[1]?.['host']).toEqual('NS2.NAMESERVER.NET.'); - }); - - it('should parse mx records', () => { - const records = parsed['mx']; - expect(records?.length).toEqual(2); - expect(records?.[0]?.['name']).toEqual('@'); - expect(records?.[0]?.['preference']).toEqual(0); - expect(records?.[0]?.['host']).toEqual('mail1'); - expect(records?.[1]?.['name']).toEqual('@'); - expect(records?.[1]?.['preference']).toEqual(10); - expect(records?.[1]?.['host']).toEqual('mail2'); - }); - - it('should parse a records', () => { - const records = parsed['a']; - expect(records?.length).toEqual(7); - expect(records?.[0]?.['name']).toEqual('@'); - expect(records?.[0]?.['ip']).toEqual('2.2.2.2'); - expect(records?.[1]?.['name']).toEqual('@'); - expect(records?.[1]?.['ip']).toEqual('1.1.1.1'); - expect(records?.[2]?.['name']).toEqual('@'); - expect(records?.[2]?.['ip']).toEqual('127.0.0.1'); - expect(records?.[3]?.['name']).toEqual('www'); - expect(records?.[3]?.['ip']).toEqual('127.0.0.1'); - expect(records?.[4]?.['name']).toEqual('mail'); - expect(records?.[4]?.['ip']).toEqual('127.0.0.1'); - expect(records?.[5]?.['name']).toEqual('mail'); - expect(records?.[5]?.['ip']).toEqual('1.2.3.4'); - expect(records?.[6]?.['name']).toEqual('tst'); - expect(records?.[6]?.['ip']).toEqual('101.228.10.127'); - expect(records?.[6]?.['ttl']).toEqual(300); - }); - - it('should parse aaaa records', () => { - const records = parsed['aaaa']; - expect(records?.length).toEqual(3); - expect(records?.[0]?.['name']).toEqual('@'); - expect(records?.[0]?.['ip']).toEqual('::1'); - expect(records?.[1]?.['name']).toEqual('mail'); - expect(records?.[1]?.['ip']).toEqual('2001:db8::1'); - expect(records?.[2]?.['name']).toEqual('A'); - expect(records?.[2]?.['ip']).toEqual('2001:db8::1'); - expect(records?.[2]?.['ttl']).toEqual(200); - }); - - it('should parse cname records', () => { - const records = parsed['cname']; - expect(records?.length).toEqual(4); - expect(records?.[0]?.['name']).toEqual('mail1'); - expect(records?.[0]?.['alias']).toEqual('mail'); - expect(records?.[1]?.['name']).toEqual('mail2'); - expect(records?.[1]?.['alias']).toEqual('mail'); - expect(records?.[2]?.['name']).toEqual('CNAME'); - expect(records?.[2]?.['alias']).toEqual('CNAME'); - expect(records?.[3]?.['name']).toEqual('CNAME'); - expect(records?.[3]?.['alias']).toEqual('CNAME'); - }); - - it('should parse caa records', () => { - const records = parsed['caa']; - expect(records?.length).toEqual(3); - expect(records?.[0]?.['name']).toEqual('@'); - expect(records?.[0]?.['flags']).toEqual(0); - expect(records?.[0]?.['tag']).toEqual('issue'); - expect(records?.[0]?.['value']).toEqual('"ca.example.net; account=230123"'); - expect(records?.[1]?.['name']).toEqual('@'); - expect(records?.[1]?.['flags']).toEqual(0); - expect(records?.[1]?.['tag']).toEqual('iodef'); - expect(records?.[1]?.['value']).toEqual('"mailto:security@example.com"'); - expect(records?.[2]?.['name']).toEqual('@'); - expect(records?.[2]?.['flags']).toEqual(0); - expect(records?.[2]?.['tag']).toEqual('iodef'); - expect(records?.[2]?.['value']).toEqual('"http://iodef.example.com/"'); - }); - - it('should parse txt records', () => { - const records = parsed['txt']; - expect(records?.length).toEqual(4); - expect(records?.[0]?.['name']).toEqual('treefrog.ca.'); - expect(records?.[0]?.['txt']).toEqual('"v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all" "asdfsdaf" "sdfsadfdasf"'); - expect(records?.[1]?.['name']).toEqual('treefrog.ca.'); - expect(records?.[1]?.['txt']).toEqual('"v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all" "asdfsdaf" sdfsadfdasf'); - expect(records?.[2]?.['name']).toEqual('treemonkey.ca.'); - expect(records?.[2]?.['txt']).toEqual('"v=DKIM1\\; k=rsa\\; p=MIGf..."'); - expect(records?.[3]?.['name']).toEqual('treemonkey.ca.'); - expect(records?.[3]?.['txt']).toEqual('"v=DKIM1\\; k=rsa\\; p=MIGf..."'); - }); - - it('should parse spf records', () => { - const records = parsed['spf']; - expect(records?.length).toEqual(4); - expect(records?.[0]?.['name']).toEqual('test'); - expect(records?.[0]?.['data']).toEqual('"v=spf1" "mx:gcloud-node.com." "-all"'); - expect(records?.[1]?.['name']).toEqual('test1'); - expect(records?.[1]?.['data']).toEqual('"v=spf2" "mx:gcloud-node.com." "-all"'); - expect(records?.[2]?.['name']).toEqual('test1'); - expect(records?.[2]?.['data']).toEqual('"v=spf3" "mx:gcloud-node.com." "-all " "aasdfsadfdsafdasf"'); - expect(records?.[3]?.['name']).toEqual('test1'); - expect(records?.[3]?.['data']).toEqual('"v=spf4" "mx:gcloud-node.com." "-all"'); - }); - - it('should parse ds records', () => { - const records = parsed['ds']; - expect(records?.length).toEqual(2); - expect(records?.[0]?.['name']).toEqual('secure.example.'); - expect(records?.[0]?.['key_tag']).toEqual('tag=12345'); - expect(records?.[0]?.['algorithm']).toEqual('alg=3'); - expect(records?.[0]?.['digest_type']).toEqual('digest_type=1'); - expect(records?.[0]?.['digest']).toEqual(''); - expect(records?.[1]?.['name']).toEqual('secure.example.'); - expect(records?.[1]?.['key_tag']).toEqual('tag=12345'); - expect(records?.[1]?.['algorithm']).toEqual('alg=3'); - expect(records?.[1]?.['digest_type']).toEqual('digest_type=1'); - expect(records?.[1]?.['digest']).toEqual('""'); - }); - - it('should parse srv records', () => { - const records = parsed['srv']; - expect(records?.length).toEqual(6); - expect(records?.[0]?.['name']).toEqual('_foobar._tcp'); - expect(records?.[0]?.['target']).toEqual('old-slow-box.example.com.'); - expect(records?.[0]?.['priority']).toEqual(0); - expect(records?.[0]?.['weight']).toEqual(1); - expect(records?.[0]?.['port']).toEqual(9); - expect(records?.[0]?.['ttl']).toEqual(200); - - expect(records?.[1]?.['name']).toEqual('_foobar._tcp'); - expect(records?.[1]?.['target']).toEqual('new-fast-box.example.com.'); - expect(records?.[1]?.['priority']).toEqual(0); - expect(records?.[1]?.['weight']).toEqual(3); - expect(records?.[1]?.['port']).toEqual(9); - - expect(records?.[2]?.['name']).toEqual('_foobar._tcp'); - expect(records?.[2]?.['target']).toEqual('sysadmins-box.example.com.'); - expect(records?.[2]?.['priority']).toEqual(1); - expect(records?.[2]?.['weight']).toEqual(0); - expect(records?.[2]?.['port']).toEqual(9); - - expect(records?.[3]?.['name']).toEqual('_foobar._tcp'); - expect(records?.[3]?.['target']).toEqual('server.example.com.'); - expect(records?.[3]?.['priority']).toEqual(1); - expect(records?.[3]?.['weight']).toEqual(0); - expect(records?.[3]?.['port']).toEqual(9); - - expect(records?.[4]?.['name']).toEqual('*._tcp'); - expect(records?.[4]?.['target']).toEqual('.'); - expect(records?.[4]?.['priority']).toEqual(0); - expect(records?.[4]?.['weight']).toEqual(0); - expect(records?.[4]?.['port']).toEqual(0); - - expect(records?.[5]?.['name']).toEqual('*._udp'); - expect(records?.[5]?.['target']).toEqual('.'); - expect(records?.[5]?.['priority']).toEqual(0); - expect(records?.[5]?.['weight']).toEqual(0); - expect(records?.[5]?.['port']).toEqual(0); - }); -}); - - - -describe('forward generator', () => { - let generated; - let lines; - beforeEach(() => { - const json = require(__dirname + '/zonefile_forward.json'); - generated = zonefile.generate(json); - lines = generated.split('\n'); - }); - - it('should generate global info', () => { - expect(lines.includes('$ORIGIN MYDOMAIN.COM.')).toBeTrue(); - expect(lines.includes('$TTL 3600')).toBeTrue(); - }); - - it('should generate soa records', () => { - const records = ` - @ IN SOA NS1.NAMESERVER.NET. HOSTMASTER.MYDOMAIN.COM. ( - 1406291485 ;serial - 3600 ;refresh - 600 ;retry - 604800 ;expire - 86400 ;minimum ttl`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate ns records', () => { - const records = ` - @ IN NS NS1.NAMESERVER.NET. - @ IN NS NS2.NAMESERVER.NET.`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate mx records', () => { - const records = ` - @ IN MX 0 mail1 - @ IN MX 10 mail2`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate a records', () => { - const records = ` - @ IN A 2.2.2.2 - @ IN A 1.1.1.1 - @ IN A 127.0.0.1 - www IN A 127.0.0.1 - mail IN A 127.0.0.1 - mail IN A 1.2.3.4 - tst 300 IN A 101.228.10.127`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate aaaa records', () => { - const records = ``; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate records', () => { - const records = ` - @ IN AAAA ::1 - mail IN AAAA 2001:db8::1 - A 200 IN AAAA 2001:db8::1`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate cname records', () => { - const records = ` - mail1 IN CNAME mail - mail2 IN CNAME mail - CNAME IN CNAME CNAME - CNAME IN CNAME CNAME`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate txt records', () => { - const records = ` - treefrog.ca. IN TXT "v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all" "asdfsdaf" "sdfsadfdasf" - treefrog.ca. IN TXT "v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all" "asdfsdaf" sdfsadfdasf - treemonkey.ca. IN TXT "v=DKIM1\\; k=rsa\\; p=MIGf..." - treemonkey.ca. IN TXT "v=DKIM1\\; k=rsa\\; p=MIGf..."`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate srv records', () => { - const records = ` - _foobar._tcp 200 IN SRV 0 1 9 old-slow-box.example.com. - _foobar._tcp IN SRV 0 3 9 new-fast-box.example.com. - _foobar._tcp IN SRV 1 0 9 sysadmins-box.example.com. - _foobar._tcp IN SRV 1 0 9 server.example.com. - *._tcp IN SRV 0 0 0 . - *._udp IN SRV 0 0 0 .`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate spf records', () => { - const records = ` - test IN SPF "v=spf1" "mx:gcloud-node.com." "-all" - test1 IN SPF "v=spf2" "mx:gcloud-node.com." "-all" - test1 IN SPF "v=spf3" "mx:gcloud-node.com." "-all " "aasdfsadfdsafdasf" - test1 IN SPF "v=spf4" "mx:gcloud-node.com." "-all"`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate caa records', () => { - const records = ` - @ IN CAA 0 issue "ca.example.net; account=230123" - @ IN CAA 0 iodef "mailto:security@example.com" - @ IN CAA 0 iodef "http://iodef.example.com/"`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); - - it('should generate ds records', () => { - const records = ` - secure.example. IN DS tag=12345 alg=3 digest_type=1 - secure.example. IN DS tag=12345 alg=3 digest_type=1 ""`; - records.trim().split('\n').forEach(record => { - expect(lines).toContain(record.trim()); - }); - }); -}); - -describe('idempotence tests', () => { - it('should', () => { - const text = fs.readFileSync(__dirname + '/zonefile_forward.txt', 'utf8'); - const json = zonefile.parse(text); - - const text1 = zonefile.generate(json); - const json1 = zonefile.parse(text1); - - expect(deepEqual(json, json1)).toBeTrue(); - - const text2 = zonefile.generate(json1); - - // exclude the date time line - expect(deepEqual(text1.split('\n').slice(2), text2.split('\n').slice(2))).toBeTrue(); - }); -}); \ No newline at end of file diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 01a2833..0000000 --- a/test/test.js +++ /dev/null @@ -1,36 +0,0 @@ -(function () { - let fs = require('fs'); - let zonefile = require('../lib/zonefile.js'); - - console.log('##########', 'Generating forward zone file from JSON', '##########'); - let options = require('./zonefile_forward.json'); - let output = zonefile.generate(options); - console.log(output); - - console.log('##########', 'Generating reverse zone file from JSON', '##########'); - options = require('./zonefile_reverse.json'); - output = zonefile.generate(options); - console.log(output); - - console.log('##########', 'Generating reverse zone file (IPv6) from JSON', '##########'); - options = require('./zonefile_reverse_ipv6.json'); - output = zonefile.generate(options); - console.log(output); - - console.log('##########', 'Parsing forward zone file to JSON', '##########'); - let text = fs.readFileSync('./zonefile_forward.txt', 'utf8'); - output = zonefile.parse(text); - console.log(output); - - console.log('\n'); - console.log('##########', 'Parsing reverse zone file to JSON', '##########'); - text = fs.readFileSync('./zonefile_reverse.txt', 'utf8'); - output = zonefile.parse(text); - console.log(output); - - console.log('\n'); - console.log('##########', 'Parsing reverse zone file (IPv6) to JSON', '##########'); - text = fs.readFileSync('./zonefile_reverse_ipv6.txt', 'utf8'); - output = zonefile.parse(text); - console.log(output); -})(); diff --git a/test/zonefile_forward.json b/test/zonefile_forward.json deleted file mode 100644 index 261e40b..0000000 --- a/test/zonefile_forward.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "$origin": "MYDOMAIN.COM.", - "$ttl": 3600, - "soa": { - "mname": "NS1.NAMESERVER.NET.", - "rname": "HOSTMASTER.MYDOMAIN.COM.", - "serial": "{time}", - "refresh": 3600, - "retry": 600, - "expire": 604800, - "minimum": 86400 - }, - "ns": [ - { - "host": "NS1.NAMESERVER.NET." - }, - { - "host": "NS2.NAMESERVER.NET." - } - ], - "a": [ - { - "name": "@", - "ip": "127.0.0.1" - }, - { - "name": "www", - "ip": "127.0.0.1" - }, - { - "name": "mail", - "ip": "127.0.0.1" - } - ], - "aaaa": [ - { - "ip": "::1" - }, - { - "name": "mail", - "ip": "2001:db8::1" - } - ], - "cname": [ - { - "name": "mail1", - "alias": "mail" - }, - { - "name": "mail2", - "alias": "mail" - } - ], - "mx": [ - { - "preference": 0, - "host": "mail1" - }, - { - "preference": 10, - "host": "mail2" - } - ], - "caa": [ - { - "flags": 0, - "tag": "issue", - "value": "ca.example.net; policy=ev" - }, - { - "flags": 0, - "tag": "iodef", - "value": "mailto:security@example.com" - }, - { - "flags": 0, - "tag": "iodef", - "value": "http://iodef.example.com/" - } - ], - "txt": [ - { - "name": "treefrog.ca.", - "txt": "\"v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all\" \"sdfsadfdasf\"" - }, - { - "name": "treemonkey.ca.", - "txt": "\"v=DKIM1\\; k=rsa\\; p=MIGf...\"" - }, - { - "name": "treemonkey1.ca.", - "txt": "\"v=DKIM1\\; k=rsa\\; p=MIGf...\"" - } - ], - "spf": [ - { - "name": "treefrog.ca.", - "data": "\"v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all\" \"sdfsadfdasf\"" - }, - { - "name": "treemonkey.ca.", - "data": "\"v=DKIM1\\; k=rsa\\; p=MIGf...\"" - }, - { - "name": "treemonkey1.ca.", - "data": "\"v=DKIM1\\; k=rsa\\; p=MIGf...\"" - } - ], - "ds": [ - { - "name": "secure.example.", - "key_tag": "tag=12345", - "algorithm": "alg=3", - "digest_type": "digest_type=1", - "digest": "" - } - ] -} \ No newline at end of file diff --git a/test/zonefile_forward.txt b/test/zonefile_forward.txt deleted file mode 100644 index 5727502..0000000 --- a/test/zonefile_forward.txt +++ /dev/null @@ -1,45 +0,0 @@ -$ORIGIN MYDOMAIN.COM. -$TTL 3600 -@ IN SOA NS1.NAMESERVER.NET. HOSTMASTER.MYDOMAIN.COM. ( - 1406291485 ;serial - 3600 ;refresh - 600 ;retry - 604800 ;expire - 86400 ;minimum ttl -) - -@ NS NS1.NAMESERVER.NET. -@ NS NS2.NAMESERVER.NET. - -@ MX 0 mail1 -@ MX 10 mail2 - - IN A 2.2.2.2 - A 1.1.1.1 -@ A 127.0.0.1 -www A 127.0.0.1 -mail A 127.0.0.1 - A 1.2.3.4 -tst 300 IN A 101.228.10.127;this is a comment - -@ AAAA ::1 -mail AAAA 2001:db8::1 - -@ CAA 0 issue "ca.example.net; account=230123" -@ CAA 0 iodef "mailto:security@example.com" -@ CAA 0 iodef "http://iodef.example.com/" - -mail1 CNAME mail -mail2 CNAME mail - -test IN SPF "v=spf1" "mx:gcloud-node.com." "-all" -test1 SPF "v=spf2" "mx:gcloud-node.com." "-all" - IN SPF "v=spf3" "mx:gcloud-node.com." "-all " "aasdfsadfdsafdasf" - SPF "v=spf4" "mx:gcloud-node.com." "-all" - -treefrog.ca. IN TXT "v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all" "asdfsdaf" "sdfsadfdasf" - IN TXT "v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all" "asdfsdaf" sdfsadfdasf -treemonkey.ca. IN TXT "v=DKIM1\; k=rsa\; p=MIGf..." -treemonkey1.ca. IN TXT "v=DKIM1\; k=rsa\; p=MIGf..." - -secure.example. DS tag=12345 alg=3 digest_type=1 \ No newline at end of file diff --git a/test/zonefile_forward_srv.json b/test/zonefile_forward_srv.json deleted file mode 100644 index 742e844..0000000 --- a/test/zonefile_forward_srv.json +++ /dev/null @@ -1,89 +0,0 @@ -{ - "$origin": "example.com.", - "soa": { - "name": "@", - "minimum": 86400, - "expire": 604800, - "retry": 3600, - "refresh": 3600, - "serial": 1995032001, - "rname": "hostmaster.example.com.", - "mname": "server.example.com." - }, - "ns": [ - { - "name": "@", - "host": "server.example.com." - }, - { - "name": "@", - "host": "ns1.ip-provider.net." - }, - { - "name": "@", - "host": "ns2.ip-provider.net." - } - ], - "srv": [ - { - "name": "_foobar._tcp", - "target": "old-slow-box.example.com.", - "priority": 0, - "weight": 1, - "port": 9 - }, - { - "name": "_foobar._tcp", - "target": "new-fast-box.example.com.", - "priority": 0, - "weight": 3, - "port": 9 - }, - { - "name": "_foobar._tcp", - "target": "sysadmins-box.example.com.", - "priority": 1, - "weight": 0, - "port": 9 - }, - { - "name": "_foobar._tcp", - "target": "server.example.com.", - "priority": 1, - "weight": 0, - "port": 9 - }, - { - "name": "*._tcp", - "target": ".", - "priority": 0, - "weight": 0, - "port": 0 - }, - { - "name": "*._udp", - "target": ".", - "priority": 0, - "weight": 0, - "port": 0 - } - ], - "a": [ - { - "name": "server", - "ip": "172.30.79.10" - }, - { - "name": "old-slow-box", - "ip": "172.30.79.11" - }, - { - "name": "sysadmins-box", - "ip": "172.30.79.12" - }, - { - "name": "new-fast-box", - "ip": "172.30.79.13" - } - ] -} diff --git a/test/zonefile_forward_srv.txt b/test/zonefile_forward_srv.txt deleted file mode 100644 index 01668f1..0000000 --- a/test/zonefile_forward_srv.txt +++ /dev/null @@ -1,22 +0,0 @@ -$ORIGIN example.com. -@ SOA server.example.com. hostmaster.example.com. ( - 1995032001 3600 3600 604800 86400 ) - NS server.example.com. - NS ns1.ip-provider.net. - NS ns2.ip-provider.net. -; foobar - use old-slow-box or new-fast-box if either is -; available, make three quarters of the logins go to -; new-fast-box. -_foobar._tcp SRV 0 1 9 old-slow-box.example.com. - SRV 0 3 9 new-fast-box.example.com. -; if neither old-slow-box or new-fast-box is up, switch to -; using the sysdmin's box and the server - SRV 1 0 9 sysadmins-box.example.com. - SRV 1 0 9 server.example.com. -server A 172.30.79.10 -old-slow-box A 172.30.79.11 -sysadmins-box A 172.30.79.12 -new-fast-box A 172.30.79.13 -; NO other services are supported -*._tcp SRV 0 0 0 . -*._udp SRV 0 0 0 . \ No newline at end of file diff --git a/test/zonefile_reverse.json b/test/zonefile_reverse.json deleted file mode 100644 index 6ec63ae..0000000 --- a/test/zonefile_reverse.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "$origin": "0.168.192.IN-ADDR.ARPA.", - "$ttl": 3600, - "soa": { - "mname": "NS1.NAMESERVER.NET.", - "rname": "HOSTMASTER.MYDOMAIN.COM.", - "serial": "{time}", - "refresh": 3600, - "retry": 600, - "expire": 604800, - "minimum": 86400 - }, - "ns": [ - { "host": "NS1.NAMESERVER.NET." }, - { "host": "NS2.NAMESERVER.NET." } - ], - "ptr":[ - { "name": 1, "host": "HOST1.MYDOMAIN.COM." }, - { "name": 2, "host": "HOST2.MYDOMAIN.COM." } - ] -} diff --git a/test/zonefile_reverse_ipv6.json b/test/zonefile_reverse_ipv6.json deleted file mode 100644 index 2670a07..0000000 --- a/test/zonefile_reverse_ipv6.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "$origin": "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.", - "$ttl": 3600, - "soa": { - "mname": "NS1.NAMESERVER.NET.", - "rname": "HOSTMASTER.MYDOMAIN.COM.", - "serial": "{time}", - "refresh": 3600, - "retry": 600, - "expire": 604800, - "minimum": 86400 - }, - "ns": [ - { "host": "NS1.NAMESERVER.NET." }, - { "host": "NS2.NAMESERVER.NET." } - ], - "ptr":[ - { "name": 1, "host": "HOST1.MYDOMAIN.COM." }, - { "name": 2, "host": "HOST2.MYDOMAIN.COM." } - ] -} diff --git a/tests/tests.js b/tests/tests.js new file mode 100644 index 0000000..704c085 --- /dev/null +++ b/tests/tests.js @@ -0,0 +1,718 @@ +const fs = require('fs'); +const zonefile = require('../lib/zonefile.js'); +const deepEqual = require('deep-equal'); + +///////////////////////////////////////////////////////////////////////////////// +// _______ // +// __ / \ // +// / | $$$$$$$ | ______ ______ _______ ______ ______ // +// __$$ |__ $$ |__$$ |/ \ / \ / | / \ / \ // +// / $$ | $$ $$/ $$$$$$ |/$$$$$$ |/$$$$$$$/ /$$$$$$ |/$$$$$$ | // +// $$$$$$$$/ $$$$$$$/ / $$ |$$ | $$/ $$ \ $$ $$ |$$ | $$/ // +// $$ | $$ | /$$$$$$$ |$$ | $$$$$$ |$$$$$$$$/ $$ | // +// $$/ $$ | $$ $$ |$$ | / $$/ $$ |$$ | // +// $$/ $$$$$$$/ $$/ $$$$$$$/ $$$$$$$/ $$/ // +// // +///////////////////////////////////////////////////////////////////////////////// +describe('forward parser', () => { + let parsed; + beforeEach(() => { + const text = fs.readFileSync(__dirname + '/zonefile_forward.txt', 'utf8'); + parsed = zonefile.parse(text); + }); + + it('should parse global info', () => { + expect(parsed['$origin']).toEqual('MYDOMAIN.COM.'); + expect(parsed['$ttl']).toEqual('3600'); + }); + + it('should parse soa records', () => { + const records = parsed['soa']; + expect(records?.['name']).toEqual('@'); + expect(records?.['minimum']).toEqual(86400); + expect(records?.['expire']).toEqual(604800); + expect(records?.['retry']).toEqual(600); + expect(records?.['refresh']).toEqual(3600); + expect(records?.['serial']).toEqual(1406291485); + expect(records?.['rname']).toEqual('HOSTMASTER.MYDOMAIN.COM.'); + expect(records?.['mname']).toEqual('NS1.NAMESERVER.NET.'); + }); + + it('should parse ns records', () => { + const records = parsed['ns']; + expect(records?.length).toEqual(2); + expect(records?.[0]?.['name']).toEqual('@'); + expect(records?.[0]?.['host']).toEqual('NS1.NAMESERVER.NET.'); + expect(records?.[1]?.['name']).toEqual('@'); + expect(records?.[1]?.['host']).toEqual('NS2.NAMESERVER.NET.'); + }); + + it('should parse mx records', () => { + const records = parsed['mx']; + expect(records?.length).toEqual(2); + expect(records?.[0]?.['name']).toEqual('@'); + expect(records?.[0]?.['preference']).toEqual(0); + expect(records?.[0]?.['host']).toEqual('mail1'); + expect(records?.[1]?.['name']).toEqual('@'); + expect(records?.[1]?.['preference']).toEqual(10); + expect(records?.[1]?.['host']).toEqual('mail2'); + }); + + it('should parse a records', () => { + const records = parsed['a']; + expect(records?.length).toEqual(7); + expect(records?.[0]?.['name']).toEqual('@'); + expect(records?.[0]?.['ip']).toEqual('2.2.2.2'); + expect(records?.[1]?.['name']).toEqual('@'); + expect(records?.[1]?.['ip']).toEqual('1.1.1.1'); + expect(records?.[2]?.['name']).toEqual('@'); + expect(records?.[2]?.['ip']).toEqual('127.0.0.1'); + expect(records?.[3]?.['name']).toEqual('www'); + expect(records?.[3]?.['ip']).toEqual('127.0.0.1'); + expect(records?.[4]?.['name']).toEqual('mail'); + expect(records?.[4]?.['ip']).toEqual('127.0.0.1'); + expect(records?.[5]?.['name']).toEqual('mail'); + expect(records?.[5]?.['ip']).toEqual('1.2.3.4'); + expect(records?.[6]?.['name']).toEqual('tst'); + expect(records?.[6]?.['ip']).toEqual('101.228.10.127'); + expect(records?.[6]?.['ttl']).toEqual(300); + }); + + it('should parse aaaa records', () => { + const records = parsed['aaaa']; + expect(records?.length).toEqual(3); + expect(records?.[0]?.['name']).toEqual('@'); + expect(records?.[0]?.['ip']).toEqual('::1'); + expect(records?.[1]?.['name']).toEqual('mail'); + expect(records?.[1]?.['ip']).toEqual('2001:db8::1'); + expect(records?.[2]?.['name']).toEqual('A'); + expect(records?.[2]?.['ip']).toEqual('2001:db8::1'); + expect(records?.[2]?.['ttl']).toEqual(200); + }); + + it('should parse cname records', () => { + const records = parsed['cname']; + expect(records?.length).toEqual(4); + expect(records?.[0]?.['name']).toEqual('mail1'); + expect(records?.[0]?.['alias']).toEqual('mail'); + expect(records?.[1]?.['name']).toEqual('mail2'); + expect(records?.[1]?.['alias']).toEqual('mail'); + expect(records?.[2]?.['name']).toEqual('CNAME'); + expect(records?.[2]?.['alias']).toEqual('CNAME'); + expect(records?.[3]?.['name']).toEqual('CNAME'); + expect(records?.[3]?.['alias']).toEqual('CNAME'); + }); + + it('should parse caa records', () => { + const records = parsed['caa']; + expect(records?.length).toEqual(3); + expect(records?.[0]?.['name']).toEqual('@'); + expect(records?.[0]?.['flags']).toEqual(0); + expect(records?.[0]?.['tag']).toEqual('issue'); + expect(records?.[0]?.['value']).toEqual('"ca.example.net; account=230123"'); + expect(records?.[1]?.['name']).toEqual('@'); + expect(records?.[1]?.['flags']).toEqual(0); + expect(records?.[1]?.['tag']).toEqual('iodef'); + expect(records?.[1]?.['value']).toEqual('"mailto:security@example.com"'); + expect(records?.[2]?.['name']).toEqual('@'); + expect(records?.[2]?.['flags']).toEqual(0); + expect(records?.[2]?.['tag']).toEqual('iodef'); + expect(records?.[2]?.['value']).toEqual('"http://iodef.example.com/"'); + }); + + it('should parse txt records', () => { + const records = parsed['txt']; + expect(records?.length).toEqual(4); + expect(records?.[0]?.['name']).toEqual('treefrog.ca.'); + expect(records?.[0]?.['txt']).toEqual('"v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all" "asdfsdaf" "sdfsadfdasf"'); + expect(records?.[1]?.['name']).toEqual('treefrog.ca.'); + expect(records?.[1]?.['txt']).toEqual('"v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all" "asdfsdaf" sdfsadfdasf'); + expect(records?.[2]?.['name']).toEqual('treemonkey.ca.'); + expect(records?.[2]?.['txt']).toEqual('"v=DKIM1\\; k=rsa\\; p=MIGf..."'); + expect(records?.[3]?.['name']).toEqual('treemonkey.ca.'); + expect(records?.[3]?.['txt']).toEqual('"v=DKIM1\\; k=rsa\\; p=MIGf..."'); + }); + + it('should parse spf records', () => { + const records = parsed['spf']; + expect(records?.length).toEqual(4); + expect(records?.[0]?.['name']).toEqual('test'); + expect(records?.[0]?.['data']).toEqual('"v=spf1" "mx:gcloud-node.com." "-all"'); + expect(records?.[1]?.['name']).toEqual('test1'); + expect(records?.[1]?.['data']).toEqual('"v=spf2" "mx:gcloud-node.com." "-all"'); + expect(records?.[2]?.['name']).toEqual('test1'); + expect(records?.[2]?.['data']).toEqual('"v=spf3" "mx:gcloud-node.com." "-all " "aasdfsadfdsafdasf"'); + expect(records?.[3]?.['name']).toEqual('test1'); + expect(records?.[3]?.['data']).toEqual('"v=spf4" "mx:gcloud-node.com." "-all"'); + }); + + it('should parse ds records', () => { + const records = parsed['ds']; + expect(records?.length).toEqual(2); + expect(records?.[0]?.['name']).toEqual('secure.example.'); + expect(records?.[0]?.['key_tag']).toEqual('tag=12345'); + expect(records?.[0]?.['algorithm']).toEqual('alg=3'); + expect(records?.[0]?.['digest_type']).toEqual('digest_type=1'); + expect(records?.[0]?.['digest']).toEqual(''); + expect(records?.[1]?.['name']).toEqual('secure.example.'); + expect(records?.[1]?.['key_tag']).toEqual('tag=12345'); + expect(records?.[1]?.['algorithm']).toEqual('alg=3'); + expect(records?.[1]?.['digest_type']).toEqual('digest_type=1'); + expect(records?.[1]?.['digest']).toEqual('""'); + }); + + it('should parse srv records', () => { + const records = parsed['srv']; + expect(records?.length).toEqual(6); + expect(records?.[0]?.['name']).toEqual('_foobar._tcp'); + expect(records?.[0]?.['target']).toEqual('old-slow-box.example.com.'); + expect(records?.[0]?.['priority']).toEqual(0); + expect(records?.[0]?.['weight']).toEqual(1); + expect(records?.[0]?.['port']).toEqual(9); + expect(records?.[0]?.['ttl']).toEqual(200); + + expect(records?.[1]?.['name']).toEqual('_foobar._tcp'); + expect(records?.[1]?.['target']).toEqual('new-fast-box.example.com.'); + expect(records?.[1]?.['priority']).toEqual(0); + expect(records?.[1]?.['weight']).toEqual(3); + expect(records?.[1]?.['port']).toEqual(9); + + expect(records?.[2]?.['name']).toEqual('_foobar._tcp'); + expect(records?.[2]?.['target']).toEqual('sysadmins-box.example.com.'); + expect(records?.[2]?.['priority']).toEqual(1); + expect(records?.[2]?.['weight']).toEqual(0); + expect(records?.[2]?.['port']).toEqual(9); + + expect(records?.[3]?.['name']).toEqual('_foobar._tcp'); + expect(records?.[3]?.['target']).toEqual('server.example.com.'); + expect(records?.[3]?.['priority']).toEqual(1); + expect(records?.[3]?.['weight']).toEqual(0); + expect(records?.[3]?.['port']).toEqual(9); + + expect(records?.[4]?.['name']).toEqual('*._tcp'); + expect(records?.[4]?.['target']).toEqual('.'); + expect(records?.[4]?.['priority']).toEqual(0); + expect(records?.[4]?.['weight']).toEqual(0); + expect(records?.[4]?.['port']).toEqual(0); + + expect(records?.[5]?.['name']).toEqual('*._udp'); + expect(records?.[5]?.['target']).toEqual('.'); + expect(records?.[5]?.['priority']).toEqual(0); + expect(records?.[5]?.['weight']).toEqual(0); + expect(records?.[5]?.['port']).toEqual(0); + }); +}); + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ______ __ // +// __ / \ / | // +// / | /$$$$$$ | ______ _______ ______ ______ ______ _$$ |_ ______ ______ // +// __$$ |__ $$ | _$$/ / \ / \ / \ / \ / \ / $$ | / \ / \ // +// / $$ | $$ |/ |/$$$$$$ |$$$$$$$ |/$$$$$$ |/$$$$$$ |$$$$$$ |$$$$$$/ /$$$$$$ |/$$$$$$ | // +// $$$$$$$$/ $$ |$$$$ |$$ $$ |$$ | $$ |$$ $$ |$$ | $$/ / $$ | $$ | __ $$ | $$ |$$ | $$/ // +// $$ | $$ \__$$ |$$$$$$$$/ $$ | $$ |$$$$$$$$/ $$ | /$$$$$$$ | $$ |/ |$$ \__$$ |$$ | // +// $$/ $$ $$/ $$ |$$ | $$ |$$ |$$ | $$ $$ | $$ $$/ $$ $$/ $$ | // +// $$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$$$$$$/ $$$$/ $$$$$$/ $$/ // +// // +/////////////////////////////////////////////////////////////////////////////////////////////////////////////// +describe('forward generator', () => { + let generated; + let lines; + beforeEach(() => { + const json = require(__dirname + '/zonefile_forward.json'); + generated = zonefile.generate(json); + lines = generated.split('\n'); + }); + + it('should generate global info', () => { + expect(lines.includes('$ORIGIN MYDOMAIN.COM.')).toBeTrue(); + expect(lines.includes('$TTL 3600')).toBeTrue(); + }); + + it('should generate soa records', () => { + const records = ` + @ IN SOA NS1.NAMESERVER.NET. HOSTMASTER.MYDOMAIN.COM. ( + 1406291485 ;serial + 3600 ;refresh + 600 ;retry + 604800 ;expire + 86400 ;minimum ttl`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate ns records', () => { + const records = ` + @ IN NS NS1.NAMESERVER.NET. + @ IN NS NS2.NAMESERVER.NET.`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate mx records', () => { + const records = ` + @ IN MX 0 mail1 + @ IN MX 10 mail2`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate a records', () => { + const records = ` + @ IN A 2.2.2.2 + @ IN A 1.1.1.1 + @ IN A 127.0.0.1 + www IN A 127.0.0.1 + mail IN A 127.0.0.1 + mail IN A 1.2.3.4 + tst 300 IN A 101.228.10.127`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate aaaa records', () => { + const records = ``; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate records', () => { + const records = ` + @ IN AAAA ::1 + mail IN AAAA 2001:db8::1 + A 200 IN AAAA 2001:db8::1`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate cname records', () => { + const records = ` + mail1 IN CNAME mail + mail2 IN CNAME mail + CNAME IN CNAME CNAME + CNAME IN CNAME CNAME`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate txt records', () => { + const records = ` + treefrog.ca. IN TXT "v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all" "asdfsdaf" "sdfsadfdasf" + treefrog.ca. IN TXT "v=spf1 a mx a:mail.treefrog.ca a:webmail.treefrog.ca ip4:76.75.250.33 ?all" "asdfsdaf" sdfsadfdasf + treemonkey.ca. IN TXT "v=DKIM1\\; k=rsa\\; p=MIGf..." + treemonkey.ca. IN TXT "v=DKIM1\\; k=rsa\\; p=MIGf..."`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate srv records', () => { + const records = ` + _foobar._tcp 200 IN SRV 0 1 9 old-slow-box.example.com. + _foobar._tcp IN SRV 0 3 9 new-fast-box.example.com. + _foobar._tcp IN SRV 1 0 9 sysadmins-box.example.com. + _foobar._tcp IN SRV 1 0 9 server.example.com. + *._tcp IN SRV 0 0 0 . + *._udp IN SRV 0 0 0 .`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate spf records', () => { + const records = ` + test IN SPF "v=spf1" "mx:gcloud-node.com." "-all" + test1 IN SPF "v=spf2" "mx:gcloud-node.com." "-all" + test1 IN SPF "v=spf3" "mx:gcloud-node.com." "-all " "aasdfsadfdsafdasf" + test1 IN SPF "v=spf4" "mx:gcloud-node.com." "-all"`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate caa records', () => { + const records = ` + @ IN CAA 0 issue "ca.example.net; account=230123" + @ IN CAA 0 iodef "mailto:security@example.com" + @ IN CAA 0 iodef "http://iodef.example.com/"`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate ds records', () => { + const records = ` + secure.example. IN DS tag=12345 alg=3 digest_type=1 + secure.example. IN DS tag=12345 alg=3 digest_type=1 ""`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); +}); + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ______ __ __ // +// __ / | / | / | // +// / | $$$$$$/ ____$$ | ______ _____ ____ ______ ______ _$$ |_ ______ _______ _______ ______ // +// __$$ |__ $$ | / $$ | / \ / \/ \ / \ / \ / $$ | / \ / \ / | / \ // +// / $$ | $$ | /$$$$$$$ |/$$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$ |$$$$$$/ /$$$$$$ |$$$$$$$ |/$$$$$$$/ /$$$$$$ | // +// $$$$$$$$/ $$ | $$ | $$ |$$ $$ |$$ | $$ | $$ |$$ | $$ |$$ | $$ | $$ | __ $$ $$ |$$ | $$ |$$ | $$ $$ | // +// $$ | _$$ |_ $$ \__$$ |$$$$$$$$/ $$ | $$ | $$ |$$ |__$$ |$$ \__$$ | $$ |/ |$$$$$$$$/ $$ | $$ |$$ \_____ $$$$$$$$/ // +// $$/ / $$ |$$ $$ |$$ |$$ | $$ | $$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$ |$$ |$$ | // +// $$$$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$/ $$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$$$$$$/ // +// $$ | // +// $$ | // +// $$/ // +// // +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +describe('forward idempotence tests', () => { + it('should be idempotent', () => { + const text = fs.readFileSync(__dirname + '/zonefile_forward.txt', 'utf8'); + const json = zonefile.parse(text); + + const text1 = zonefile.generate(json); + const json1 = zonefile.parse(text1); + + expect(deepEqual(json, json1)).toBeTrue(); + + const text2 = zonefile.generate(json1); + + // exclude the date time line + expect(deepEqual(text1.split('\n').slice(2), text2.split('\n').slice(2))).toBeTrue(); + }); +}); + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +// _______ __ __ // +// / \ / | / | // +// $$$$$$$ | ______ ______ _______ ______ ______ __ __ $$ | $$ | // +// ______ $$ |__$$ |/ \ / \ / | / \ / \ / \ / |$$ |__$$ | // +// / | $$ $$/ $$$$$$ |/$$$$$$ |/$$$$$$$/ /$$$$$$ |/$$$$$$ | $$ \ /$$/ $$ $$ | // +// $$$$$$/ $$$$$$$/ / $$ |$$ | $$/ $$ \ $$ $$ |$$ | $$/ $$ /$$/ $$$$$$$$ | // +// $$ | /$$$$$$$ |$$ | $$$$$$ |$$$$$$$$/ $$ | $$ $$/ $$ | // +// $$ | $$ $$ |$$ | / $$/ $$ |$$ | $$$/ $$ | // +// $$/ $$$$$$$/ $$/ $$$$$$$/ $$$$$$$/ $$/ $/ $$/ // +// // +////////////////////////////////////////////////////////////////////////////////////////////////////////// +describe('reverse ipv4 parser', () => { + let parsed; + beforeEach(() => { + const text = fs.readFileSync(__dirname + '/zonefile_reverse_ipv4.txt', 'utf8'); + parsed = zonefile.parse(text); + }); + + it('should parse global info', () => { + expect(parsed['$origin']).toEqual('0.168.192.IN-ADDR.ARPA.'); + expect(parsed['$ttl']).toEqual('3600'); + }); + + it('should parse soa records', () => { + const records = parsed['soa']; + expect(records?.['name']).toEqual('@'); + expect(records?.['minimum']).toEqual(86400); + expect(records?.['expire']).toEqual(604800); + expect(records?.['retry']).toEqual(600); + expect(records?.['refresh']).toEqual(3600); + expect(records?.['serial']).toEqual(1406291485); + expect(records?.['rname']).toEqual('HOSTMASTER.MYDOMAIN.COM.'); + expect(records?.['mname']).toEqual('NS1.NAMESERVER.NET.'); + }); + + it('should parse ns records', () => { + const records = parsed['ns']; + expect(records?.length).toEqual(2); + expect(records?.[0]?.['name']).toEqual('@'); + expect(records?.[0]?.['host']).toEqual('NS1.NAMESERVER.NET.'); + expect(records?.[1]?.['name']).toEqual('@'); + expect(records?.[1]?.['host']).toEqual('NS2.NAMESERVER.NET.'); + }); + + it('should parse ptr records', () => { + const records = parsed['ptr']; + expect(records?.length).toEqual(8); + expect(records?.[0]?.['name']).toEqual('1'); + expect(records?.[0]?.['fullname']).toEqual(records?.[0]?.['name'] + '.' + parsed['$origin']); + expect(records?.[0]?.['host']).toEqual('HOST1.MYDOMAIN.COM.'); + expect(records?.[0]?.['ttl']).toEqual(400); + + expect(records?.[1]?.['name']).toEqual('2'); + expect(records?.[1]?.['fullname']).toEqual(records?.[1]?.['name'] + '.' + parsed['$origin']); + expect(records?.[1]?.['host']).toEqual('HOST2.MYDOMAIN.COM.'); + + expect(records?.[2]?.['name']).toEqual('3'); + expect(records?.[2]?.['fullname']).toEqual(records?.[2]?.['name'] + '.' + parsed['$origin']); + expect(records?.[2]?.['host']).toEqual('HOST3.MYDOMAIN.COM.'); + + expect(records?.[3]?.['name']).toEqual('4'); + expect(records?.[3]?.['fullname']).toEqual(records?.[3]?.['name'] + '.' + parsed['$origin']); + expect(records?.[3]?.['host']).toEqual('HOST4.MYDOMAIN.COM.'); + + expect(records?.[4]?.['name']).toEqual('4'); + expect(records?.[4]?.['fullname']).toEqual(records?.[4]?.['name'] + '.' + parsed['$origin']); + expect(records?.[4]?.['host']).toEqual('HOST5.MYDOMAIN.COM.'); + + expect(records?.[5]?.['name']).toEqual('4'); + expect(records?.[5]?.['fullname']).toEqual(records?.[5]?.['name'] + '.' + parsed['$origin']); + expect(records?.[5]?.['host']).toEqual('HOST6.MYDOMAIN.COM.'); + + expect(records?.[6]?.['name']).toEqual('10.3'); + expect(records?.[6]?.['fullname']).toEqual(records?.[6]?.['name'] + '.' + parsed['$origin']); + expect(records?.[6]?.['host']).toEqual('HOST3.MYDOMAIN.COM.'); + + expect(records?.[7]?.['name']).toEqual('10.4'); + expect(records?.[7]?.['fullname']).toEqual(records?.[7]?.['name'] + '.' + parsed['$origin']); + expect(records?.[7]?.['host']).toEqual('HOST4.MYDOMAIN.COM.'); + }); +}); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ______ __ __ __ // +// / \ / | / | / | // +// /$$$$$$ | ______ _______ ______ ______ ______ _$$ |_ ______ ______ __ __ $$ | $$ | // +// ______ $$ | _$$/ / \ / \ / \ / \ / \ / $$ | / \ / \ / \ / |$$ |__$$ | // +// / | $$ |/ |/$$$$$$ |$$$$$$$ |/$$$$$$ |/$$$$$$ |$$$$$$ |$$$$$$/ /$$$$$$ |/$$$$$$ | $$ \ /$$/ $$ $$ | // +// $$$$$$/ $$ |$$$$ |$$ $$ |$$ | $$ |$$ $$ |$$ | $$/ / $$ | $$ | __ $$ | $$ |$$ | $$/ $$ /$$/ $$$$$$$$ | // +// $$ \__$$ |$$$$$$$$/ $$ | $$ |$$$$$$$$/ $$ | /$$$$$$$ | $$ |/ |$$ \__$$ |$$ | $$ $$/ $$ | // +// $$ $$/ $$ |$$ | $$ |$$ |$$ | $$ $$ | $$ $$/ $$ $$/ $$ | $$$/ $$ | // +// $$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$$$$$$/ $$$$/ $$$$$$/ $$/ $/ $$/ // +// // +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +describe('reverse ipv4 generator', () => { + let generated; + let lines; + beforeEach(() => { + const json = require(__dirname + '/zonefile_reverse_ipv4.json'); + generated = zonefile.generate(json); + lines = generated.split('\n'); + }); + + it('should generate global info', () => { + expect(lines.includes('$ORIGIN 0.168.192.IN-ADDR.ARPA.')).toBeTrue(); + expect(lines.includes('$TTL 3600')).toBeTrue(); + }); + + it('should generate soa records', () => { + const records = ` + @ IN SOA NS1.NAMESERVER.NET. HOSTMASTER.MYDOMAIN.COM. ( + 1406291485 ;serial + 3600 ;refresh + 600 ;retry + 604800 ;expire + 86400 ;minimum ttl`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate ns records', () => { + const records = ` + @ IN NS NS1.NAMESERVER.NET. + @ IN NS NS2.NAMESERVER.NET.`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate ptr records', () => { + const records = ` + 1 400 IN PTR HOST1.MYDOMAIN.COM. + 2 IN PTR HOST2.MYDOMAIN.COM. + 3 IN PTR HOST3.MYDOMAIN.COM. + 4 IN PTR HOST4.MYDOMAIN.COM. + 4 IN PTR HOST5.MYDOMAIN.COM. + 4 IN PTR HOST6.MYDOMAIN.COM. + 10.3 IN PTR HOST3.MYDOMAIN.COM. + 10.4 IN PTR HOST4.MYDOMAIN.COM.`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); +}); + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ______ __ __ __ __ // +// / | / | / | / | / | // +// $$$$$$/ ____$$ | ______ _____ ____ ______ ______ _$$ |_ ______ _______ _______ ______ __ __ $$ | $$ | // +// ______ $$ | / $$ | / \ / \/ \ / \ / \ / $$ | / \ / \ / | / \ / \ / |$$ |__$$ | // +// / | $$ | /$$$$$$$ |/$$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$ |$$$$$$/ /$$$$$$ |$$$$$$$ |/$$$$$$$/ /$$$$$$ | $$ \ /$$/ $$ $$ | // +// $$$$$$/ $$ | $$ | $$ |$$ $$ |$$ | $$ | $$ |$$ | $$ |$$ | $$ | $$ | __ $$ $$ |$$ | $$ |$$ | $$ $$ | $$ /$$/ $$$$$$$$ | // +// _$$ |_ $$ \__$$ |$$$$$$$$/ $$ | $$ | $$ |$$ |__$$ |$$ \__$$ | $$ |/ |$$$$$$$$/ $$ | $$ |$$ \_____ $$$$$$$$/ $$ $$/ $$ | // +// / $$ |$$ $$ |$$ |$$ | $$ | $$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$ |$$ |$$ | $$$/ $$ | // +// $$$$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$/ $$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$$$$$$/ $/ $$/ // +// $$ | // +// $$ | // +// $$/ // +// // +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +describe('reverse ipv4 idempotence tests', () => { + it('should be idempotent', () => { + const text = fs.readFileSync(__dirname + '/zonefile_reverse_ipv4.txt', 'utf8'); + const json = zonefile.parse(text); + + const text1 = zonefile.generate(json); + const json1 = zonefile.parse(text1); + + expect(deepEqual(json, json1)).toBeTrue(); + + const text2 = zonefile.generate(json1); + + // exclude the date time line + expect(deepEqual(text1.split('\n').slice(2), text2.split('\n').slice(2))).toBeTrue(); + }); +}); + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +// _______ ______ // +// / \ / \ // +// $$$$$$$ | ______ ______ _______ ______ ______ __ __ /$$$$$$ | // +// ______ $$ |__$$ |/ \ / \ / | / \ / \ / \ / |$$ \__$$/ // +// / | $$ $$/ $$$$$$ |/$$$$$$ |/$$$$$$$/ /$$$$$$ |/$$$$$$ | $$ \ /$$/ $$ \ // +// $$$$$$/ $$$$$$$/ / $$ |$$ | $$/ $$ \ $$ $$ |$$ | $$/ $$ /$$/ $$$$$$$ | // +// $$ | /$$$$$$$ |$$ | $$$$$$ |$$$$$$$$/ $$ | $$ $$/ $$ \__$$ | // +// $$ | $$ $$ |$$ | / $$/ $$ |$$ | $$$/ $$ $$/ // +// $$/ $$$$$$$/ $$/ $$$$$$$/ $$$$$$$/ $$/ $/ $$$$$$/ // +// // +////////////////////////////////////////////////////////////////////////////////////////////////////////// +describe('reverse ipv6 parser', () => { + let parsed; + beforeEach(() => { + const text = fs.readFileSync(__dirname + '/zonefile_reverse_ipv6.txt', 'utf8'); + parsed = zonefile.parse(text); + }); + + it('should parse global info', () => { + expect(parsed['$origin']).toEqual('0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.'); + expect(parsed['$ttl']).toEqual('3600'); + }); + + it('should parse soa records', () => { + const records = parsed['soa']; + expect(records?.['name']).toEqual('@'); + expect(records?.['minimum']).toEqual(86400); + expect(records?.['expire']).toEqual(604800); + expect(records?.['retry']).toEqual(600); + expect(records?.['refresh']).toEqual(3600); + expect(records?.['serial']).toEqual(1406291485); + expect(records?.['rname']).toEqual('HOSTMASTER.MYDOMAIN.COM.'); + expect(records?.['mname']).toEqual('NS1.NAMESERVER.NET.'); + }); + + it('should parse ns records', () => { + const records = parsed['ns']; + expect(records?.length).toEqual(2); + expect(records?.[0]?.['name']).toEqual('@'); + expect(records?.[0]?.['host']).toEqual('NS1.NAMESERVER.NET.'); + expect(records?.[1]?.['name']).toEqual('@'); + expect(records?.[1]?.['host']).toEqual('NS2.NAMESERVER.NET.'); + }); + + it('should parse ptr records', () => { + const records = parsed['ptr']; + expect(records?.length).toEqual(2); + expect(records?.[0]?.['name']).toEqual('1'); + expect(records?.[0]?.['fullname']).toEqual(records?.[0]?.['name'] + '.' + parsed['$origin']); + expect(records?.[0]?.['host']).toEqual('HOST1.MYDOMAIN.COM.'); + expect(records?.[0]?.['ttl']).toEqual(400); + + expect(records?.[1]?.['name']).toEqual('2'); + expect(records?.[1]?.['fullname']).toEqual(records?.[1]?.['name'] + '.' + parsed['$origin']); + expect(records?.[1]?.['host']).toEqual('HOST2.MYDOMAIN.COM.'); + }); +}); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ______ __ ______ // +// / \ / | / \ // +// /$$$$$$ | ______ _______ ______ ______ ______ _$$ |_ ______ ______ __ __ /$$$$$$ | // +// ______ $$ | _$$/ / \ / \ / \ / \ / \ / $$ | / \ / \ / \ / |$$ \__$$/ // +// / | $$ |/ |/$$$$$$ |$$$$$$$ |/$$$$$$ |/$$$$$$ |$$$$$$ |$$$$$$/ /$$$$$$ |/$$$$$$ | $$ \ /$$/ $$ \ // +// $$$$$$/ $$ |$$$$ |$$ $$ |$$ | $$ |$$ $$ |$$ | $$/ / $$ | $$ | __ $$ | $$ |$$ | $$/ $$ /$$/ $$$$$$$ | // +// $$ \__$$ |$$$$$$$$/ $$ | $$ |$$$$$$$$/ $$ | /$$$$$$$ | $$ |/ |$$ \__$$ |$$ | $$ $$/ $$ \__$$ | // +// $$ $$/ $$ |$$ | $$ |$$ |$$ | $$ $$ | $$ $$/ $$ $$/ $$ | $$$/ $$ $$/ // +// $$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$$$$$$/ $$$$/ $$$$$$/ $$/ $/ $$$$$$/ // +// // +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +describe('reverse ipv4 generator', () => { + let generated; + let lines; + beforeEach(() => { + const json = require(__dirname + '/zonefile_reverse_ipv6.json'); + generated = zonefile.generate(json); + lines = generated.split('\n'); + }); + + it('should generate global info', () => { + expect(lines.includes('$ORIGIN 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.')).toBeTrue(); + expect(lines.includes('$TTL 3600')).toBeTrue(); + }); + + it('should generate soa records', () => { + const records = ` + @ IN SOA NS1.NAMESERVER.NET. HOSTMASTER.MYDOMAIN.COM. ( + 1406291485 ;serial + 3600 ;refresh + 600 ;retry + 604800 ;expire + 86400 ;minimum ttl`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate ns records', () => { + const records = ` + @ IN NS NS1.NAMESERVER.NET. + @ IN NS NS2.NAMESERVER.NET.`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); + + it('should generate ptr records', () => { + const records = ` + 1 400 IN PTR HOST1.MYDOMAIN.COM. + 2 IN PTR HOST2.MYDOMAIN.COM.`; + records.trim().split('\n').forEach(record => { + expect(lines).toContain(record.trim()); + }); + }); +}); + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ______ __ __ ______ // +// / | / | / | / \ // +// $$$$$$/ ____$$ | ______ _____ ____ ______ ______ _$$ |_ ______ _______ _______ ______ __ __ /$$$$$$ | // +// ______ $$ | / $$ | / \ / \/ \ / \ / \ / $$ | / \ / \ / | / \ / \ / |$$ \__$$/ // +// / | $$ | /$$$$$$$ |/$$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$ |$$$$$$/ /$$$$$$ |$$$$$$$ |/$$$$$$$/ /$$$$$$ | $$ \ /$$/ $$ \ // +// $$$$$$/ $$ | $$ | $$ |$$ $$ |$$ | $$ | $$ |$$ | $$ |$$ | $$ | $$ | __ $$ $$ |$$ | $$ |$$ | $$ $$ | $$ /$$/ $$$$$$$ | // +// _$$ |_ $$ \__$$ |$$$$$$$$/ $$ | $$ | $$ |$$ |__$$ |$$ \__$$ | $$ |/ |$$$$$$$$/ $$ | $$ |$$ \_____ $$$$$$$$/ $$ $$/ $$ \__$$ | // +// / $$ |$$ $$ |$$ |$$ | $$ | $$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$ |$$ |$$ | $$$/ $$ $$/ // +// $$$$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$/ $$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$$$$$$/ $/ $$$$$$/ // +// $$ | // +// $$ | // +// $$/ // +// // +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +describe('reverse ipv4 idempotence tests', () => { + it('should be idempotent', () => { + const text = fs.readFileSync(__dirname + '/zonefile_reverse_ipv6.txt', 'utf8'); + const json = zonefile.parse(text); + + const text1 = zonefile.generate(json); + const json1 = zonefile.parse(text1); + + expect(deepEqual(json, json1)).toBeTrue(); + + const text2 = zonefile.generate(json1); + + // exclude the date time line + expect(deepEqual(text1.split('\n').slice(2), text2.split('\n').slice(2))).toBeTrue(); + }); +}); \ No newline at end of file diff --git a/specs/zonefile_forward.json b/tests/zonefile_forward.json similarity index 100% rename from specs/zonefile_forward.json rename to tests/zonefile_forward.json diff --git a/specs/zonefile_forward.txt b/tests/zonefile_forward.txt similarity index 100% rename from specs/zonefile_forward.txt rename to tests/zonefile_forward.txt diff --git a/tests/zonefile_reverse_ipv4.json b/tests/zonefile_reverse_ipv4.json new file mode 100644 index 0000000..cff79ae --- /dev/null +++ b/tests/zonefile_reverse_ipv4.json @@ -0,0 +1,67 @@ +{ + "$origin": "0.168.192.IN-ADDR.ARPA.", + "$ttl": "3600", + "soa": { + "name": "@", + "minimum": 86400, + "expire": 604800, + "retry": 600, + "refresh": 3600, + "serial": 1406291485, + "rname": "HOSTMASTER.MYDOMAIN.COM.", + "mname": "NS1.NAMESERVER.NET." + }, + "ns": [ + { + "name": "@", + "host": "NS1.NAMESERVER.NET." + }, + { + "name": "@", + "host": "NS2.NAMESERVER.NET." + } + ], + "ptr": [ + { + "name": "1", + "fullname": "1.0.168.192.IN-ADDR.ARPA.", + "host": "HOST1.MYDOMAIN.COM.", + "ttl": 400 + }, + { + "name": "2", + "fullname": "2.0.168.192.IN-ADDR.ARPA.", + "host": "HOST2.MYDOMAIN.COM." + }, + { + "name": "3", + "fullname": "3.0.168.192.IN-ADDR.ARPA.", + "host": "HOST3.MYDOMAIN.COM." + }, + { + "name": "4", + "fullname": "4.0.168.192.IN-ADDR.ARPA.", + "host": "HOST4.MYDOMAIN.COM." + }, + { + "name": "4", + "fullname": "4.0.168.192.IN-ADDR.ARPA.", + "host": "HOST5.MYDOMAIN.COM." + }, + { + "name": "4", + "fullname": "4.0.168.192.IN-ADDR.ARPA.", + "host": "HOST6.MYDOMAIN.COM." + }, + { + "name": "10.3", + "fullname": "10.3.0.168.192.IN-ADDR.ARPA.", + "host": "HOST3.MYDOMAIN.COM." + }, + { + "name": "10.4", + "fullname": "10.4.0.168.192.IN-ADDR.ARPA.", + "host": "HOST4.MYDOMAIN.COM." + } + ] +} \ No newline at end of file diff --git a/test/zonefile_reverse.txt b/tests/zonefile_reverse_ipv4.txt similarity index 83% rename from test/zonefile_reverse.txt rename to tests/zonefile_reverse_ipv4.txt index 88dc9c1..2857cd3 100644 --- a/test/zonefile_reverse.txt +++ b/tests/zonefile_reverse_ipv4.txt @@ -11,15 +11,13 @@ $TTL 3600 @ NS NS1.NAMESERVER.NET. @ NS NS2.NAMESERVER.NET. -1 PTR HOST1.MYDOMAIN.COM. +1 400 PTR HOST1.MYDOMAIN.COM. 2 PTR HOST2.MYDOMAIN.COM. -$ORIGIN 30.168.192.in-addr.arpa. 3 PTR HOST3.MYDOMAIN.COM. 4 PTR HOST4.MYDOMAIN.COM. PTR HOST5.MYDOMAIN.COM. IN PTR HOST6.MYDOMAIN.COM. -$ORIGIN 168.192.in-addr.arpa. 10.3 PTR HOST3.MYDOMAIN.COM. 10.4 PTR HOST4.MYDOMAIN.COM. diff --git a/tests/zonefile_reverse_ipv6.json b/tests/zonefile_reverse_ipv6.json new file mode 100644 index 0000000..ae797e1 --- /dev/null +++ b/tests/zonefile_reverse_ipv6.json @@ -0,0 +1,37 @@ +{ + "$origin": "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.", + "$ttl": "3600", + "soa": { + "name": "@", + "minimum": 86400, + "expire": 604800, + "retry": 600, + "refresh": 3600, + "serial": 1406291485, + "rname": "HOSTMASTER.MYDOMAIN.COM.", + "mname": "NS1.NAMESERVER.NET." + }, + "ns": [ + { + "name": "@", + "host": "NS1.NAMESERVER.NET." + }, + { + "name": "@", + "host": "NS2.NAMESERVER.NET." + } + ], + "ptr": [ + { + "name": "1", + "fullname": "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.", + "host": "HOST1.MYDOMAIN.COM.", + "ttl": 400 + }, + { + "name": "2", + "fullname": "2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.", + "host": "HOST2.MYDOMAIN.COM." + } + ] +} \ No newline at end of file diff --git a/test/zonefile_reverse_ipv6.txt b/tests/zonefile_reverse_ipv6.txt similarity index 83% rename from test/zonefile_reverse_ipv6.txt rename to tests/zonefile_reverse_ipv6.txt index fef41aa..8d7fa3f 100644 --- a/test/zonefile_reverse_ipv6.txt +++ b/tests/zonefile_reverse_ipv6.txt @@ -8,8 +8,8 @@ $TTL 3600 86400 ;minimum ttl ) -@ NS NS1.NAMESERVER.NET. +@ NS NS1.NAMESERVER.NET. @ NS NS2.NAMESERVER.NET. -1 PTR HOST1.MYDOMAIN.COM. +1 400 PTR HOST1.MYDOMAIN.COM. 2 PTR HOST2.MYDOMAIN.COM.