Adds check for valid URL for URL record type

This commit is contained in:
Akshay Nair committed 2021-05-20 21:53:05 +05:30
1 parent 642b1d1a10
commit c184dfaef7
2 files changed
+7 -2

No files matched your search

+3
View File
@@ -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', () => {
+4 -2
View File
@@ -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],
]),
]),