<commit_before>// auth0 rules rely on a configuration object, which is a set of secrets stored inside auth0, so we need to
// hoist them. Mozilla-IAM also uses a "global" object that is normally at the top of the rules list, and is
// contained inside global.js, which is a pruned down copy of Global-Function-Declarations.js
const fs = require('fs');
const path = require('path');
const requireFromString = require('require-from-string');

module.exports = {
  // no idea from the docs what the first variable is
  handler: (_ = null, user, context) => {
    return {
      context,
      user,
    }
  },

  load: (filename, preExportEval = '', silent = true) => {
    const ruleFile = path.join(__dirname, '../../rules', `${filename}`);

    const silence = silent ? `console.log = console.error = () => {};` : '';

    // shim auth0 globals into each rule, and set each function to be the global export
    const ruleText = `
      const configuration = require('./modules/global/configuration.js');
      const global = require('./modules/global/global.js');

      ${silence}
      ${preExportEval}

      module.exports = ${fs.readFileSync(ruleFile, 'utf8')};
      `;

    const ruleModule = requireFromString(ruleText, filename);

    return ruleModule;
  }
};
<commit_msg>Add protection against accidents in tests<commit_after>// auth0 rules rely on a configuration object, which is a set of secrets stored inside auth0, so we need to
// hoist them. Mozilla-IAM also uses a "global" object that is normally at the top of the rules list, and is
// contained inside global.js, which is a pruned down copy of Global-Function-Declarations.js
const fs = require('fs');
const path = require('path');
const requireFromString = require('require-from-string');

module.exports = {
  // no idea from the docs what the first variable is
  handler: (_ = null, user, context) => {
    return {
      context,
      user,
    }
  },

  load: (filename, preExportEval = '', silent = true) => {
    const ruleFile = path.join(__dirname, '../../rules', `${filename}`);

    // this is here because you can easily screw up your tests if you
    // switch the order of preExportEval and silent
    if (typeof silent !== 'boolean') {
      throw 'Incorrect argument order in rule loader';
    }

    const silence = silent ? `console.log = console.error = () => {};` : '';

    // shim auth0 globals into each rule, and set each function to be the global export
    const ruleText = `
      const configuration = require('./modules/global/configuration.js');
      const global = require('./modules/global/global.js');

      ${silence}
      ${preExportEval}

      module.exports = ${fs.readFileSync(ruleFile, 'utf8')};
      `;

    const ruleModule = requireFromString(ruleText, filename);

    return ruleModule;
  }
};

{'fraction_non_alphanumeric': 0.125044404973357, 'fraction_numerical': 0.002841918294849023, 'mean_word_length': 3.1350954478707784, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2462257', 'n_tokens_mistral': 787, 'n_tokens_neox': 767, 'n_words': 292}