1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

fix many test problems (#1677)

* fix many test problems

- adds [stoppable](https://npm.im/stoppable) to force-stop net & http
  servers
- upgrades to latest mocha
- much cleanup of servers
- some removal of useless code

Signed-off-by: Christopher Hiller <boneskull@boneskull.com>

* increase wait time to hack at race condition

* PoC with fork of stoppable

Signed-off-by: Christopher Hiller <boneskull@boneskull.com>

* fix custom stoppable url for newer npm

* make travis go faster; attempt to avoid npm troubles

* fix coveralls executable path

* add extra time for flake to trigger spec

Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
This commit is contained in:
Christopher Hiller 2018-04-23 04:37:26 -07:00 committed by Nick O'Leary
parent 25345302e8
commit e1195ac00a
33 changed files with 267 additions and 194 deletions

View File

@ -1,20 +1,10 @@
sudo: false sudo: false
language: node_js language: node_js
env:
- CXX="g++-4.8"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- gcc-4.8
node_js: node_js:
- "8" - "8"
- "6" - "6"
- "4" - "4"
script: script:
- istanbul cover ./node_modules/.bin/grunt --report lcovonly && istanbul report text && ( cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js || true ) && rm -rf coverage - istanbul cover ./node_modules/.bin/grunt --report lcovonly && istanbul report text && ( cat coverage/lcov.info | $(npm get prefix)/bin/coveralls || true ) && rm -rf coverage
before_script: before_script:
- npm install -g istanbul - npm install -g istanbul coveralls
- npm install coveralls

View File

@ -1,114 +1,115 @@
{ {
"name": "node-red", "name": "node-red",
"version": "0.18.4", "version": "0.18.4",
"description": "A visual tool for wiring the Internet of Things", "description": "A visual tool for wiring the Internet of Things",
"homepage": "http://nodered.org", "homepage": "http://nodered.org",
"license": "Apache-2.0", "license": "Apache-2.0",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/node-red/node-red.git" "url": "https://github.com/node-red/node-red.git"
},
"main": "red/red.js",
"scripts": {
"start": "node red.js",
"test": "grunt",
"build": "grunt build"
},
"bin": {
"node-red": "./red.js",
"node-red-pi": "bin/node-red-pi"
},
"contributors": [
{
"name": "Nick O'Leary"
}, },
"main": "red/red.js", {
"scripts": { "name": "Dave Conway-Jones"
"start": "node red.js",
"test": "grunt",
"build": "grunt build"
},
"bin": {
"node-red": "./red.js",
"node-red-pi": "bin/node-red-pi"
},
"contributors": [
{
"name": "Nick O'Leary"
},
{
"name": "Dave Conway-Jones"
}
],
"keywords": [
"editor",
"messaging",
"iot",
"flow"
],
"dependencies": {
"basic-auth": "2.0.0",
"bcryptjs": "2.4.3",
"body-parser": "1.18.2",
"cheerio": "0.22.0",
"clone": "2.1.1",
"cookie": "0.3.1",
"cookie-parser": "1.4.3",
"cors": "2.8.4",
"cron": "1.3.0",
"express": "4.16.2",
"express-session": "1.15.6",
"follow-redirects": "1.3.0",
"fs-extra": "5.0.0",
"fs.notify": "0.0.4",
"hash-sum": "1.0.2",
"i18next": "1.10.6",
"is-utf8": "0.2.1",
"js-yaml": "3.10.0",
"json-stringify-safe": "5.0.1",
"jsonata": "1.5.0",
"media-typer": "0.3.0",
"memorystore": "1.6.0",
"mqtt": "2.15.1",
"multer": "1.3.0",
"mustache": "2.3.0",
"node-red-node-email": "0.1.*",
"node-red-node-feedparser": "0.1.*",
"node-red-node-rbe": "0.2.*",
"node-red-node-twitter": "0.1.*",
"nopt": "4.0.1",
"oauth2orize": "1.11.0",
"on-headers": "1.0.1",
"passport": "0.4.0",
"passport-http-bearer": "1.0.1",
"passport-oauth2-client-password": "0.1.2",
"raw-body": "2.3.2",
"semver": "5.4.1",
"sentiment": "2.1.0",
"uglify-js": "3.3.6",
"when": "3.7.8",
"ws": "1.1.5",
"xml2js": "0.4.19"
},
"optionalDependencies": {
"bcrypt": "~1.0.3"
},
"devDependencies": {
"chromedriver": "^2.33.2",
"grunt": "~1.0.1",
"grunt-chmod": "~1.1.1",
"grunt-cli": "~1.2.0",
"grunt-concurrent": "~2.3.1",
"grunt-contrib-clean": "~1.1.0",
"grunt-contrib-compress": "~1.4.0",
"grunt-contrib-concat": "~1.0.1",
"grunt-contrib-copy": "~1.0.0",
"grunt-contrib-jshint": "~1.1.0",
"grunt-contrib-uglify": "~3.3.0",
"grunt-contrib-watch": "~1.0.0",
"grunt-jsonlint": "~1.1.0",
"grunt-mocha-istanbul": "5.0.2",
"grunt-nodemon": "~0.4.2",
"grunt-sass": "~2.0.0",
"grunt-simple-mocha": "~0.4.1",
"grunt-webdriver": "^2.0.3",
"istanbul": "0.4.5",
"mocha": "~3.4.2",
"should": "^8.4.0",
"sinon": "1.17.7",
"supertest": "3.0.0",
"wdio-chromedriver-service": "^0.1.1",
"wdio-mocha-framework": "^0.5.11",
"wdio-spec-reporter": "^0.1.3",
"webdriverio": "^4.9.11"
},
"engines": {
"node": ">=4"
} }
],
"keywords": [
"editor",
"messaging",
"iot",
"flow"
],
"dependencies": {
"basic-auth": "2.0.0",
"bcryptjs": "2.4.3",
"body-parser": "1.18.2",
"cheerio": "0.22.0",
"clone": "2.1.1",
"cookie": "0.3.1",
"cookie-parser": "1.4.3",
"cors": "2.8.4",
"cron": "1.3.0",
"express": "4.16.2",
"express-session": "1.15.6",
"follow-redirects": "1.3.0",
"fs-extra": "5.0.0",
"fs.notify": "0.0.4",
"hash-sum": "1.0.2",
"i18next": "1.10.6",
"is-utf8": "0.2.1",
"js-yaml": "3.10.0",
"json-stringify-safe": "5.0.1",
"jsonata": "1.5.0",
"media-typer": "0.3.0",
"memorystore": "1.6.0",
"mqtt": "2.15.1",
"multer": "1.3.0",
"mustache": "2.3.0",
"node-red-node-email": "0.1.*",
"node-red-node-feedparser": "0.1.*",
"node-red-node-rbe": "0.2.*",
"node-red-node-twitter": "0.1.*",
"nopt": "4.0.1",
"oauth2orize": "1.11.0",
"on-headers": "1.0.1",
"passport": "0.4.0",
"passport-http-bearer": "1.0.1",
"passport-oauth2-client-password": "0.1.2",
"raw-body": "2.3.2",
"semver": "5.4.1",
"sentiment": "2.1.0",
"uglify-js": "3.3.6",
"when": "3.7.8",
"ws": "1.1.5",
"xml2js": "0.4.19"
},
"optionalDependencies": {
"bcrypt": "~1.0.3"
},
"devDependencies": {
"chromedriver": "^2.33.2",
"grunt": "~1.0.1",
"grunt-chmod": "~1.1.1",
"grunt-cli": "~1.2.0",
"grunt-concurrent": "~2.3.1",
"grunt-contrib-clean": "~1.1.0",
"grunt-contrib-compress": "~1.4.0",
"grunt-contrib-concat": "~1.0.1",
"grunt-contrib-copy": "~1.0.0",
"grunt-contrib-jshint": "~1.1.0",
"grunt-contrib-uglify": "~3.3.0",
"grunt-contrib-watch": "~1.0.0",
"grunt-jsonlint": "~1.1.0",
"grunt-mocha-istanbul": "5.0.2",
"grunt-nodemon": "~0.4.2",
"grunt-sass": "~2.0.0",
"grunt-simple-mocha": "~0.4.1",
"grunt-webdriver": "^2.0.3",
"istanbul": "0.4.5",
"mocha": "^5.1.1",
"should": "^8.4.0",
"sinon": "1.17.7",
"stoppable": "^1.0.6",
"supertest": "3.0.0",
"wdio-chromedriver-service": "^0.1.1",
"wdio-mocha-framework": "^0.5.11",
"wdio-spec-reporter": "^0.1.3",
"webdriverio": "^4.9.11"
},
"engines": {
"node": ">=4"
}
} }

