mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-08-06 18:23:06 +00:00
Fixes cname validation
This commit is contained in:
@@ -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
@@ -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],
|
||||
]),
|
||||
]),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user