<commit_before>var validator = require('validator');
var config = require('./config');
var errors = require('./errors');

/**
 * Shared validation functions for validating various fields.
 * These functions, being in a common library, may not be used
 * for project specific validations and techniques, such as using
 * the project database module to perform various lookups. Those
 * validation tasks are best left to a project specific validation module
 */
var spaceAndPeriodRegex = /^[A-Za-z0-9\.\s]*$/;
var spacePeriodAndUnderscoreRegex = /^[A-Za-z0-9_\.\s]*$/;
var periodAndUnderscoreRegex = /^[A-Za-z0-9_\.]*$/;
var usernameRegex = /^[A-Za-z0-9_@\.]*$/;    // ascii printable plus enough to enter email, and underscore
var passwordRegex = /^[A-Za-z0-9!@#%^&*_\s]*$/;    // A few more punctuation chars.
var subjectRegex = /^[A-Za-z0-9!?_\.\s]*$/;    // A few more punctuation chars.


var firstLastNameRegex = /^[$!{}]/;
var spaceAndLimitedPunctuationRegex = /^[A-Za-z0-9\.\s,!#@$%^&*]*$/;
var serviceNameRegex = /^[A-Za-z0-9\.]*$/;
var spaceOnlyRegex = /^[A-Za-z0-9\s]*$/;
var underscoreOnlyRegex = /^[A-Za-z0-9_]*$/;
var underscoreSpaceOnlyRegex = /^[A-Za-z0-9_\s]*$/;
var permissionOpRegex = /[and|or|single]/;
var lowerCaseDotRegex = /^[a-z\.]*$/;

// read, execute, update, delete, readMeta, updateMeta, readPermissions, updatePermissions
var allowableRightsRegex = /[r|x|u|d|mu|pr|pu]/;

var PermissionStringLength = 100;
var DescriptionStringLength = 256;
var MaxRightsLength = 4000;
var RealmMaxLength = 75;
var RealmMinLength = 2;
var RolesMaxLength = 75;
var GroupsMaxLength = 75;
var OriginsMaxLength = 100;
var PasswordMinLength = 8;
var PasswordMaxLength = 48;
var EmailMaxLength = 50;
var ServiceMaxLength = 50;
var PermissionOpMaxLength = 6;
var serviceTypeMaxLength = 32;
var MAX_TEMPLATE_LENGTH = 65536;
var MAX_SUBJECT_LENGTH = 78; // RFC-2822
var MAX_EXPIRESIN_LENGTH = 10;  // number of ascii characters that is enough?

var NameMaxLength = 40;
var NameMinLength = 1;

/**
 * For example, min length 8, max length: 30, no punctuation other than the subrealm
 * separator '.' and '_'
 * @param val The realm name to test
 */
var realmValidator = function (val) {
    if (typeof(val) !=='string') {
        return false;
    }
    if (val.length < RealmMinLength || val.length > RealmMaxLength) {
        return false;
    }
    return periodAndUnderscoreRegex.test(val);
};
exports.realmValidator = realmValidator;

// Username validator. Valid chars are ascii character ranges plus a few punctuation
// characters for email addresses as username.
var usernameValidator = function (val) {

    //In order to have modules respect the logging configuration supplied by the service, we
    //need to get the logger in a 'lazy' fashion.  If we get it during initialization, then
    //the logger instance only has the default configuration.
    var logger = require('./loggers').getLogger();

    if (typeof(val) !=='string') {
        logger.debug('Username invalid type');
        return false;
    }
    if (val.length < NameMinLength || val.length > NameMaxLength) {
        logger.debug('Username invalid length');
        return false;
    }
    var result = usernameRegex.test(val);
    return result;
};
exports.usernameValidator = usernameValidator;


// First, last name validator
var nameValidator = function (val) {
    if (typeof(val) !=='string') {
        return false;
    }
    if (val.length < NameMinLength || val.length > NameMaxLength) {
        return false;
    }
    // Allow all unicode chars for name fields.
    return !firstLastNameRegex.test(val);
};
exports.nameValidator = nameValidator;

// accountname validator.
var accountNameValidator = function (val) {
    if (typeof(val) !=='string') {
        return false;
    }
    if (val.length < NameMinLength || val.length > NameMaxLength) {
        return false;
    }
    return spacePeriodAndUnderscoreRegex.test(val);
};
exports.accountNameValidator = accountNameValidator;

// Account description validator
var descriptionValidator = function (val) {
    if (typeof(val) !=='string') {
        return false;
    }
    if (val.length > DescriptionStringLength) {
        return false;
    }
    return spaceAndLimitedPunctuationRegex.test(val);
};
exports.descriptionValidator = descriptionValidator;

var serviceNameValidator = function (val) {
    if (typeof(val) !=='string') {
        return false;
    }
    if (val.length > ServiceMaxLength) {
        return false;
    }
    return serviceNameRegex.test(val);
};
exports.serviceNameValidator = serviceNameValidator;<commit_msg>VRAS-337 increased group description length and removed regex filtering of description fields<commit_after>var validator = require('validator');
var config = require('./config');
var errors = require('./errors');

/**
 * Shared validation functions for validating various fields.
 * These functions, being in a common library, may not be used
 * for project specific validations and techniques, such as using
 * the project database module to perform various lookups. Those
 * validation tasks are best left to a project specific validation module
 */
var spaceAndPeriodRegex = /^[A-Za-z0-9\.\s]*$/;
var spacePeriodAndUnderscoreRegex = /^[A-Za-z0-9_\.\s]*$/;
var periodAndUnderscoreRegex = /^[A-Za-z0-9_\.]*$/;
var usernameRegex = /^[A-Za-z0-9_@\.]*$/;    // ascii printable plus enough to enter email, and underscore
var passwordRegex = /^[A-Za-z0-9!@#%^&*_\s]*$/;    // A few more punctuation chars.
var subjectRegex = /^[A-Za-z0-9!?_\.\s]*$/;    // A few more punctuation chars.


var firstLastNameRegex = /^[$!{}]/;
var spaceAndLimitedPunctuationRegex = /^[A-Za-z0-9\.\s,!#@$%^&?*]*$/;
var serviceNameRegex = /^[A-Za-z0-9\.]*$/;
var spaceOnlyRegex = /^[A-Za-z0-9\s]*$/;
var underscoreOnlyRegex = /^[A-Za-z0-9_]*$/;
var underscoreSpaceOnlyRegex = /^[A-Za-z0-9_\s]*$/;
var permissionOpRegex = /[and|or|single]/;
var lowerCaseDotRegex = /^[a-z\.]*$/;

// read, execute, update, delete, readMeta, updateMeta, readPermissions, updatePermissions
var allowableRightsRegex = /[r|x|u|d|mu|pr|pu]/;

var PermissionStringLength = 100;
var DescriptionStringLength = 500;
var MaxRightsLength = 4000;
var RealmMaxLength = 75;
var RealmMinLength = 2;
var RolesMaxLength = 75;
var GroupsMaxLength = 75;
var OriginsMaxLength = 100;
var PasswordMinLength = 8;
var PasswordMaxLength = 48;
var EmailMaxLength = 50;
var ServiceMaxLength = 50;
var PermissionOpMaxLength = 6;
var serviceTypeMaxLength = 32;
var MAX_TEMPLATE_LENGTH = 65536;
var MAX_SUBJECT_LENGTH = 78; // RFC-2822
var MAX_EXPIRESIN_LENGTH = 10;  // number of ascii characters that is enough?

var NameMaxLength = 40;
var NameMinLength = 1;

/**
 * For example, min length 8, max length: 30, no punctuation other than the subrealm
 * separator '.' and '_'
 * @param val The realm name to test
 */
var realmValidator = function (val) {
    if (typeof(val) !=='string') {
        return false;
    }
    if (val.length < RealmMinLength || val.length > RealmMaxLength) {
        return false;
    }
    return periodAndUnderscoreRegex.test(val);
};
exports.realmValidator = realmValidator;

// Username validator. Valid chars are ascii character ranges plus a few punctuation
// characters for email addresses as username.
var usernameValidator = function (val) {

    //In order to have modules respect the logging configuration supplied by the service, we
    //need to get the logger in a 'lazy' fashion.  If we get it during initialization, then
    //the logger instance only has the default configuration.
    var logger = require('./loggers').getLogger();

    if (typeof(val) !=='string') {
        logger.debug('Username invalid type');
        return false;
    }
    if (val.length < NameMinLength || val.length > NameMaxLength) {
        logger.debug('Username invalid length');
        return false;
    }
    var result = usernameRegex.test(val);
    return result;
};
exports.usernameValidator = usernameValidator;


// First, last name validator
var nameValidator = function (val) {
    if (typeof(val) !=='string') {
        return false;
    }
    if (val.length < NameMinLength || val.length > NameMaxLength) {
        return false;
    }
    // Allow all unicode chars for name fields.
    return !firstLastNameRegex.test(val);
};
exports.nameValidator = nameValidator;

// accountname validator.
var accountNameValidator = function (val) {
    if (typeof(val) !=='string') {
        return false;
    }
    if (val.length < NameMinLength || val.length > NameMaxLength) {
        return false;
    }
    return spacePeriodAndUnderscoreRegex.test(val);
};
exports.accountNameValidator = accountNameValidator;

// Account description validator
var descriptionValidator = function (val) {
    if (typeof(val) !=='string') {
        return false;
    }
    if (val.length > DescriptionStringLength) {
        return false;
    }
    return true;
};
exports.descriptionValidator = descriptionValidator;

var serviceNameValidator = function (val) {
    if (typeof(val) !=='string') {
        return false;
    }
    if (val.length > ServiceMaxLength) {
        return false;
    }
    return serviceNameRegex.test(val);
};
exports.serviceNameValidator = serviceNameValidator;
{'fraction_non_alphanumeric': 0.12958143569724573, 'fraction_numerical': 0.015723270440251572, 'mean_word_length': 3.5931274900398407, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5585519', 'n_tokens_mistral': 2992, 'n_tokens_neox': 2791, 'n_words': 840}