<commit_before>"use strict";

global.chai    = require("chai");
global.expect  = global.chai.expect;
global.sinon   = require("sinon");
global.cheerio = require('cheerio');

var sinonChai = require("sinon-chai");
global.chai.use(sinonChai);

var db = require('../models');

process.env.NODE_ENV = 'test';

/**
 * Alter the authentication method in order to make authenticated request for tests
 */

var authHelper = require('../lib/auth-helper');

// This token is used to authenticate requests during tests
global.TEST_AUTHORIZATION_TOKEN = "<PASSWORD>";

var isValidTestRequest = function(req) {
  return process.env.NODE_ENV === 'test' &&
         req.headers.authorization === 'Bearer ' + global.TEST_AUTHORIZATION_TOKEN;
};

// Replace authentication function to allow testing using a bearer token
// TODO: Can we use a sinon.stub to do this?

var _ensureAuthenticated = authHelper.ensureAuthenticated;

authHelper.ensureAuthenticated = function(req, res, next) {
    if (isValidTestRequest(req)) {
      db.User.findAll()
        .success(function(users) {
          req.user = (users.length >= 0) ? users[0] : null;
          next();
        });
    }
    else {
      _ensureAuthenticated(req, res, next);
    }
};

var app = require('../lib/app');
var supertest = require("supertest");
global.request = supertest(app);

<commit_msg>Fixed logic error<commit_after>"use strict";

global.chai    = require("chai");
global.expect  = global.chai.expect;
global.sinon   = require("sinon");
global.cheerio = require('cheerio');

var sinonChai = require("sinon-chai");
global.chai.use(sinonChai);

var db = require('../models');

process.env.NODE_ENV = 'test';

/**
 * Alter the authentication method in order to make authenticated request for tests
 */

var authHelper = require('../lib/auth-helper');

// This token is used to authenticate requests during tests
global.TEST_AUTHORIZATION_TOKEN = "<PASSWORD>";

var isValidTestRequest = function(req) {
  return process.env.NODE_ENV === 'test' &&
         req.headers.authorization === 'Bearer ' + global.TEST_AUTHORIZATION_TOKEN;
};

// Replace authentication function to allow testing using a bearer token
// TODO: Can we use a sinon.stub to do this?

var _ensureAuthenticated = authHelper.ensureAuthenticated;

authHelper.ensureAuthenticated = function(req, res, next) {
    if (isValidTestRequest(req)) {
      db.User.findAll()
        .success(function(users) {
          req.user = (users.length > 0) ? users[0] : null;
          next();
        });
    }
    else {
      _ensureAuthenticated(req, res, next);
    }
};

var app = require('../lib/app');
var supertest = require("supertest");
global.request = supertest(app);


{'fraction_non_alphanumeric': 0.14115456238361265, 'fraction_numerical': 0.0014897579143389199, 'mean_word_length': 3.7040280210157617, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '876710', 'n_tokens_mistral': 849, 'n_tokens_neox': 845, 'n_words': 206}