From d14991db0facf18a8a5ed09f7a90ed5322dc61c2 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Mon, 5 Oct 2020 00:30:47 +0530 Subject: [PATCH] Fixes cname validation --- tests/domain-utils.test.js | 3 ++- utils/domain.js | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/domain-utils.test.js b/tests/domain-utils.test.js index fc914c783..cc08e5df2 100644 --- a/tests/domain-utils.test.js +++ b/tests/domain-utils.test.js @@ -23,13 +23,14 @@ describe('validateDomainData', () => { { forceHttps: false }, { forceHttps: 1 }, { name: 'helo' }, - { record: { CNAME: ['sd'] } }, { name: 'wwow', record: { A: ['12312'] } }, ...['', ' ', undefined, 'hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '12112**dsd', Array(101).fill('a').join('')] .map(name => ({ ...defaultDomain, name, })), + { ...defaultDomain, record: { CNAME: ['sd'], A: ['121,3213'] } }, + //{ ...defaultDomain, record: { FOOBAR: ['sd'] } }, { ...defaultDomain, owner: {}, }, { ...defaultDomain, owner: { username: 'hwelo', }, }, { ...defaultDomain, owner: { email: 'hwelo' }, }, diff --git a/utils/domain.js b/utils/domain.js index 97b73f4a4..0108ba548 100644 --- a/utils/domain.js +++ b/utils/domain.js @@ -4,6 +4,8 @@ const R = require('ramda'); const DOMAINS_PATH = path.resolve('domains'); +const log = m => x => console.log(m, x) || x; + const toDomain = str => path.join(DOMAINS_PATH, str); const toDomainData = R.compose(require, toDomain); @@ -23,6 +25,11 @@ const validate = pattern => data => R.compose( R.toPairs, )(pattern); +const validateCNAME = R.allPass([ + R.compose(R.equals(1), R.length, R.keys), + R.propSatisfies(R.is(Array), 'CNAME'), +]); + const validateDomainData = validate({ name: { reason: 'The name of the file is invalid', @@ -52,10 +59,9 @@ const validateDomainData = validate({ reason: 'Invalid record', fn: R.allPass([ R.is(Object), - R.compose(hasLengthLessThan(1), R.keys), - R.anyPass([ - R.propSatisfies(R.is(Array), 'CNAME'), - R.propSatisfies(R.is(Array), 'A'), + R.cond([ + [R.prop('CNAME'), validateCNAME], + [R.T, R.T], ]), ]), },