Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

socks-proxy-agent

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socks-proxy-agent - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

test/server.crt

13

History.md
1.0.2 / 2015-07-01
==================
* remove "v4a" from description
* socks-proxy-agent: cast `port` to a Number
* travis: attempt to make node v0.8 work
* travis: test node v0.12, don't test v0.11
* test: pass `rejectUnauthorized` as a proxy opt
* test: catch http.ClientRequest errors
* test: add self-signed SSL server cert files
* test: refactor to use local SOCKS, HTTP and HTTPS servers
* README: use SVG for Travis-CI badge
1.0.1 / 2015-03-01

@@ -3,0 +16,0 @@ ==================

7

package.json
{
"name": "socks-proxy-agent",
"version": "1.0.1",
"description": "A SOCKS (v4a) proxy `http.Agent` implementation for HTTP and HTTPS",
"version": "1.0.2",
"description": "A SOCKS proxy `http.Agent` implementation for HTTP and HTTPS",
"main": "socks-proxy-agent.js",

@@ -33,4 +33,5 @@ "scripts": {

"devDependencies": {
"mocha": "2"
"mocha": "2",
"socksv5": "0.0.6"
}
}
socks-proxy-agent
================
### A SOCKS (v4a) proxy `http.Agent` implementation for HTTP and HTTPS
[![Build Status](https://travis-ci.org/TooTallNate/node-socks-proxy-agent.png?branch=master)](https://travis-ci.org/TooTallNate/node-socks-proxy-agent)
### A SOCKS proxy `http.Agent` implementation for HTTP and HTTPS
[![Build Status](https://travis-ci.org/TooTallNate/node-socks-proxy-agent.svg?branch=master)](https://travis-ci.org/TooTallNate/node-socks-proxy-agent)
This module provides an `http.Agent` implementation that connects to a specified
SOCKS (v4a) proxy server, and can be used with the built-in `http` or `https`
modules.
This module provides an `http.Agent` implementation that connects to a
specified SOCKS proxy server, and can be used with the built-in `http`
or `https` modules.

@@ -10,0 +10,0 @@ It can also be used in conjunction with the `ws` module to establish a WebSocket

@@ -136,7 +136,7 @@

ipaddress: proxy.host,
port: proxy.port,
port: +proxy.port,
type: proxy.version
},
target: {
port: opts.port
port: +opts.port
},

@@ -143,0 +143,0 @@ command: 'connect'

@@ -6,3 +6,3 @@

var net = require('net');
var fs = require('fs');
var url = require('url');

@@ -12,52 +12,175 @@ var http = require('http');

var assert = require('assert');
var socks = require('socksv5');
var SocksProxyAgent = require('../');
describe('SocksProxyAgent', function () {
var httpServer, httpPort;
var httpsServer, httpsPort;
var socksServer, socksPort;
// adjusting the "slow" and "timeout" values because I run the
// tests against the Tor SOCKS proxy
this.slow(5000);
this.timeout(10000);
before(function (done) {
// setup SOCKS proxy server
socksServer = socks.createServer(function(info, accept, deny) {
//console.log(info);
accept();
});
socksServer.listen(0, '127.0.0.1', function() {
socksPort = socksServer.address().port;
//console.log('SOCKS server listening on port %d', socksPort);
done();
});
socksServer.useAuth(socks.auth.None());
//socksServer.useAuth(socks.auth.UserPassword(function(user, password, cb) {
// cb(user === 'nodejs' && password === 'rules!');
//}));
});
var proxy = process.env.SOCKS_PROXY || process.env.socks_proxy || 'socks://127.0.0.1:9050';
before(function (done) {
// setup target HTTP server
httpServer = http.createServer();
httpServer.listen(function () {
httpPort = httpServer.address().port;
done();
});
});
it('should work against an HTTP endpoint', function (done) {
var agent = new SocksProxyAgent(proxy);
var link = 'http://jsonip.com/';
var opts = url.parse(link);
opts.agent = agent;
http.get(opts, function (res) {
var data = '';
res.setEncoding('utf8');
res.on('data', function (b) {
data += b;
before(function (done) {
// setup target SSL HTTPS server
var options = {
key: fs.readFileSync(__dirname + '/server.key'),
cert: fs.readFileSync(__dirname + '/server.crt')
};
httpsServer = https.createServer(options);
httpsServer.listen(function () {
httpsPort = httpsServer.address().port;
done();
});
});
after(function (done) {
socksServer.once('close', function () { done(); });
socksServer.close();
});
after(function (done) {
httpServer.once('close', function () { done(); });
httpServer.close();
});
after(function (done) {
httpsServer.once('close', function () { done(); });
httpsServer.close();
});
describe('constructor', function () {
it('should throw an Error if no "proxy" argument is given', function () {
assert.throws(function () {
new SocksProxyAgent();
});
res.on('end', function () {
data = JSON.parse(data);
assert('ip' in data);
assert(net.isIP(data.ip));
done();
});
it('should accept a "string" proxy argument', function () {
var agent = new SocksProxyAgent('socks://127.0.0.1:' + socksPort);
assert.equal('127.0.0.1', agent.proxy.host);
assert.equal(socksPort, agent.proxy.port);
assert.equal(false, agent.secureEndpoint);
});
it('should accept a `url.parse()` result object argument', function () {
var opts = url.parse('socks://127.0.0.1:' + socksPort);
var agent = new SocksProxyAgent(opts);
assert.equal('127.0.0.1', agent.proxy.host);
assert.equal(socksPort, agent.proxy.port);
assert.equal(false, agent.secureEndpoint);
});
describe('secureEndpoint', function () {
it('should default to `false`', function () {
var opts = url.parse('socks://127.0.0.1:' + socksPort);
var agent = new SocksProxyAgent(opts);
assert.equal(socksPort, agent.proxy.port);
assert.equal(false, agent.secureEndpoint);
});
it('should be `true` when passed in as the second argument', function () {
var opts = url.parse('socks://127.0.0.1:' + socksPort);
var agent = new SocksProxyAgent(opts, true);
assert.equal(socksPort, agent.proxy.port);
assert.equal(true, agent.secureEndpoint);
});
});
});
it('should work against an HTTPS endpoint', function (done) {
var agent = new SocksProxyAgent(proxy, true);
var link = 'https://graph.facebook.com/tootallnate';
var opts = url.parse(link);
opts.agent = agent;
https.get(opts, function (res) {
var data = '';
res.setEncoding('utf8');
res.on('data', function (b) {
data += b;
describe('"http" module', function () {
it('should work against an HTTP endpoint', function (done) {
// set HTTP "request" event handler for this test
httpServer.once('request', function (req, res) {
assert.equal('/foo', req.url);
res.statusCode = 404;
res.end(JSON.stringify(req.headers));
});
res.on('end', function () {
data = JSON.parse(data);
assert.equal('tootallnate', data.username);
done();
var secure = false;
var proxy = 'socks://127.0.0.1:' + socksPort;
var agent = new SocksProxyAgent(proxy, secure);
var link = 'http://127.0.0.1:' + httpPort + '/foo';
var opts = url.parse(link);
opts.agent = agent;
opts.headers = { foo: 'bar' };
var req = http.get(opts, function (res) {
assert.equal(404, res.statusCode);
var data = '';
res.setEncoding('utf8');
res.on('data', function (b) {
data += b;
});
res.on('end', function () {
data = JSON.parse(data);
assert.equal('bar', data.foo);
done();
});
});
req.once('error', done);
});
});
describe('"https" module', function () {
it('should work against an HTTPS endpoint', function (done) {
// set HTTPS "request" event handler for this test
httpsServer.once('request', function (req, res) {
assert.equal('/foo', req.url);
res.statusCode = 404;
res.end(JSON.stringify(req.headers));
});
var secure = true;
var proxy = url.parse('socks://127.0.0.1:' + socksPort);
// XXX: in node >= v0.12, you can pass the `rejectUnauthorized`
// directly to the http.get() `opts`, but for <= v0.10 we're
// passing it as a proxy option instead
proxy.rejectUnauthorized = false;
var agent = new SocksProxyAgent(proxy, secure);
var link = 'https://127.0.0.1:' + httpsPort + '/foo';
var opts = url.parse(link);
opts.agent = agent;
// XXX: works in v0.12, doesn't in <= v0.10
//opts.rejectUnauthorized = false;
opts.headers = { foo: 'bar' };
var req = https.get(opts, function (res) {
assert.equal(404, res.statusCode);
var data = '';
res.setEncoding('utf8');
res.on('data', function (b) {
data += b;
});
res.on('end', function () {
data = JSON.parse(data);
assert.equal('bar', data.foo);
done();
});
});
req.once('error', done);
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc