<commit_before>var Utils = require('../utils/util');

var destroySession = function(req, res) {
  req.session.destroy(() => {
    console.log('destroySession forced -> session.destroy');
    Utils.sendJSONres(res, 200, {message: "Session destroyed correctly!"});
  });
};

var setStringSession = function(req, res) {
  req.session.authToken = 'fake';
  console.log('setStringSession forced -> req.session.authToken = fake');
  Utils.sendJSONres(res, 200, {message: "Session modified correctly!"});
};

var setJsonWithoutTokenSession = function(req, res) {
  req.session.authToken = JSON.stringify({
    _id: 'fakeid',
    user: null,
    token: null, // without token
    exp: (new Date()).getTime()
  });
  console.log('setJsonWithoutTokenSession forced -> req.session.authToken = a JSON');
  Utils.sendJSONres(res, 200, {message: "Session modified correctly!"});
};

var setJsonWithWrongFormatTokenSession = function(req, res) {
  req.session.authToken = JSON.stringify({
    _id: 'fakeid',
    token: '<PASSWORD>', // only one dot :)
    user: null,
    exp: (new Date()).getTime()
  });
  console.log('setJsonWithWrongFormatTokenSession forced -> req.session.authToken = a JSON');
  Utils.sendJSONres(res, 200, {message: "Session modified correctly!"});
};

var setJsonWithExpiredDateSession = function(req, res) {
  req.session.authToken = JSON.stringify({
    _id: 'fakeid',
    token: '<PASSWORD>', // only one dot :)
    user: null,
    exp: (new Date()).getTime()-50000 // obviously wrong
  });
  console.log('setJsonWithExpiredDateSession forced -> req.session.authToken = a JSON');
  Utils.sendJSONres(res, 200, {message: "Session modified correctly!"});
};

module.exports = {
  destroySession: destroySession,
  setStringSession: setStringSession,
  setJsonWithoutTokenSession: setJsonWithoutTokenSession,
  setJsonWithWrongFormatTokenSession: setJsonWithWrongFormatTokenSession,
  setJsonWithExpiredDateSession: setJsonWithExpiredDateSession
};
<commit_msg>I forgot to add testing controller #24<commit_after>var Utils = require('../utils/util');

var destroySession = function(req, res) {
  req.session.destroy(() => {
    console.log('destroySession forced -> session.destroy');
    Utils.sendJSONres(res, 200, {message: "Session destroyed correctly!"});
  });
};

var setStringSession = function(req, res) {
  req.session.authToken = 'fake';
  console.log('setStringSession forced -> req.session.authToken = fake');
  Utils.sendJSONres(res, 200, {message: "Session modified correctly!"});
};

var setJsonWithoutTokenSession = function(req, res) {
  req.session.authToken = JSON.stringify({
    _id: 'fakeid',
    user: null,
    token: null, // without token
    exp: (new Date()).getTime()
  });
  console.log('setJsonWithoutTokenSession forced -> req.session.authToken = a JSON');
  Utils.sendJSONres(res, 200, {message: "Session modified correctly!"});
};

var setJsonWithWrongFormatTokenSession = function(req, res) {
  req.session.authToken = JSON.stringify({
    _id: 'fakeid',
    token: '<PASSWORD>', // only one dot :)
    user: null,
    exp: (new Date()).getTime()
  });
  console.log('setJsonWithWrongFormatTokenSession forced -> req.session.authToken = a JSON');
  Utils.sendJSONres(res, 200, {message: "Session modified correctly!"});
};

var setJsonWithExpiredDateSession = function(req, res) {
  var expiry = new Date();
	expiry.setTime(expiry.getTime() - 600000); //expired 10 minutes ago (10*60*1000)
  console.warn("+++++++++++++++++++++++++++++++++");
  req.session.authToken = JSON.stringify({
    _id: '<PASSWORD>',
    user: {
      _id: "581d01b3706b0a34de2c0b03",
			local: {
				email: 'email',
				name: 'name'
			}
		},
    exp: parseFloat(expiry.getTime()) // obviously wrong
  });
  console.warn(req.session.authToken);
  console.log('setJsonWithExpiredDateSession forced -> req.session.authToken = a JSON');
  Utils.sendJSONres(res, 200, {message: "Session modified correctly!"});
};

module.exports = {
  destroySession: destroySession,
  setStringSession: setStringSession,
  setJsonWithoutTokenSession: setJsonWithoutTokenSession,
  setJsonWithWrongFormatTokenSession: setJsonWithWrongFormatTokenSession,
  setJsonWithExpiredDateSession: setJsonWithExpiredDateSession
};

{'fraction_non_alphanumeric': 0.15277119848413073, 'fraction_numerical': 0.01634296541923259, 'mean_word_length': 4.8088033012379645, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '501466', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1296, 'n_words': 283}