UNPKG

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