Fixes cname validation

This commit is contained in:
Akshay Nair
2020-10-05 00:30:47 +05:30
parent d1575fe75c
commit d14991db0f
2 changed files with 12 additions and 5 deletions
+2 -1
View File
@@ -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' }, },
+10 -4
View File
@@ -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],
]),
]),
},