Move to express 4.x

This commit is contained in:
Nick O'Leary
2015-07-15 22:43:24 +01:00
parent ca91a5dd95
commit d668d43a0a
18 changed files with 143 additions and 148 deletions

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var should = require("should");
var when = require("when");
var sinon = require("sinon");
@@ -28,7 +28,7 @@ var settings = require("../../../../red/settings");
describe("api auth middleware",function() {
describe("ensureClientSecret", function() {
it("leaves client_secret alone if not present",function(done) {
var req = {
@@ -51,26 +51,26 @@ describe("api auth middleware",function() {
})
});
});
describe("revoke", function() {
it("revokes a token", function(done) {
var revokeToken = sinon.stub(Tokens,"revoke",function() {
return when.resolve();
});
var req = { body: { token: "abcdef" } };
var res = { send: function(resp) {
var res = { status: function(resp) {
revokeToken.restore();
resp.should.equal(200);
done();
}};
auth.revoke(req,res);
});
});
describe("login", function() {
beforeEach(function() {
sinon.stub(Tokens,"init",function(){});
@@ -96,7 +96,7 @@ describe("api auth middleware",function() {
done();
}});
});
});
});

View File

@@ -17,6 +17,7 @@
var should = require("should");
var request = require('supertest');
var express = require('express');
var bodyParser = require('body-parser');
var sinon = require('sinon');
var when = require('when');
@@ -25,16 +26,16 @@ var redNodes = require("../../../red/nodes");
var flows = require("../../../red/api/flows");
describe("flows api", function() {
var app;
before(function() {
app = express();
app.use(express.json());
app.use(bodyParser.json());
app.get("/flows",flows.get);
app.post("/flows",flows.post);
});
it('returns flow', function(done) {
var getFlows = sinon.stub(redNodes,'getFlows', function() {
return [1,2,3];
@@ -52,7 +53,7 @@ describe("flows api", function() {
done();
});
});
it('sets flows', function(done) {
var setFlows = sinon.stub(redNodes,'setFlows', function() {
return when.resolve();
@@ -86,5 +87,5 @@ describe("flows api", function() {
done();
});
});
});

View File

@@ -17,6 +17,7 @@
var should = require("should");
var request = require('supertest');
var express = require('express');
var bodyParser = require('body-parser');
var when = require('when');
@@ -27,7 +28,7 @@ var library = require("../../../red/api/library");
var auth = require("../../../red/api/auth");
describe("library api", function() {
function initStorage(_flows,_libraryEntries) {
var flows = _flows;
var libraryEntries = _libraryEntries;
@@ -67,13 +68,13 @@ describe("library api", function() {
describe("flows", function() {
var app;
before(function() {
app = express();
app.use(express.json());
app.use(bodyParser.json());
app.get("/library/flows",library.getAll);
app.post(new RegExp("/library/flows\/(.*)"),library.post);
app.get(new RegExp("/library/flows\/(.*)"),library.get);
app.get(new RegExp("/library/flows\/(.*)"),library.get);
});
it('returns empty result', function(done) {
initStorage({},{flows:{}});
@@ -97,8 +98,8 @@ describe("library api", function() {
.expect(404)
.end(done);
});
it('can store and retrieve item', function(done) {
initStorage({},{flows:{}});
var flow = '[]';
@@ -122,7 +123,7 @@ describe("library api", function() {
});
});
});
it('lists a stored item', function(done) {
initStorage({f:["bar"]});
request(app)
@@ -137,7 +138,7 @@ describe("library api", function() {
done();
});
});
it('returns 403 for malicious get attempt', function(done) {
initStorage({});
// without the userDir override the malicious url would be
@@ -162,10 +163,10 @@ describe("library api", function() {
describe("type", function() {
var app;
before(function() {
app = express();
app.use(express.json());
app.use(bodyParser.json());
library.init(app);
auth.init({});
RED.library.register("test");
@@ -184,7 +185,7 @@ describe("library api", function() {
done();
});
});
it('returns 404 for non-existent entry', function(done) {
initStorage({},{});
request(app)
@@ -192,7 +193,7 @@ describe("library api", function() {
.expect(404)
.end(done);
});
it('can store and retrieve item', function(done) {
initStorage({},{'test':{}});
var flow = {text:"test content"};
@@ -216,7 +217,7 @@ describe("library api", function() {
});
});
});
it('lists a stored item', function(done) {
initStorage({},{'test':{'a':['abc','def']}});
request(app)
@@ -232,22 +233,22 @@ describe("library api", function() {
done();
});
});
it('returns 403 for malicious access attempt', function(done) {
request(app)
.get('/library/test/../../../../../../../../../../etc/passwd')
.expect(403)
.end(done);
});
it('returns 403 for malicious access attempt', function(done) {
request(app)
.get('/library/test/..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\etc\\passwd')
.expect(403)
.end(done);
});
it('returns 403 for malicious access attempt', function(done) {
request(app)
.post('/library/test/../../../../../../../../../../etc/passwd')
@@ -256,6 +257,6 @@ describe("library api", function() {
.expect(403)
.end(done);
});
});
});

View File

@@ -17,6 +17,7 @@
var should = require("should");
var request = require('supertest');
var express = require('express');
var bodyParser = require('body-parser');
var sinon = require('sinon');
var when = require('when');
@@ -32,7 +33,7 @@ describe("nodes api", function() {
before(function() {
app = express();
app.use(express.json());
app.use(bodyParser.json());
app.get("/nodes",nodes.getAll);
app.post("/nodes",nodes.post);
app.get("/nodes/:mod",nodes.getModule);

View File

@@ -26,12 +26,12 @@ var ui = require("../../../red/api/ui");
describe("ui api", function() {
var app;
describe("slash handler", function() {
before(function() {
app = express();
app.get("/foo",ui.ensureSlash,function(req,res) { res.send(200);});
app.get("/foo",ui.ensureSlash,function(req,res) { res.sendStatus(200);});
});
it('redirects if the path does not end in a slash',function(done) {
request(app)
@@ -57,13 +57,13 @@ describe("ui api", function() {
.expect(200,done);
});
});
describe("icon handler", function() {
before(function() {
app = express();
app.get("/icons/:icon",ui.icon);
});
function binaryParser(res, callback) {
res.setEncoding('binary');
res.data = '';
@@ -80,7 +80,7 @@ describe("ui api", function() {
b1[i].should.equal(b2[i]);
}
}
it('returns the default icon when getting an unknown icon', function(done) {
var defaultIcon = fs.readFileSync(path.resolve(__dirname+'/../../../public/icons/arrow-in.png'));
request(app)
@@ -96,7 +96,7 @@ describe("ui api", function() {
compareBuffers(res.body,defaultIcon);
done();
});
});
it('returns a known icon', function(done) {
var injectIcon = fs.readFileSync(path.resolve(__dirname+'/../../../public/icons/inject.png'));
@@ -114,7 +114,7 @@ describe("ui api", function() {
done();
});
});
it('returns a registered icon' , function(done) {
var testIcon = fs.readFileSync(path.resolve(__dirname+'/../../resources/icons/test_icon.png'));
events.emit("node-icon-dir", path.resolve(__dirname+'/../../resources/icons'));
@@ -133,7 +133,7 @@ describe("ui api", function() {
});
});
});
describe("editor ui handler", function() {
before(function() {
app = express();
@@ -153,7 +153,7 @@ describe("ui api", function() {
});
});
});
describe("editor ui resource handler", function() {
before(function() {
app = express();
@@ -172,7 +172,7 @@ describe("ui api", function() {
});
});
});