Skip to content

Commit

Permalink
Test: fix issues with jshint
Browse files Browse the repository at this point in the history
  • Loading branch information
José Moreira committed Jan 18, 2016
1 parent 3a0ccc8 commit 8fb1410
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 133 deletions.
22 changes: 11 additions & 11 deletions test/proxy-protocol.regexp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,45 @@ describe( "PROXY Protocol regexp tests", function () {
describe( "UNKNOWN", function () {

it( "localhost", function () {
expect( test("PROXY UNKNOWN") ).to.be.ok;
expect( test("PROXY UNKNOWN") ).to.be.ok()
});

/* For "UNKNOWN", the rest of the line before the
CRLF may be omitted by the sender, and the receiver must ignore anything
presented before the CRLF is found.
*/
it( "ignore things uppon UNKNOWN", function () {
expect( test("PROXY UNKNOWN SOMETHING UGLY MUAHAHA") ).to.be.ok;
expect( test("PROXY UNKNOWN SOMETHING UGLY MUAHAHA") ).to.be.ok()
});

it( "should fail if anything is behind UNKNOWN", function () {
expect( test("PROXY hahaa UNKNOWN") ).to.not.be.ok;
expect( test("PROXY hahaa UNKNOWN") ).to.not.be.ok()
});

});

describe( "TCP4", function () {

it( "basic", function () {
expect( test("PROXY TCP4 127.0.0.1 127.0.0.1 80 80") ).to.be.ok;
expect( test("PROXY TCP4 127.0.0.1 127.0.0.1 80 80") ).to.be.ok()
});

it( "star.findhit.com example", function () {
expect( test("PROXY TCP4 188.82.2.220 54.171.44.240 3450 443") ).to.be.ok;
expect( test("PROXY TCP4 188.82.2.220 54.171.44.240 3450 443") ).to.be.ok()
});

});

describe( "TCP6", function () {

it( "localhost", function () {
expect( test("PROXY TCP6 ::1 ::1 80 80") ).to.be.ok;
expect( test("PROXY TCP6 ::FFFF ::FFFF 80 80") ).to.be.ok;
expect( test("PROXY TCP6 ::ffff ::ffff 80 80") ).to.be.ok;
expect( test("PROXY TCP6 ::1 ::1 80 80") ).to.be.ok()
expect( test("PROXY TCP6 ::FFFF ::FFFF 80 80") ).to.be.ok()
expect( test("PROXY TCP6 ::ffff ::ffff 80 80") ).to.be.ok()
});

it( "FE80:0000:0000:0000:0202:B3FF:FE1E:8329", function () {
expect( test("PROXY TCP6 FE80:0000:0000:0000:0202:B3FF:FE1E:8329 FE80:0000:0000:0000:0202:B3FF:FE1E:8329 80 80") ).to.be.ok;
expect( test("PROXY TCP6 FE80:0000:0000:0000:0202:B3FF:FE1E:8329 FE80:0000:0000:0000:0202:B3FF:FE1E:8329 80 80") ).to.be.ok()
});

});
Expand All @@ -63,9 +63,9 @@ describe( "PROXY Protocol regexp tests", function () {
it( 'port '+ port +' should ' + ( ok ? '' : 'NOT' ) + ' be ok', function () {
var res = test( 'PROXY TCP4 127.0.0.1 127.0.0.1 '+ port +' '+ port );
if ( ok )
expect( res ).to.be.ok;
expect( res ).to.be.ok()
else {
expect( res ).to.not.be.ok;
expect( res ).to.not.be.ok()
}
});
}
Expand Down
164 changes: 91 additions & 73 deletions test/specific/issue-15.test.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,106 @@
'use strict';

/* related to issue https://github.com/findhit/proxywrap/issues/15 */
var http = require('http')
var assert = require('assert')
var net = require('net')
var exec = require('child_process').exec
var http = require( 'http' )
var assert = require( 'assert' )
var net = require( 'net' )
var exec = require( 'child_process' ).exec
var child
var proxyWrap = require('../..')
var proxyWrap = require( '../..' )

function findCloseWaitConnections(port, callback) {
function findCloseWaitConnections ( port, callback ) {
var child = exec('netstat -tonp | grep 8000 | grep CLOSE_WAIT',
function (err, stdout, stderr) {
if (err) {
return callback(err);
function ( err, stdout, stderr ) {
if ( err ) {
return callback(err)
}
return callback(null, stdout);
});
return callback(null, stdout)
})
}

function reproduce(proxyWrapConf, callback) {
var socket, server, port, proxiedHttp;
if (!callback) {
callback = proxyWrapConf;
proxyWrapConf = null;
function reproduce ( proxyWrapConf, callback ) {
var socket, server, port, proxiedHttp
if ( ! callback ) {
callback = proxyWrapConf
proxyWrapConf = null
}

proxiedHttp = proxyWrap.proxy(http, proxyWrapConf);
proxiedHttp = proxyWrap.proxy( http, proxyWrapConf )

server = proxiedHttp
.createServer(function handler ( req, res) {
throw new Error('For this test socket should not call #write()')
})
.listen(function ( err ) {

server = proxiedHttp.createServer(function handler(req, res) {
throw new Error('For this test socket should not call #write()');
}).listen(function (err) {
if (err) {
return done(err);
return done(err)
}
port = this.address().port;
socket = net.connect({
port: port
}, function () {
socket.end();
});
socket.on('end', function () {
return callback(null, server);
});
});

port = this.address().port

socket = net.connect(
{
port: port
},
function () {
socket.end()
}
)

socket.on( 'end', function () {
return callback( null, server )
})
})
}
describe('Sockets closed before any write #15', function () {
describe('On strict mode', function () {
var port, server;
before(function (done) {
reproduce(function (err, _server) {
server = _server;
port = server.address().port;
return done();
});
});

describe( 'Sockets closed before any write #15', function () {
describe( 'On strict mode', function () {
var port, server

before(function ( done ) {
reproduce(function ( err, _server ) {
server = _server
port = server.address().port
done()
})
})

after(function () {
server.close();
});
it('should be restored', function (done) {
findCloseWaitConnections(port, function (err, stdout) {
assert(!stdout);
return done();
});
});
});
describe('On non-strict mode', function () {
var port, server;
before(function (done) {
reproduce({
strict: false
}, function (err, _server) {
server = _server;
port = server.address().port;
return done();
});
});
server.close()
})

it( 'should be restored', function ( done ) {
findCloseWaitConnections( port, function ( err, stdout ) {
assert( ! stdout )
done()
})
})
})

describe( 'On non-strict mode', function () {
var port, server

before(function ( done ) {
reproduce(
{
strict: false
},
function ( err, _server ) {
server = _server
port = server.address().port
done()
}
)
})

after(function () {
server.close();
});
it('should be restored', function (done) {
findCloseWaitConnections(port, function (err, stdout) {
assert(!stdout);
return done();
});
});
});
});
server.close()
})

it( 'should be restored', function ( done ) {
findCloseWaitConnections( port, function ( err, stdout ) {
assert( ! stdout )
done()
})
})
})
})
Loading

0 comments on commit 8fb1410

Please sign in to comment.