var should = require('should');
var httpMocks = require('node-mocks-http');

var authRbac = {};
authRbac.httpBasic = require('../');

var auth = require('./common');

function checkRequestAuthInfo(req) {
	req.should.have.property('auth');
	req.auth.should.have.properties(['user', 'role']);
	(!!req.auth.user).should.be.true;
	(!!req.auth.role).should.be.true;
}

function checkAskForCredentialsResponse(res) {
	res.statusCode.should.equal(401);
	var authHeader = res.getHeader('WWW-Authenticate');
	(authHeader !== null).should.be.true;
	var data = /realm="([^"]*)"/i.exec(authHeader);
	(!!data).should.be.true;
	data[1].should.equal('test');
}

describe('httpBasic', function() {
	var httpBasic;

	before(function() {
		httpBasic = authRbac.httpBasic(auth, 'test');
	});

	it('puts auth info in req.auth if valid credentials given', function(done) {
		var req = httpMocks.createRequest({ headers: {
			// Authorization: Basic #{base64('guest:1234')}
			authorization: 'Authorization: Basic Z3Vlc3Q6MTIzNA=='
		}});
		var res = httpMocks.createResponse();
		httpBasic(req, res, function(err) {
			if (err)
				return done(err);
			checkRequestAuthInfo(req);
			done();
		});
	});

	it('responds with error and sends realm if auth method is not basic', function(done) {
		var req = httpMocks.createRequest({ headers: {
			// Authorization: Unknown #{base64('guest:1234')}
			authorization: 'Authorization: Unknown Z3Vlc3Q6MTIzNA=='
		}});
		var res = httpMocks.createResponse();
		httpBasic(req, res, function(err) {
			if (err)
				return done(err);
			req.should.not.have.property('auth');
			checkAskForCredentialsResponse(res);
			return done();
		});
	});

	it('responds with error and sends realm if auth header is not present', function(done) {
		var req = httpMocks.createRequest();
		var res = httpMocks.createResponse();
		httpBasic(req, res, function(err) {
			if (err)
				return done(err);
			req.should.not.have.property('auth');
			checkAskForCredentialsResponse(res);
			return done();
		});
	});
});

@@ -1,18 +1,16 @@
 var 
-should
+chai
  = requi
@@ -17,16 +17,40 @@
 re('
-should')
+chai');%0Avar expect = chai.expect
 ;%0Ava
@@ -111,10 +111,28 @@
 c = 
-%7B%7D
+require('auth-rbac')
 ;%0Aau
@@ -162,25 +162,24 @@
 ire('../');%0A
-%0A
 var auth = r
@@ -241,137 +241,104 @@
  %7B%0A%09
-req.should.have.property('auth');%0A%09req.auth.should.have.properties(%5B'user', 'role'%5D);%0A%09(!!req.auth.user).should.be.true;%0A%09(!!req.
+expect(req).to.have.deep.property('auth.user').that.exists;%0A%09expect(req).to.have.deep.property('
 auth
@@ -342,32 +342,30 @@
 uth.role
+'
 ).
-should.be.true
+that.exists
 ;%0A%7D%0A%0Afun
@@ -413,36 +413,51 @@
  %7B%0A%09
-res.statusCode.should.equal(
+expect(res).to.have.property('statusCode', 
 401)
@@ -512,16 +512,22 @@
 ate');%0A%09
+expect
 (authHea
@@ -533,33 +533,18 @@
 ader
- !== null).should.be.true
+).to.be.ok
 ;%0A%09v
@@ -595,55 +595,60 @@
 );%0A%09
-(!!data).should.be.true;%0A%09data%5B1%5D.should.equal(
+expect(data).to.be.ok.and.have.deep.property('%5B1%5D', 
 'tes
@@ -1558,34 +1558,38 @@
 ne(err);%0A%09%09%09
-req.should
+expect(req).to
 .not.have.pr
@@ -1922,18 +1922,22 @@
 %0A%09%09%09
-req.should
+expect(req).to
 .not

Use chai instead of should.js