basic-auth.js 993 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. (function () {
  2. /*global describe, it*/
  3. 'use strict';
  4. var should = require('should'),
  5. express = require('express'),
  6. supertest = require('supertest'),
  7. basicAuth = require('basic-auth-connect'),
  8. cors = require('../lib');
  9. var app;
  10. /* -------------------------------------------------------------------------- */
  11. app = express();
  12. app.use(basicAuth('username', 'password'));
  13. app.use(cors());
  14. app.post('/', function (req, res) {
  15. res.send('hello world');
  16. });
  17. /* -------------------------------------------------------------------------- */
  18. describe('basic auth', function () {
  19. it('POST works', function (done) {
  20. supertest(app)
  21. .post('/')
  22. .auth('username', 'password')
  23. .expect(200)
  24. .end(function (err, res) {
  25. should.not.exist(err);
  26. res.headers['access-control-allow-origin'].should.eql('*');
  27. res.text.should.eql('hello world');
  28. done();
  29. });
  30. });
  31. });
  32. }());