<commit_before>'use strict';

describe('auth', function () {
  it('should send auth before other commands', function (done) {
    var authed = false;
    var server = new MockServer(17379, function (argv) {
      if (argv[0] === 'auth' && argv[1] === 'pass') {
        authed = true;
      } else if (argv[0] === 'get' && argv[1] === 'foo') {
        expect(authed).to.eql(true);
        redis.disconnect();
        server.disconnect();
        done();
      }
    });
    var redis = new Redis({ port: 17379, password: '<PASSWORD>' });
    redis.get('foo').catch(function () {});
  });

  it('should resend auth after reconnect', function (done) {
    var begin = false;
    var authed = false;
    var server = new MockServer(17379, function (argv) {
      if (!begin) {
        return;
      }
      if (argv[0] === 'auth' && argv[1] === 'pass') {
        authed = true;
      } else if (argv[0] === 'get' && argv[1] === 'foo') {
        expect(authed).to.eql(true);
        redis.disconnect();
        server.disconnect();
        done();
      }
    });
    var redis = new Redis({ port: 17379, password: '<PASSWORD>' });
    redis.once('ready', function () {
      begin = true;
      redis.disconnect({ reconnect: true });
      redis.get('foo').catch(function () {});
    });
  });

  it('should emit "error" when the server doesn\'t need auth', function (done) {
    var server = new MockServer(17379, function (argv) {
      if (argv[0] === 'auth' && argv[1] === 'pass') {
        return new Error('ERR Client sent AUTH, but no password is set');
      }
    });
    var redis = new Redis({ port: 17379, password: '<PASSWORD>' });
    redis.on('error', function (error) {
      expect(error).to.have.property('message', 'ERR Client sent AUTH, but no password is set');
      redis.disconnect();
      server.disconnect();
      done();
    });
  });

  it('should emit "error" when the password is wrong', function (done) {
    var server = new MockServer(17379, function (argv) {
      if (argv[0] === 'auth' && argv[1] === 'pass') {
        return new Error('ERR invalid password');
      }
    });
    var redis = new Redis({ port: 17379, password: '<PASSWORD>' });
    redis.on('error', function (error) {
      expect(error).to.have.property('message', 'ERR invalid password');
      redis.disconnect();
      server.disconnect();
      done();
    });
  });

  it('should emit "error" when password is not provided', function (done) {
    var server = new MockServer(17379, function (argv) {
      if (argv[0] === 'info') {
        return new Error('NOAUTH Authentication required.');
      }<commit_msg>test: fix outdated tests<commit_after>'use strict';

describe('auth', function () {
  it('should send auth before other commands', function (done) {
    var authed = false;
    var server = new MockServer(17379, function (argv) {
      if (argv[0] === 'auth' && argv[1] === 'pass') {
        authed = true;
      } else if (argv[0] === 'get' && argv[1] === 'foo') {
        expect(authed).to.eql(true);
        redis.disconnect();
        server.disconnect();
        done();
      }
    });
    var redis = new Redis({ port: 17379, password: '<PASSWORD>' });
    redis.get('foo').catch(function () {});
  });

  it('should resend auth after reconnect', function (done) {
    var begin = false;
    var authed = false;
    var server = new MockServer(17379, function (argv) {
      if (!begin) {
        return;
      }
      if (argv[0] === 'auth' && argv[1] === 'pass') {
        authed = true;
      } else if (argv[0] === 'get' && argv[1] === 'foo') {
        expect(authed).to.eql(true);
        redis.disconnect();
        server.disconnect();
        done();
      }
    });
    var redis = new Redis({ port: 17379, password: '<PASSWORD>' });
    redis.once('ready', function () {
      begin = true;
      redis.disconnect({ reconnect: true });
      redis.get('foo').catch(function () {});
    });
  });

  it('should not emit "error" when the server doesn\'t need auth', function (done) {
    var server = new MockServer(17379, function (argv) {
      if (argv[0] === 'auth' && argv[1] === 'pass') {
        return new Error('ERR Client sent AUTH, but no password is set');
      }
    });
    var errorEmited = false;
    var redis = new Redis({ port: 17379, password: '<PASSWORD>' });
    redis.on('error', function () {
      errorEmited = true;
    });
    stub(console, 'warn', function (warn) {
      expect(warn).to.match(/but a password was supplied/);
      console.warn.restore();
      setTimeout(function () {
        expect(errorEmited).to.eql(false);
        redis.disconnect();
        server.disconnect();
        done();
      }, 0);
    });
  });

  it('should emit "error" when the password is wrong', function (done) {
    var server = new MockServer(17379, function (argv) {
      if (argv[0] === 'auth' && argv[1] === 'pass') {
        return new Error('ERR invalid password');
      }
    });
    var redis = new Redis({ port: 17379, password: '<PASSWORD>' });
    redis.on('error', function (error) {
      expect(error).to.have.property('message', 'ERR invalid password');
      redis.disconnect();
      server.disconnect();
      done();
    });
  });

  it('should emit "error" when password is not provided', function (done) {
    var server = new MockServer(17379, function (argv) {
      if (argv[0] === 'info') {
        return new Error('NOAUTH Authentication required.');
      }
{'fraction_non_alphanumeric': 0.18170126768326292, 'fraction_numerical': 0.021495498805805622, 'mean_word_length': 2.607687210072896, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6476638', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1694, 'n_words': 465}