Skip to content

Commit

Permalink
Merge pull request #3 from yawnt/tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
yawnt committed Aug 28, 2013
2 parents d40e4be + 2fac7b9 commit f4e9945
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/caronte/streams/forward.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ function ForwardStream(options) {
var self = this;

self.options = options;
self.res = res;
// To uncomment the line below, please see
// https://github.com/yawnt/caronte/commit/9ab8749a9bec33b49c495975e8364336ad7be1a3#commitcomment-3947117
//self.res = res;

Writable.call(this);

Expand Down
17 changes: 17 additions & 0 deletions test/lib-caronte-passes-web-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,21 @@ describe('lib/caronte/passes/web.js', function() {
expect(done).to.eql(5000);
});
});

describe('#XHeaders', function () {
var stubRequest = {
connection: {
remoteAddress: '192.168.1.2',
remotePort: '8080'
},
headers: {}
}

it('set the correct x-forwarded-* headers', function () {
caronte.XHeaders(stubRequest, {}, { xfwd: true });
expect(stubRequest.headers['x-forwarded-for']).to.be('192.168.1.2');
expect(stubRequest.headers['x-forwarded-port']).to.be('8080');
expect(stubRequest.headers['x-forwarded-proto']).to.be('http');
});
});
});
37 changes: 37 additions & 0 deletions test/lib-caronte-streams-forward-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var ForwardStream = require('../lib/caronte/streams/forward'),
expect = require('expect.js'),
Writable = require('stream').Writable,
http = require('http');


describe('lib/caronte/passes/web.js', function () {
describe('forward stream constructor', function () {
it('should be an instance of Writable stream and get the correct options and methods', function () {
var stubOptions = {
key: 'value'
};
var forwardProxy = new ForwardStream(stubOptions);

expect(forwardProxy).to.be.a(Writable);
expect(forwardProxy.options).to.eql({ key: 'value' });
expect(forwardProxy.onPipe).to.be.a('function');
expect(forwardProxy.onFinish).to.be.a('function');
expect(forwardProxy._events).to.have.property('pipe');
expect(forwardProxy._events).to.have.property('finish');
});
});

describe('should pipe the request and finish it', function () {
it('should make the request on pipe and finish it');
var stubOptions = {
target: {
hostname : 'www.google.com',
port : '80',
path : '/'
}
};

var forwardProxy = new ForwardStream({});

});
});

0 comments on commit f4e9945

Please sign in to comment.