diff --git a/tests/validations.test.js b/tests/validations.test.js index 057ffc3c84..2971b82a75 100644 --- a/tests/validations.test.js +++ b/tests/validations.test.js @@ -31,6 +31,7 @@ describe('validateDomainData', () => { { ...defaultDomain, owner: { email: 'hwelo' }, }, { ...defaultDomain, record: { CNAME: 'http://foobar.com' } }, { ...defaultDomain, record: { CNAME: 'https://foobar.com' } }, + { ...defaultDomain, record: { URL: 'foobar.com' } }, ]; const validCases = [ @@ -44,6 +45,8 @@ describe('validateDomainData', () => { description: getstroflen(99), }, { ...defaultDomain, record: { CNAME: 'aa.sd', URL: '121,3213' } }, + { ...defaultDomain, record: { URL: 'https://foobar.com' } }, + { ...defaultDomain, record: { URL: 'http://foobar.com/foobar/' } }, ]; it('should return false for invalid data', () => { diff --git a/utils/validations.js b/utils/validations.js index 4d04448163..7365a2ab09 100644 --- a/utils/validations.js +++ b/utils/validations.js @@ -2,11 +2,13 @@ const R = require('ramda'); const { VALID_RECORD_TYPES } = require('./constants'); const { or, and, validate, between, testRegex, withLengthEq, withLengthGte } = require('./helpers'); +const isValidURL = testRegex(/^https?:\/\//ig); + const validateCnameRecord = key => and([ R.propSatisfies(R.is(String), key), R.compose(withLengthEq(1), R.reject(R.equals('URL')), R.keys), R.propSatisfies(withLengthGte(3), key), - R.propSatisfies(R.complement(testRegex(/^https?:\/\//ig)), key), + R.propSatisfies(R.complement(isValidURL), key), ]); const validateARecord = key => and([ @@ -46,7 +48,7 @@ const validateDomainData = validate({ R.cond([ [R.has('CNAME'), validateCnameRecord('CNAME')], [R.has('A'), validateARecord('A')], - [R.has('URL'), R.propSatisfies(R.is(String), 'URL')], + [R.has('URL'), R.propSatisfies(isValidURL, 'URL')], [R.T, R.T], ]), ]),