View File

@ -24,6 +24,10 @@ describe('sentiment Node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
}); });

View File

@ -24,6 +24,10 @@ describe('inject node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
}); });

View File

@ -25,6 +25,10 @@ describe('debug node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
beforeEach(function (done) { beforeEach(function (done) {
setTimeout(function() { setTimeout(function() {
done(); done();

View File

@ -24,6 +24,10 @@ describe('link Node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
}); });

View File

@ -24,6 +24,10 @@ describe('function node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
}); });

View File

@ -24,6 +24,10 @@ describe('template node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
}); });

View File

@ -304,11 +304,11 @@ describe('trigger node', function() {
} }
else { else {
msg.should.have.a.property("payload", "bar"); msg.should.have.a.property("payload", "bar");
spy.restore(); RED.util.evaluateNodeProperty.restore();
done(); done();
} }
} }
catch(err) { spy.restore(); done(err); } catch(err) { RED.util.evaluateNodeProperty.restore(); done(err); }
}); });
n1.emit("input", {payload:null}); n1.emit("input", {payload:null});
}); });
@ -384,6 +384,7 @@ describe('trigger node', function() {
}); });
it('should be able to extend the delay', function(done) { it('should be able to extend the delay', function(done) {
this.timeout(5000); // add extra time for flake
var spy = sinon.stub(RED.util, 'evaluateNodeProperty', var spy = sinon.stub(RED.util, 'evaluateNodeProperty',
function(arg1, arg2, arg3, arg4) { return arg1; } function(arg1, arg2, arg3, arg4) { return arg1; }
); );

View File

@ -19,6 +19,7 @@ var http = require("http");
var should = require("should"); var should = require("should");
var express = require("express"); var express = require("express");
var bodyParser = require('body-parser'); var bodyParser = require('body-parser');
var stoppable = require('stoppable');
var helper = require("../../helper.js"); var helper = require("../../helper.js");
var httpRequestNode = require("../../../../nodes/core/io/21-httprequest.js"); var httpRequestNode = require("../../../../nodes/core/io/21-httprequest.js");
var hashSum = require("hash-sum"); var hashSum = require("hash-sum");
@ -30,13 +31,10 @@ describe('HTTP Request Node', function() {
function startServer(done) { function startServer(done) {
testPort += 1; testPort += 1;
testServer = http.createServer(testApp); testServer = stoppable(http.createServer(testApp));
testServer.on('error', function(err) {
startServer(done);
});
testServer.listen(testPort,function(err) { testServer.listen(testPort,function(err) {
done(); done(err);
}) });
} }
function getTestURL(url) { function getTestURL(url) {
@ -57,13 +55,18 @@ describe('HTTP Request Node', function() {
} }
res.json(result); res.json(result);
}); });
startServer(function() { startServer(function(err) {
if (err) {
done(err);
}
helper.startServer(done); helper.startServer(done);
}); });
}); });
after(function() { after(function(done) {
testServer.close(); testServer.stop(() => {
helper.stopServer(done);
});
}); });
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();

