This commit is contained in:
quoije
2023-05-10 21:03:22 -04:00
parent ef1b411c12
commit bd732815c7
1304 changed files with 192970 additions and 5407 deletions
+17
View File
@@ -0,0 +1,17 @@
const isFQDN = require('validator').isFQDN;
/*
Check if all the elements are valid domains
*/
module.exports = function (chai) {
chai.Assertion.addProperty('isFQDN', function () {
var obj = this._obj, _this = this;
obj.forEach(function(o){
_this.assert(
isFQDN(o)
, 'expected "' + o + '" to be a valid domain'
, 'expected "' + o + '" to not be all lowecase'
);
});
});
};
+15
View File
@@ -0,0 +1,15 @@
/*
Check if all the elements are in lowercase
*/
module.exports = function (chai) {
chai.Assertion.addProperty('lowercase', function () {
var obj = this._obj, _this = this;
obj.forEach(function(o){
_this.assert(
o === o.toLowerCase()
, 'expected "' + o + '" to be all lowercase'
, 'expected "' + o + '" to not be all lowercase'
);
});
});
};
+20
View File
@@ -0,0 +1,20 @@
var wildcard = require('../../wildcard');
const _ = require('lodash');
/*
Check if all the elements are in lowercase
*/
module.exports = function (chai) {
chai.Assertion.addProperty('notInWildcard', function () {
this._obj.forEach(domain => {
if (new RegExp(/(.+(?:\.[\w-]+\.[\w-]+)+)$/).test(domain)) {
wildcard.forEach(wildcard => {
this.assert(
! _.endsWith(domain, wildcard)
, '"' + domain + '" is already in the wildcard list'
);
})
}
});
});
};
+33
View File
@@ -0,0 +1,33 @@
const _ = require('lodash');
const domains = require('../index');
const chai = require('chai');
const expect = chai.expect;
chai.use(require("chai-sorted"));
chai.use(require('./helpers/lowercase'));
chai.use(require('./helpers/isFQDN'));
chai.use(require('./helpers/notInWildcard'));
describe('Domains', function(){
it('should be an array', function(){
expect(domains).to.be.a('array');
});
it('should have at least one domain', function(){
expect(domains).to.have.length.above(0);
});
it('should be in alphabetical order', function(){
expect(domains).to.be.sorted();
});
it('should not have duplicates', function(){
expect(domains).to.deep.equal(_.uniq(domains));
});
it('should be lowercase', function(){
expect(domains).to.be.all.lowercase;
});
it('should be a valid domain', function(){
expect(domains).to.be.all.isFQDN;
});
it('should not be a wildcard domain', function(){
expect(domains).to.be.all.notInWildcard;
});
});
+29
View File
@@ -0,0 +1,29 @@
const _ = require('lodash');
const domains = require('../wildcard');
const chai = require('chai');
const expect = chai.expect;
chai.use(require("chai-sorted"));
chai.use(require('./helpers/lowercase'));
chai.use(require('./helpers/isFQDN'));
describe('Wildcard domains', function(){
it('should be an array', function(){
expect(domains).to.be.a('array');
});
it('should have at least one domain', function(){
expect(domains).to.have.length.above(0);
});
it('should be in alphabetical order', function(){
expect(domains).to.be.sorted();
});
it('should not have duplicates', function(){
expect(domains).to.deep.equal(_.uniq(domains));
});
it('should be lowercase', function(){
expect(domains).to.be.all.lowercase;
});
it('should be a valid domain', function(){
expect(domains).to.be.all.isFQDN;
});
});