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" ] } } 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 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 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"] + } +} 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 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], ]), ]),