View File

@ -61,6 +61,10 @@ describe('websocket Node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
closeAll(); closeAll();
helper.unload(); helper.unload();

View File

@ -16,6 +16,7 @@
var net = require("net"); var net = require("net");
var should = require("should"); var should = require("should");
var stoppable = require('stoppable');
var helper = require("../../helper.js"); var helper = require("../../helper.js");
var tcpinNode = require("../../../../nodes/core/io/31-tcpin.js"); var tcpinNode = require("../../../../nodes/core/io/31-tcpin.js");
@ -26,20 +27,13 @@ describe('TCP in Node', function() {
var server_port = 9300; var server_port = 9300;
var reply_data = undefined; var reply_data = undefined;
before(function(done) {
done();
});
after(function() {
});
beforeEach(function(done) { beforeEach(function(done) {
startServer(done); startServer(done);
}); });
afterEach(function() { afterEach(function(done) {
stopServer();
helper.unload(); helper.unload();
stopServer(done);
}); });
function sendArray(sock, array) { function sendArray(sock, array) {
@ -55,15 +49,15 @@ describe('TCP in Node', function() {
function startServer(done) { function startServer(done) {
server_port += 1; server_port += 1;
server = net.createServer(function(c) { server = stoppable(net.createServer(function(c) {
sendArray(c, reply_data); sendArray(c, reply_data);
}).listen(server_port, "localhost", function(err) { })).listen(server_port, "localhost", function(err) {
done(err); done(err);
}); });
} }
function stopServer() { function stopServer(done) {
server.close(); server.stop(done);
} }
function send(wdata) { function send(wdata) {

View File

@ -16,6 +16,7 @@
var net = require("net"); var net = require("net");
var should = require("should"); var should = require("should");
var stoppable = require('stoppable');
var helper = require("../../helper.js"); var helper = require("../../helper.js");
var tcpinNode = require("../../../../nodes/core/io/31-tcpin.js"); var tcpinNode = require("../../../../nodes/core/io/31-tcpin.js");
@ -26,7 +27,7 @@ describe('TCP Request Node', function() {
function startServer(done) { function startServer(done) {
port += 1; port += 1;
server = net.createServer(function(c) { server = stoppable(net.createServer(function(c) {
c.on('data', function(data) { c.on('data', function(data) {
var rdata = "ACK:"+data.toString(); var rdata = "ACK:"+data.toString();
c.write(rdata); c.write(rdata);
@ -34,7 +35,7 @@ describe('TCP Request Node', function() {
c.on('error', function(err) { c.on('error', function(err) {
startServer(done); startServer(done);
}); });
}).listen(port, "127.0.0.1", function(err) { })).listen(port, "127.0.0.1", function(err) {
done(); done();
}); });
} }
@ -43,8 +44,8 @@ describe('TCP Request Node', function() {
startServer(done); startServer(done);
}); });
after(function() { after(function(done) {
server.close(); server.stop(done);
}); });
afterEach(function() { afterEach(function() {

View File

@ -27,7 +27,8 @@ describe('UDP in Node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function() { after(function(done) {
helper.stopServer(done);
}); });
afterEach(function() { afterEach(function() {

View File

@ -27,7 +27,8 @@ describe('UDP out Node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function() { after(function(done) {
helper.stopServer(done);
}); });
afterEach(function() { afterEach(function() {
@ -38,7 +39,7 @@ describe('UDP out Node', function() {
var sock = dgram.createSocket('udp4'); var sock = dgram.createSocket('udp4');
sock.on('message', function(msg, rinfo) { sock.on('message', function(msg, rinfo) {
msg.should.deepEqual(data); msg.should.deepEqual(data);
done(); sock.close(done);
}); });
sock.bind(port, '127.0.0.1'); sock.bind(port, '127.0.0.1');
port++; port++;

View File

@ -28,8 +28,8 @@ describe('switch Node', function() {
afterEach(function(done) { afterEach(function(done) {
helper.unload(); helper.unload();
helper.stopServer(done);
RED.settings.nodeMessageBufferMaxLength = 0; RED.settings.nodeMessageBufferMaxLength = 0;
helper.stopServer(done);
}); });
it('should be loaded with some defaults', function(done) { it('should be loaded with some defaults', function(done) {

View File

@ -578,7 +578,6 @@ describe('change Node', function() {
}); });
it('reports invalid regex', function(done) { it('reports invalid regex', function(done) {
var sinon = require('sinon');
var flow = [{"id":"changeNode1","type":"change","action":"change","property":"payload","from":"\\+**+","to":"NUMBER","reg":true,"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change","action":"change","property":"payload","from":"\\+**+","to":"NUMBER","reg":true,"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {

View File

@ -135,11 +135,13 @@ describe('range Node', function() {
var sinon = require('sinon'); var sinon = require('sinon');
sinon.stub(rangeNode1, 'log', function(log) { sinon.stub(rangeNode1, 'log', function(log) {
if (log.indexOf("notnumber") > -1) { if (log.indexOf("notnumber") > -1) {
rangeNode1.log.restore();
done(); done();
} else { } else {
try { try {
should.fail(null, null, "Non-number inputs should be reported!"); should.fail(null, null, "Non-number inputs should be reported!");
} catch (err) { } catch (err) {
rangeNode1.log.restore();
done(err); done(err);
} }
} }

View File

@ -26,6 +26,10 @@ describe('SPLIT node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
}); });
@ -268,6 +272,10 @@ describe('JOIN node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
RED.settings.nodeMessageBufferMaxLength = 0; RED.settings.nodeMessageBufferMaxLength = 0;

View File

@ -25,6 +25,10 @@ describe('SORT node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
RED.settings.nodeMessageBufferMaxLength = 0; RED.settings.nodeMessageBufferMaxLength = 0;

View File

@ -26,6 +26,10 @@ describe('BATCH node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
RED.settings.nodeMessageBufferMaxLength = 0; RED.settings.nodeMessageBufferMaxLength = 0;

View File

@ -24,6 +24,10 @@ describe('CSV node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
}); });

View File

@ -15,7 +15,6 @@
**/ **/
var should = require("should"); var should = require("should");
var sinon = require("sinon");
var path = require("path"); var path = require("path");
var fs = require('fs-extra'); var fs = require('fs-extra');
@ -31,6 +30,10 @@ describe('html node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
beforeEach(function() { beforeEach(function() {
fs.existsSync(file).should.be.true(); fs.existsSync(file).should.be.true();
}); });

View File

@ -24,6 +24,10 @@ describe('JSON node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
}); });

View File

@ -24,6 +24,10 @@ describe('XML node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
}); });

View File

@ -24,6 +24,10 @@ describe('YAML node', function() {
helper.startServer(done); helper.startServer(done);
}); });
after(function(done) {
helper.stopServer(done);
});
afterEach(function() { afterEach(function() {
helper.unload(); helper.unload();
}); });

View File

@ -130,15 +130,20 @@ describe('tail Node', function() {
}); });
} }
it('should throw an error if run on Windows', function(done) { it('should throw an error if run on Windows', function() {
// Stub os platform so we can make it look like windows // Stub os platform so we can make it look like windows
var os = require('os'); var os = require('os');
var spy = sinon.stub(os, 'platform', function(arg) { return("windows"); }); var spy = sinon.stub(os, 'platform', function(arg) { return("windows"); });
/*jshint immed: false */ /*jshint immed: false */
(function() { tailNode("1234"); }).should.throw(); try {
os.platform.restore(); (function() { tailNode("1234"); }).should.throw();
done(); } catch (err) {
throw err;
}
finally {
os.platform.restore();
}
}); });
/* /*

View File

@ -28,7 +28,7 @@ describe('file Nodes', function() {
var resourcesDir = path.join(__dirname,"..","..","..","resources"); var resourcesDir = path.join(__dirname,"..","..","..","resources");
var fileToTest = path.join(resourcesDir,"50-file-test-file.txt"); var fileToTest = path.join(resourcesDir,"50-file-test-file.txt");
var wait = 150; var wait = 250;
beforeEach(function(done) { beforeEach(function(done) {
//fs.writeFileSync(fileToTest, "File message line 1\File message line 2\n"); //fs.writeFileSync(fileToTest, "File message line 1\File message line 2\n");

View File

@ -19,6 +19,7 @@ var sinon = require("sinon");
var when = require("when"); var when = require("when");
var request = require('supertest'); var request = require('supertest');
var express = require("express"); var express = require("express");
var stoppable = require('stoppable');
var nock; var nock;
if (!process.version.match(/^v0\.[0-9]\./)) { if (!process.version.match(/^v0\.[0-9]\./)) {
// only set nock for node >= 0.10 // only set nock for node >= 0.10
@ -132,7 +133,7 @@ module.exports = {
}, },
startServer: function(done) { startServer: function(done) {
server = http.createServer(function(req,res) { app(req,res); }); server = stoppable(http.createServer(function(req,res) { app(req,res); }), 0);
RED.init(server, { RED.init(server, {
SKIP_BUILD_CHECK: true, SKIP_BUILD_CHECK: true,
logging:{console:{level:'off'}} logging:{console:{level:'off'}}
@ -150,13 +151,13 @@ module.exports = {
stopServer: function(done) { stopServer: function(done) {
if (server) { if (server) {
try { try {
server.on('close', function() { comms.stop();
comms.stop(); server.stop(done);
});
server.close(done);
} catch(e) { } catch(e) {
done(); done();
} }
} else {
done();
} }
}, },

View File

@ -813,7 +813,6 @@ describe("api/admin/nodes", function() {
describe('get icons', function() { describe('get icons', function() {
it('returns icon list', function(done) { it('returns icon list', function(done) {
debugger;
initNodes({ initNodes({
nodes:{ nodes:{
getNodeIcons: function() { getNodeIcons: function() {

View File

@ -16,6 +16,7 @@
var should = require("should"); var should = require("should");
var sinon = require("sinon"); var sinon = require("sinon");
const stoppable = require('stoppable');
var when = require("when"); var when = require("when");
var http = require('http'); var http = require('http');
@ -30,13 +31,8 @@ var Tokens = require("../../../../red/api/auth/tokens");
var address = '127.0.0.1'; var address = '127.0.0.1';
var listenPort = 0; // use ephemeral port var listenPort = 0; // use ephemeral port
describe("api/editor/comms", function() {
beforeEach(function (done) { describe("api/editor/comms", function() {
setTimeout(function() {
done();
}, 55);
});
describe("with default keepalive", function() { describe("with default keepalive", function() {
var server; var server;
@ -44,7 +40,7 @@ describe("api/editor/comms", function() {
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return when.resolve(null);}); sinon.stub(Users,"default",function() { return when.resolve(null);});
server = http.createServer(function(req,res){app(req,res)}); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, { comms.init(server, {
settings:{}, settings:{},
log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}}, log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}},
@ -59,9 +55,10 @@ describe("api/editor/comms", function() {
}); });
}); });
after(function() { after(function(done) {
Users.default.restore(); Users.default.restore();
comms.stop(); comms.stop();
server.stop(done);
}); });
it('accepts connection', function(done) { it('accepts connection', function(done) {
@ -150,7 +147,7 @@ describe("api/editor/comms", function() {
}); });
}); });
it.skip('listens for node/status events'); it('listens for node/status events');
}); });
describe("disabled editor", function() { describe("disabled editor", function() {
var server; var server;
@ -158,7 +155,7 @@ describe("api/editor/comms", function() {
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return when.resolve(null);}); sinon.stub(Users,"default",function() { return when.resolve(null);});
server = http.createServer(function(req,res){app(req,res)}); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, { comms.init(server, {
settings:{disableEditor:true}, settings:{disableEditor:true},
log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}}, log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}},
@ -173,9 +170,10 @@ describe("api/editor/comms", function() {
}); });
}); });
after(function() { after(function(done) {
Users.default.restore(); Users.default.restore();
comms.stop(); comms.stop();
server.stop(done);
}); });
it('rejects websocket connections',function(done) { it('rejects websocket connections',function(done) {
@ -197,7 +195,7 @@ describe("api/editor/comms", function() {
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return when.resolve(null);}); sinon.stub(Users,"default",function() { return when.resolve(null);});
server = http.createServer(function(req,res){app(req,res)}); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, { comms.init(server, {
settings:{httpAdminRoot:"/adminPath"}, settings:{httpAdminRoot:"/adminPath"},
log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}}, log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}},
@ -212,9 +210,10 @@ describe("api/editor/comms", function() {
}); });
}); });
after(function() { after(function(done) {
Users.default.restore(); Users.default.restore();
comms.stop(); comms.stop();
server.stop(done);
}); });
it('accepts connections',function(done) { it('accepts connections',function(done) {
@ -236,7 +235,7 @@ describe("api/editor/comms", function() {
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return when.resolve(null);}); sinon.stub(Users,"default",function() { return when.resolve(null);});
server = http.createServer(function(req,res){app(req,res)}); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server,{ comms.init(server,{
settings:{httpAdminRoot:"/adminPath"}, settings:{httpAdminRoot:"/adminPath"},
log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}}, log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}},
@ -251,9 +250,10 @@ describe("api/editor/comms", function() {
}); });
}); });
after(function() { after(function(done) {
Users.default.restore(); Users.default.restore();
comms.stop(); comms.stop();
server.stop(done);
}); });
it('accepts connections',function(done) { it('accepts connections',function(done) {
@ -275,7 +275,7 @@ describe("api/editor/comms", function() {
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return when.resolve(null);}); sinon.stub(Users,"default",function() { return when.resolve(null);});
server = http.createServer(function(req,res){app(req,res)}); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, { comms.init(server, {
settings:{httpAdminRoot:"adminPath"}, settings:{httpAdminRoot:"adminPath"},
log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}}, log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}},
@ -290,9 +290,10 @@ describe("api/editor/comms", function() {
}); });
}); });
after(function() { after(function(done) {
Users.default.restore(); Users.default.restore();
comms.stop(); comms.stop();
server.stop(done);
}); });
it('accepts connections',function(done) { it('accepts connections',function(done) {
@ -314,7 +315,7 @@ describe("api/editor/comms", function() {
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return when.resolve(null);}); sinon.stub(Users,"default",function() { return when.resolve(null);});
server = http.createServer(function(req,res){app(req,res)}); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, { comms.init(server, {
settings:{webSocketKeepAliveTime: 100}, settings:{webSocketKeepAliveTime: 100},
log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}}, log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}},
@ -328,9 +329,10 @@ describe("api/editor/comms", function() {
done(); done();
}); });
}); });
after(function() { after(function(done) {
Users.default.restore(); Users.default.restore();
comms.stop(); comms.stop();
server.stop(done);
}); });
it('are sent', function(done) { it('are sent', function(done) {
var ws = new WebSocket(url); var ws = new WebSocket(url);
@ -400,7 +402,7 @@ describe("api/editor/comms", function() {
}); });
server = http.createServer(function(req,res){app(req,res)}); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server,{ comms.init(server,{
settings:{adminAuth:{}}, settings:{adminAuth:{}},
log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}}, log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}},
@ -414,11 +416,12 @@ describe("api/editor/comms", function() {
done(); done();
}); });
}); });
after(function() { after(function(done) {
getDefaultUser.restore(); getDefaultUser.restore();
getUser.restore(); getUser.restore();
getToken.restore(); getToken.restore();
comms.stop(); comms.stop();
server.stop(done);
}); });
it('prevents connections that do not authenticate',function(done) { it('prevents connections that do not authenticate',function(done) {
@ -490,7 +493,7 @@ describe("api/editor/comms", function() {
var getDefaultUser; var getDefaultUser;
before(function(done) { before(function(done) {
getDefaultUser = sinon.stub(Users,"default",function() { return when.resolve({permissions:"read"});}); getDefaultUser = sinon.stub(Users,"default",function() { return when.resolve({permissions:"read"});});
server = http.createServer(function(req,res){app(req,res)}); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, { comms.init(server, {
settings:{adminAuth:{}}, settings:{adminAuth:{}},
log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}}, log:{warn:function(){},_:function(){},trace:function(){},audit:function(){}},
@ -504,9 +507,10 @@ describe("api/editor/comms", function() {
done(); done();
}); });
}); });
after(function() { after(function(done) {
getDefaultUser.restore(); getDefaultUser.restore();
comms.stop(); comms.stop();
server.stop(done);
}); });
it('allows anonymous connections that do not authenticate',function(done) { it('allows anonymous connections that do not authenticate',function(done) {

View File

@ -52,9 +52,9 @@ describe("api/editor/sshkeys", function() {
session_data = _session; session_data = _session;
return when.resolve(); return when.resolve();
} }
}, }
log:{audit:function(){},error:function(msg){errors.push(msg)}}
}, },
log:{audit:function(){},error:function(msg){errors.push(msg)},trace:function(){}},
storage: { storage: {
projects: { projects: {
ssh: { ssh: {

View File

@ -49,7 +49,11 @@ describe("localfilesystem/projects/git/authServer", function() {
return sendPrompt(rs.path,"Password"); return sendPrompt(rs.path,"Password");
}).then(function(response) { }).then(function(response) {
response.should.eql("TEST_PASS"); response.should.eql("TEST_PASS");
}).then(done).catch(function(err) { }).then(() => {
rs.close();
done();
}).catch(function(err) {
rs.close();
done(err); done(err);
}) })
@ -64,7 +68,11 @@ describe("localfilesystem/projects/git/authServer", function() {
return sendPrompt(rs.path,"Enter"); return sendPrompt(rs.path,"Enter");
}).then(function(response) { }).then(function(response) {
response.should.eql("TEST_PASSPHRASE"); response.should.eql("TEST_PASSPHRASE");
}).then(done).catch(function(err) { }).then(() => {
rs.close();
done();
}).catch(function(err) {
rs.close();
done(err); done(err);
}) })