From db45c9af5600b1a9acdd82a47598218ab298c969 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 17 Sep 2023 13:10:33 +0530 Subject: [PATCH 1/6] feat(script): adds support for multiple txt records --- tests/register.test.js | 50 ++++++++++++++++++++++++++++++++------- tests/validations.test.js | 2 +- utils/validations.js | 2 +- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/tests/register.test.js b/tests/register.test.js index 88eb4694e..e472588e7 100644 --- a/tests/register.test.js +++ b/tests/register.test.js @@ -3,7 +3,16 @@ const { toHostList, registerDomains } = require('../scripts/register-domains'); const { TTL, DOMAIN_DOMAIN } = require('../utils/constants'); const { getDomainService } = require('../utils/domain-service'); -const getCpanel = ({ zone, addZone, removeZone, redir, addRedir, removeRedir } = {}) => ({ +const getCpanel = ({ + zone, + addZone, + removeZone, + redir, + addRedir, + removeRedir, + addEmail, + removeEmail +} = {}) => ({ zone: { fetch: (_) => zone(), add: (rec) => addZone(rec), @@ -95,13 +104,16 @@ describe('registerDomains', () => { it('should add the new set hosts', async () => { const localHosts = [ - { name: 'a', record: { CNAME: 'boo', URL: 'z' } }, - { name: 'b', record: { CNAME: 'xaa', URL: 'x' } }, - { name: 'c', record: { CNAME: 'yello', URL: 'https://google.com' } }, + { name: 'a', record: { CNAME: 'boo' } }, + { name: 'b', record: { A: [ '1.1.1.1', '1.1.1.2' ], MX: 'somemx', TXT: 'some txt' } }, + { name: 'c', record: { URL: 'https://google.com' } }, + { name: 'd', record: { CNAME: 'foobar' } }, + { name: 'e', record: { A: [ '2.2.2.2' ], TXT: ['some', 'extra', 'txt'] } } ]; const remoteHosts = [ { line: 1, name: 'a', type: 'CNAME', address: 'boo' }, - { line: 2, name: 'b', type: 'CNAME', address: 'xaa' }, + { line: 2, name: 'b', type: 'MX', address: 'othermx' }, + { line: 3, name: 'd', type: 'CNAME', address: 'foobaz' }, ]; const remoteRedirections = [ { domain: `b.${DOMAIN_DOMAIN}`, destination: 'x' }, @@ -111,10 +123,30 @@ describe('registerDomains', () => { const domainService = mockDS({ zones: remoteHosts, redirections: remoteRedirections }); await registerDomains({ getDomains: async () => localHosts, domainService }); - expect(addZone).toBeCalledTimes(1); - expect(removeZone).toBeCalledTimes(0); - expect(addRedir).toBeCalledTimes(2); - expect(removeRedir).toBeCalledTimes(1); + expect(addZone).toBeCalledTimes(8); + expect(addZone).toHaveBeenCalledWith({ name: 'b', type: 'A', address: '1.1.1.2', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'd', type: 'CNAME', cname: 'foobar', address: 'foobar', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'b', type: 'A', address: '1.1.1.2', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'b', type: 'TXT', address: 'some txt', txtdata: 'some txt', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'A', address: '2.2.2.2', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'TXT', address: 'some', txtdata: 'some', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'TXT', address: 'extra', txtdata: 'extra', line: undefined }); + expect(addZone).toHaveBeenCalledWith({ name: 'e', type: 'TXT', address: 'txt', txtdata: 'txt', line: undefined }); + + expect(removeZone).toBeCalledTimes(1); + expect(removeZone).toHaveBeenCalledWith({ line: 3 }); + + expect(addRedir).toBeCalledTimes(1); + expect(addRedir).toHaveBeenCalledWith({ + domain: 'c.booboo.xyz', + redirect: 'https://google.com', + redirect_wildcard: 1, + redirect_www: 1, + type: 'permanent', + }); + + expect(addEmail).toBeCalledTimes(1); + expect(addEmail).toHaveBeenCalledWith({ domain: 'b.is-a.dev', exchanger: 'somemx', priority: 20 }); }); }); diff --git a/tests/validations.test.js b/tests/validations.test.js index e97ddbb08..219546bad 100644 --- a/tests/validations.test.js +++ b/tests/validations.test.js @@ -54,7 +54,6 @@ describe('validateDomainData', () => { { ...defaultDomain, record: { CNAME: 'foobar.com', A: ['11.22.22.33'] } }, { ...defaultDomain, record: { CNAME: 'foobar.com', MX: ['ALT4.ASPMX.L.GOOGLE.COM'] } }, ...INVALID_NAMES.map(name => ({ ...defaultDomain, name })).slice(0, 1), - { ...defaultDomain, record: { TXT: ['foobar wow nice!!!'] } }, { ...defaultDomain, name: 'a.b' }, { ...defaultDomain, name: 'ww2.baa' }, { ...defaultDomain, name: 'help.baa' }, @@ -86,6 +85,7 @@ describe('validateDomainData', () => { { ...defaultDomain, name: '_github-challenge-phenax.akshay' }, { ...defaultDomain, name: '_github-challenge-hello01-ga' }, { ...defaultDomain, name: '_github-challenge-hello01_ga' }, + { ...defaultDomain, record: { TXT: ['foobar wow nice!!!', 'more text'] } }, ]; it('should return false for invalid data', () => { diff --git a/utils/validations.js b/utils/validations.js index 963e8ed3d..9a99343fa 100644 --- a/utils/validations.js +++ b/utils/validations.js @@ -74,7 +74,7 @@ const validateDomainData = validate({ [R.has('A'), validateARecord('A')], [R.has('URL'), R.propSatisfies(isValidURL, 'URL')], [R.has('MX'), validateMXRecord('MX')], - [R.has('TXT'), R.propSatisfies(R.is(String), 'TXT')], + [R.has('TXT'), R.propSatisfies(or([ R.is(String), R.is(Array) ]), 'TXT')], [R.T, R.T], ]), ]), From d24c7220b0f94236f0da0fe3cf5fb39598fda22f Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 17 Sep 2023 14:51:19 +0530 Subject: [PATCH 2/6] chore(domains): adds multiple txt example for akshay.json --- domains/akshay.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/domains/akshay.json b/domains/akshay.json index 130700660..095fe26f3 100644 --- a/domains/akshay.json +++ b/domains/akshay.json @@ -6,6 +6,7 @@ "email": "phenax5@gmail.com" }, "record": { - "URL": "https://phenax.github.io" + "URL": "https://phenax.github.io", + "TXT": [ "Hello there!", "It's me, Akshay" ] } } From ed1c83abf307c308ab58693e94ed4792f3510884 Mon Sep 17 00:00:00 2001 From: DenDanskeMine Date: Sun, 17 Sep 2023 12:54:20 +0200 Subject: [PATCH 3/6] feat(domain): christian.is-a.dev --- domains/christian.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 domains/christian.json diff --git a/domains/christian.json b/domains/christian.json new file mode 100644 index 000000000..5a1ce84c4 --- /dev/null +++ b/domains/christian.json @@ -0,0 +1,11 @@ +{ + "owner": { + "username": "DenDanskeMine", + "email": "christianhrose@outlook.dk" + }, + "record": { + "A": ["217.174.245.249"], + "MX": ["hosts.is-a.dev"], + "TXT": "v=spf1 a mx ip4:217.174.245.249 ~all" + } +} \ No newline at end of file From e5bb66c8709d65657da2b2a7ac41aae1d6927ca0 Mon Sep 17 00:00:00 2001 From: Noah <108767214+NoahPrm@users.noreply.github.com> Date: Sun, 17 Sep 2023 15:30:56 +0200 Subject: [PATCH 4/6] feat(domain): add `noah.is-a.dev` --- domains/noah.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 domains/noah.json diff --git a/domains/noah.json b/domains/noah.json new file mode 100644 index 000000000..211aab7f6 --- /dev/null +++ b/domains/noah.json @@ -0,0 +1,10 @@ +{ + "owner": { + "username": "NoahPrm", + "email": "noah.parmentier@icloud.com" + }, + + "record": { + "A": ["185.143.241.106"] + } +} From 62a66dc923676fbb7288b6ac5727484ca409b117 Mon Sep 17 00:00:00 2001 From: MrBogdanYT Date: Sun, 17 Sep 2023 17:21:13 +0300 Subject: [PATCH 5/6] feat(domain): bogdan.is-a.dev --- domains/bogdan.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 domains/bogdan.json diff --git a/domains/bogdan.json b/domains/bogdan.json new file mode 100644 index 000000000..052d58fbe --- /dev/null +++ b/domains/bogdan.json @@ -0,0 +1,11 @@ +{ + "owner": { + "username": "MrBogdanYT", + "email": "hysbskyblockgod@gmail.com" + }, + "record": { + "A": ["217.174.245.249"], + "MX": ["hosts.is-a.dev"], + "TXT": "v=spf1 a mx ip4:217.174.245.249 ~all" + } +} \ No newline at end of file From ccdb5a988bcaa91f7f8450d21f6a88a04f4a6a38 Mon Sep 17 00:00:00 2001 From: npc-123 Date: Sun, 17 Sep 2023 22:33:59 +0700 Subject: [PATCH 6/6] feat(domain): npc.is-a.dev --- domains/npc.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 domains/npc.json diff --git a/domains/npc.json b/domains/npc.json new file mode 100644 index 000000000..5eb5e5abe --- /dev/null +++ b/domains/npc.json @@ -0,0 +1,11 @@ +{ + "owner": { + "username": "npc-123", + "email": "aziznasrul85@gmail.com" + }, + "record": { + "A": ["217.174.245.249"], + "MX": ["hosts.is-a.dev"], + "TXT": "v=spf1 a mx ip4:217.174.245.249 ~all" + } +} \ No newline at end of file