mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-14 20:17:19 +00:00
fix(script): fixes validation for ipv6
This commit is contained in:
5 files changed
+12
-5
No files matched your search
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
"author": "Akshay Nair <phenax5@gmail.com>",
|
"author": "Akshay Nair <phenax5@gmail.com>",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"is-ip": "^5.0.1",
|
"ip-regex": "^5.0.0",
|
||||||
"ramda": "^0.27.1"
|
"ramda": "^0.27.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const { validateDomainData, isValidDomain } = require('../utils/validations');
|
const { validateDomainData, isValidDomain } = require('../utils/validations');
|
||||||
const INVALID_NAMES = require('../utils/invalid-domains.json');
|
const INVALID_NAMES = require('../utils/invalid-domains.json');
|
||||||
|
const ipRegex = require('ip-regex');
|
||||||
|
|
||||||
const defaultDomain = {
|
const defaultDomain = {
|
||||||
name: 'aaa',
|
name: 'aaa',
|
||||||
@@ -60,6 +61,10 @@ describe('validateDomainData', () => {
|
|||||||
{ ...defaultDomain, name: 'help.baa' },
|
{ ...defaultDomain, name: 'help.baa' },
|
||||||
{ ...defaultDomain, name: '_github-pages-challenge-is-a-dev' },
|
{ ...defaultDomain, name: '_github-pages-challenge-is-a-dev' },
|
||||||
{ ...defaultDomain, name: '_github-challenge-is-a-dev' },
|
{ ...defaultDomain, name: '_github-challenge-is-a-dev' },
|
||||||
|
{ ...defaultDomain, record: { AAAA: [] } },
|
||||||
|
{ ...defaultDomain, record: { AAAA: ['182.22.222.22', '::1'] } },
|
||||||
|
{ ...defaultDomain, record: { AAAA: '182.22.222.22' } },
|
||||||
|
{ ...defaultDomain, record: { A: '::1' } },
|
||||||
];
|
];
|
||||||
|
|
||||||
const validCases = [
|
const validCases = [
|
||||||
@@ -86,6 +91,8 @@ describe('validateDomainData', () => {
|
|||||||
{ ...defaultDomain, name: '_github-challenge-phenax.akshay' },
|
{ ...defaultDomain, name: '_github-challenge-phenax.akshay' },
|
||||||
{ ...defaultDomain, name: '_github-challenge-hello01-ga' },
|
{ ...defaultDomain, name: '_github-challenge-hello01-ga' },
|
||||||
{ ...defaultDomain, name: '_github-challenge-hello01_ga' },
|
{ ...defaultDomain, name: '_github-challenge-hello01_ga' },
|
||||||
|
{ ...defaultDomain, record: { AAAA: ['::1', '2001:db8:3333:4444:5555:6666:7777:8888'] } },
|
||||||
|
{ ...defaultDomain, record: { A: ['122.222.222.222'] } },
|
||||||
];
|
];
|
||||||
|
|
||||||
it('should return false for invalid data', () => {
|
it('should return false for invalid data', () => {
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ const DOMAINS_PATH = path.resolve('domains');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
ENV,
|
ENV,
|
||||||
IS_TEST,
|
IS_TEST,
|
||||||
VALID_RECORD_TYPES: ['CNAME', 'A', 'URL', 'MX', 'TXT'],
|
VALID_RECORD_TYPES: ['CNAME', 'A', 'URL', 'MX', 'TXT', 'AAAA'],
|
||||||
DOMAIN_DOMAIN: DOMAIN_DOMAIN || 'booboo.xyz',
|
DOMAIN_DOMAIN: DOMAIN_DOMAIN || 'booboo.xyz',
|
||||||
DOMAIN_USER: IS_TEST ? 'testuser' : DOMAIN_USER,
|
DOMAIN_USER: IS_TEST ? 'testuser' : DOMAIN_USER,
|
||||||
DOMAIN_API_KEY: IS_TEST ? 'testkey' : DOMAIN_API_KEY,
|
DOMAIN_API_KEY: IS_TEST ? 'testkey' : DOMAIN_API_KEY,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const R = require('ramda');
|
|||||||
const { VALID_RECORD_TYPES } = require('./constants');
|
const { VALID_RECORD_TYPES } = require('./constants');
|
||||||
const { or, and, validate, between, testRegex, withLengthEq, withLengthGte } = require('./helpers');
|
const { or, and, validate, between, testRegex, withLengthEq, withLengthGte } = require('./helpers');
|
||||||
const INVALID_NAMES = require('./invalid-domains.json');
|
const INVALID_NAMES = require('./invalid-domains.json');
|
||||||
const { isIPv4, isIPv6 } = require('is-ip');
|
const { default: ipRegex } = require('ip-regex');
|
||||||
|
|
||||||
const isValidURL = and([R.is(String), testRegex(/^https?:\/\//ig)]);
|
const isValidURL = and([R.is(String), testRegex(/^https?:\/\//ig)]);
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ const validateCnameRecord = type => and([
|
|||||||
const validateARecord = type => and([
|
const validateARecord = type => and([
|
||||||
R.propIs(Array, type),
|
R.propIs(Array, type),
|
||||||
R.propSatisfies(withLengthGte(1), type),
|
R.propSatisfies(withLengthGte(1), type),
|
||||||
R.all(isIPv4),
|
R.all(testRegex(ipRegex.v4({ exact: true }))),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const validateMXRecord = type => and([
|
const validateMXRecord = type => and([
|
||||||
@@ -30,7 +30,7 @@ const validateMXRecord = type => and([
|
|||||||
const validateAAAARecord = R.propSatisfies(and([
|
const validateAAAARecord = R.propSatisfies(and([
|
||||||
R.is(Array),
|
R.is(Array),
|
||||||
withLengthGte(1),
|
withLengthGte(1),
|
||||||
R.all(isIPv6),
|
R.all(testRegex(ipRegex.v6({ exact: true }))),
|
||||||
]))
|
]))
|
||||||
|
|
||||||
const checkRestrictedNames = R.complement(R.includes(R.__, INVALID_NAMES))
|
const checkRestrictedNames = R.complement(R.includes(R.__, INVALID_NAMES))
|
||||||
|
|||||||
Reference in new issue
Block a user