0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00
ghost/test/unit/data/validator/validator_spec.js
Hannah Wolfe 0fe8426f97
Renamed validation to validator + better public API
- renamed our internal validation library to "validator" - which is the same as the tool it wraps
- updated the public api so that validator methods are directly exposed
- this will make it a drop-in replacement for validator-js
- in turn, this allows us to pull this out into @tryghost/validator, and use our own wrapper instead of the 3rd party library
2021-06-15 15:32:36 +01:00

42 lines
1.5 KiB
JavaScript

const should = require('should');
const validator = require('../../../../core/server/data/validator');
const validators = ['isLength',
'isEmpty',
'isURL',
'isEmail',
'isIn',
'isUUID',
'isBoolean',
'isInt',
'isLowercase',
'equals',
'matches'
];
const custom = ['isTimezone', 'isEmptyOrURL', 'isSlug'];
describe('Validator', function () {
it('should export our required functions', function () {
should.exist(validator);
const allMethods = validators.concat(custom).concat('validate');
Object.keys(validator).should.eql(allMethods);
});
describe('Custom Validators', function () {
it('isEmptyOrUrl filters javascript urls', function () {
validator.isEmptyOrURL('javascript:alert(0)').should.be.false();
validator.isEmptyOrURL('http://example.com/lol/<script>lalala</script>/').should.be.false();
validator.isEmptyOrURL('http://example.com/lol?somequery=<script>lalala</script>').should.be.false();
validator.isEmptyOrURL('').should.be.true();
validator.isEmptyOrURL('http://localhost:2368').should.be.true();
validator.isEmptyOrURL('http://example.com/test/').should.be.true();
validator.isEmptyOrURL('http://www.example.com/test/').should.be.true();
validator.isEmptyOrURL('http://example.com/foo?somequery=bar').should.be.true();
validator.isEmptyOrURL('example.com/test/').should.be.true();
});
});
});