<commit_before>
// Test Application
var app = require('express')();
app.use(require('..')(auth, 'my realm'));

function auth (key, fn) {
  fn(null, key === 'test')
}
app.get('/', function (req,res) {
  res.send('ok');
});

var request = require('supertest')(app);

describe('Basic Auth', function () {

  it('should fail with wrong user', function (done) {
    request
    .get('/')
    .auth('fail', 'asd')
    .expect(401)
    .end(done)
  })

  it('should authenticate with the right user', function (done) {
    request
    .get('/')
    .auth('test')
    .expect(200)
    .end(done)
  })
})

describe('Headers', function () {
  it('should accept X-APIKEY', function (done) {
    request
    .get('/')
    .set('X-APIKEY', 'test')
    .expect(200)
    .end(done)
  })

  it('should accept APIKEY', function (done) {
    request
    .get('/')
    .set('APIKEY', 'test')
    .expect(200)
    .end(done)
  })

  it('should accept X-Api-Key', function (done) {
    request
    .get('/')
    .set('X-Api-Key', 'test')
    .expect(200)
    .end(done)
  })<commit_msg>test for user object<commit_after>// test user
var user = { id: 1, name: '<NAME>' };

// Test Application
var app = require('express')()
app.use(require('..')(auth, 'my realm'))

function auth (key, fn) {
  fn(null, key === 'test' ? user : null)
}

app.get('/', function (req, res) {
  res.send(req.user)
})

var request = require('supertest')(app);

describe('Basic Auth', function () {

  it('should fail with wrong user', function (done) {
    request
    .get('/')
    .auth('fail', 'asd')
    .expect(401)
    .end(done)
  })

  it('should authenticate with the right user', function (done) {
    request
    .get('/')
    .auth('test')
    .expect(200)
    .expect(user)
    .end(done)
  })
})

describe('Headers', function () {
  it('should accept X-APIKEY', function (done) {
    request
    .get('/')
    .set('X-APIKEY', 'test')
    .expect(200)
    .expect(user)
    .end(done)
  })

  it('should accept APIKEY', function (done) {
    request
    .get('/')
    .set('APIKEY', 'test')
    .expect(200)
    .expect(user)
    .end(done)
  })

  it('should accept X-Api-Key', function (done) {
    request
    .get('/')
    .set('X-Api-Key', 'test')
    .expect(200)
    .expect(user)
    .end(done)
  })
{'fraction_non_alphanumeric': 0.21353251318101935, 'fraction_numerical': 0.013620386643233744, 'mean_word_length': 2.7389162561576357, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '2916911', 'n_tokens_mistral': 858, 'n_tokens_neox': 822, 'n_words': 192}