ControlServer.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const _ = require('lodash');
  2. const { assert } = require('chai');
  3. const { Provider } = require('nconf');
  4. const nconf = new Provider();
  5. const getPort = require('get-port');
  6. nconf.use('memory');
  7. require(`${__dirname}/../src/nconf_load_env.js`)(nconf);
  8. nconf.defaults(require(`${__dirname}/../src/default_config.js`));
  9. const { ControlServer, TorPool, HTTPServer, SOCKSServer, DNSServer } = require('../');
  10. let controlServer = new ControlServer(nconf);
  11. let controlPort;
  12. describe('ControlServer', function () {
  13. describe('#listen(port)', function () {
  14. it('should bind to a given port', async function () {
  15. controlPort = await getPort();
  16. await controlServer.listen(controlPort);
  17. });
  18. });
  19. describe('#createTorPool(options)', function () {
  20. it('should create a TorPool with a given configuration', function () {
  21. let torPool = controlServer.createTorPool({ ProtocolWarnings: 1 });
  22. assert.instanceOf(controlServer.tor_pool, TorPool);
  23. assert.equal(1, torPool.default_tor_config.ProtocolWarnings);
  24. });
  25. });
  26. describe('#createSOCKSServer(port)', function () {
  27. it('should create a SOCKS Server', async function () {
  28. let port = await getPort();
  29. controlServer.createSOCKSServer(port);
  30. assert.instanceOf(controlServer.socksServer, SOCKSServer);
  31. });
  32. });
  33. describe('#createDNSServer(port)', function () {
  34. it('should create a DNS Server', async function () {
  35. let port = await getPort();
  36. controlServer.createDNSServer(port);
  37. assert.instanceOf(controlServer.dnsServer, DNSServer);
  38. });
  39. });
  40. describe('#createHTTPServer(port)', function () {
  41. it('should create a HTTP Server', async function () {
  42. let port = await getPort();
  43. controlServer.createHTTPServer(port);
  44. assert.instanceOf(controlServer.httpServer, HTTPServer);
  45. });
  46. });
  47. describe('#close()', function () {
  48. it('should close the RPC Server', function () {
  49. controlServer.close();
  50. });
  51. });
  52. after('shutdown tor pool', async function () {
  53. await controlServer.tor_pool.exit();
  54. });
  55. });