diff --git a/tests/domain-utils.test.js b/tests/domain-utils.test.js index cc08e5df2..1946978fa 100644 --- a/tests/domain-utils.test.js +++ b/tests/domain-utils.test.js @@ -10,13 +10,17 @@ describe('getDomains', () => { const defaultDomain = { name: 'aaa', forceHttps: false, - record: { A: ['121.121.121.121'] }, + record: { + A: ['121.121.121.121'] + }, owner: { username: 'betsy', email: 'betsyfuckyoassup@foobar.com', }, }; +const getstroflen = len => Array(len).fill('a').join(''); + describe('validateDomainData', () => { const invalidCases = [ {}, @@ -24,8 +28,7 @@ describe('validateDomainData', () => { { forceHttps: 1 }, { name: 'helo' }, { name: 'wwow', record: { A: ['12312'] } }, - ...['', ' ', undefined, 'hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '12112**dsd', Array(101).fill('a').join('')] - .map(name => ({ + ...['', ' ', undefined, 'hlo wld', 'g32++13', 'ajsdD_123yq', 'khsda%', '122*dsd', getstroflen(101)].map(name => ({ ...defaultDomain, name, })), @@ -44,7 +47,7 @@ describe('validateDomainData', () => { })), { ...defaultDomain, - description: Array(99).fill('a').join(''), + description: getstroflen(99), }, ]; @@ -59,6 +62,7 @@ describe('validateDomainData', () => { it('should return true if the name is valid', () => { validCases.forEach(data => { const { valid, errors } = validateDomainData(data); + if (!valid) console.log(errors); expect(valid).toBe(true); expect(errors).toEqual([]); }); diff --git a/utils/domain.js b/utils/domain.js index 0108ba548..69f1d83fd 100644 --- a/utils/domain.js +++ b/utils/domain.js @@ -25,9 +25,9 @@ const validate = pattern => data => R.compose( R.toPairs, )(pattern); -const validateCNAME = R.allPass([ +const validateNameRecord = type => R.allPass([ R.compose(R.equals(1), R.length, R.keys), - R.propSatisfies(R.is(Array), 'CNAME'), + R.propSatisfies(R.is(Array), type), ]); const validateDomainData = validate({ @@ -60,7 +60,9 @@ const validateDomainData = validate({ fn: R.allPass([ R.is(Object), R.cond([ - [R.prop('CNAME'), validateCNAME], + [R.prop('CNAME'), validateNameRecord('CNAME')], + [R.prop('ALIAS'), validateNameRecord('ALIAS')], + [R.prop('A'), R.propSatisfies(R.is(Array), 'A')], [R.T, R.T], ]), ]),