<commit_before>var assert = require('assert'),
    _ = require('lodash');

describe('SQL Interface', function() {

  describe('.find()', function() {

    /////////////////////////////////////////////////////
    // TEST SETUP
    ////////////////////////////////////////////////////

    before(function(done) {

      // Insert 10 Users
      var users = [];

      for(var i=0; i<10; i++) {
        users.push({first_name: 'find_user' + i, type: 'find test', age: i*10 });  // include an integer field
      }

      Sql.User.createEach(users, function(err, users) {
        if(err) return done(err);
        done();
      });
    });

    /////////////////////////////////////////////////////
    // TEST METHODS
    ////////////////////////////////////////////////////


    it('should escape attribute names to prevent SQL injection attacks', function(done) {
      Sql.User.find({ type: 'find_test', 'first_name`IS NULL OR 1=1 #': 'whatever' }, function(err, users) {
        assert(err, 'Should have escaped field name and prevented data from being returned (caused an error)');
        assert(!users || !users.length, 'Should have escaped field name and prevented data from being returned');
        done();
      });
    });

    it('should escape values when using startsWith modifier to prevent SQL injection attacks', function(done) {
      var part = '\\\\\\" OR 1=1; -- %_';
      Sql.User.find({ first_name: { startsWith: part }}, function(err, users) {
        assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
        done();
      });
    });

    it('should escape values when using endsWith modifier to prevent SQL injection attacks', function(done) {
      var part = '\\\\\\" OR 1=1; -- %_';
      Sql.User.find({ first_name: { endsWith: part }}, function(err, users) {
        assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
        done();
      });
    });

    it('should escape values when using contains modifier to prevent SQL injection attacks', function(done) {
      var part = '\\\\\\" OR 1=1; -- %_';
      Sql.User.find({ first_name: { contains: part }}, function(err, users) {
        assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
        done();
      });
    });

  });
});<commit_msg>add like test<commit_after>var assert = require('assert'),
    _ = require('lodash');

describe('SQL Interface', function() {

  describe('.find()', function() {

    /////////////////////////////////////////////////////
    // TEST SETUP
    ////////////////////////////////////////////////////

    before(function(done) {

      // Insert 10 Users
      var users = [];

      for(var i=0; i<10; i++) {
        users.push({first_name: 'find_user' + i, type: 'find test', age: i*10 });  // include an integer field
      }

      Sql.User.createEach(users, function(err, users) {
        if(err) return done(err);
        done();
      });
    });

    /////////////////////////////////////////////////////
    // TEST METHODS
    ////////////////////////////////////////////////////


    it('should escape attribute names to prevent SQL injection attacks', function(done) {
      Sql.User.find({ type: 'find_test', 'first_name`IS NULL OR 1=1 #': 'whatever' }, function(err, users) {
        assert(err, 'Should have escaped field name and prevented data from being returned (caused an error)');
        assert(!users || !users.length, 'Should have escaped field name and prevented data from being returned');
        done();
      });
    });

    it('should escape values when using startsWith modifier to prevent SQL injection attacks', function(done) {
      var part = '\\\\\\" OR 1=1; -- %_';
      Sql.User.find({ first_name: { startsWith: part }}, function(err, users) {
        assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
        done();
      });
    });

    it('should escape values when using endsWith modifier to prevent SQL injection attacks', function(done) {
      var part = '\\\\\\" OR 1=1; -- %_';
      Sql.User.find({ first_name: { endsWith: part }}, function(err, users) {
        assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
        done();
      });
    });

    it('should escape values when using contains modifier to prevent SQL injection attacks', function(done) {
      var part = '\\\\\\" OR 1=1; -- %_';
      Sql.User.find({ first_name: { contains: part }}, function(err, users) {
        assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
        done();
      });
    });

    it('should escape values when using like modifier to prevent SQL injection attacks', function(done) {
      var part = '\\\\\\" OR 1=1; -- %_';
      Sql.User.find({ first_name: { like: part }}, function(err, users) {
        assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
        done();
      });
    });

  });
});
{'fraction_non_alphanumeric': 0.22043739113605573, 'fraction_numerical': 0.0061931488291078, 'mean_word_length': 1.9994196169471852, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6171793', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1311, 'n_words': 443}