tor-router/test/test.js

99 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-01-31 15:56:42 +00:00
const SocksAgent = require('socks5-http-client/lib/Agent');
const request = require('request');
const async = require('async');
const temp = require('temp');
temp.track();
const TorRouter = require('../');
const getPort = require('get-port');
const dns = require('native-dns');
const _ = require('lodash');
2018-08-09 20:13:48 +00:00
const winston = require('winston');
2017-01-31 15:56:42 +00:00
2018-08-09 20:13:48 +00:00
var colors = require('mocha/lib/reporters/base').colors;
colors['diff added'] = 32;
colors['diff removed'] = 31;
2017-01-31 23:11:36 +00:00
2018-08-09 20:13:48 +00:00
var nconf = require('nconf')
nconf = require(`${__dirname}/../src/nconf_load_env.js`)(nconf);
nconf.defaults(require(`${__dirname}/../src/default_config.js`));
2017-03-22 16:44:08 +00:00
2018-08-09 20:13:48 +00:00
var logger = winston.createLogger({
level: 'info',
format: winston.format.simple(),
transports: [new (require('winston-null-transport'))() ]
});
2017-03-22 16:44:08 +00:00
2017-01-31 15:56:42 +00:00
describe('TorProcess', function () {
2018-08-09 20:13:48 +00:00
const torDataDir = temp.mkdirSync();
var tor = new (TorRouter.TorProcess)(nconf.get('torPath'), { DataDirectory: torDataDir, ProtocolWarnings: 0 }, null, logger);
2017-01-31 15:56:42 +00:00
describe('#create()', function () {
2018-08-09 20:13:48 +00:00
this.timeout(60000);
2017-01-31 15:56:42 +00:00
2018-08-09 20:13:48 +00:00
it('should create the child process', function (done) {
2017-01-31 15:56:42 +00:00
tor.create(done);
});
2018-08-09 20:13:48 +00:00
it('should signal when it is listening on the control port', function (done) {
if (tor.control_port_listening)
return done();
tor.once('control_listen', done);
2017-01-31 15:56:42 +00:00
});
2018-08-09 20:13:48 +00:00
it('should signal when connected to the control port', function (done) {
if (tor.control_port_connected)
return done();
tor.once('controller_ready', done);
2017-01-31 15:56:42 +00:00
});
2018-08-09 20:13:48 +00:00
it('should signal when it is listening on the socks port', function (done) {
if (tor.socks_port_listening)
return done();
tor.once('socks_listen', done);
2017-01-31 15:56:42 +00:00
});
2018-08-09 20:13:48 +00:00
it('should signal when it is listening on the dns port', function (done) {
if (tor.dns_port_listening)
return done();
tor.once('dns_listen', done);
2017-01-31 15:56:42 +00:00
});
2018-08-09 20:13:48 +00:00
it('should signal when bootstrapped', function (done) {
tor.once('error', done);
if (tor.bootstrapped)
return done();
tor.once('ready', done);
2017-01-31 15:56:42 +00:00
});
2018-08-09 20:13:48 +00:00
});
2017-01-31 15:56:42 +00:00
2018-08-09 20:13:48 +00:00
describe('#set_config(keyword, value)', function () {
it('should set sample configuration option via the control protocol', function (done) {
tor.set_config('ProtocolWarnings', 1, done);
2017-01-31 15:56:42 +00:00
});
});
2018-08-09 20:13:48 +00:00
describe('#get_config(keyword, value)', function () {
it('should retrieve sample configuration option via the control protocol', function (done) {
tor.get_config('ProtocolWarnings', function (error, value) {
done(error, (value == 1));
2017-01-31 15:56:42 +00:00
});
});
});
2018-08-09 20:13:48 +00:00
describe('#new_identity()', function () {
it('should use a new identity', function (done) {
tor.new_identity(done);
2017-01-31 15:56:42 +00:00
});
});
2018-08-09 20:13:48 +00:00
describe('#signal()', function () {
it('should send a signal via the control protocol', function (done) {
tor.signal('DEBUG', done);
2017-01-31 15:56:42 +00:00
});
});
2017-01-31 23:11:36 +00:00
2018-08-09 20:13:48 +00:00
after('shutdown tor', function () {
tor.exit();
require('fs').unlinkSync(torDataDir);
2017-01-31 23:11:36 +00:00
});
2018-08-09 20:13:48 +00:00
});