mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Tie auth middleware to needsPermission api
This commit is contained in:
@@ -27,59 +27,6 @@ var settings = require("../../../../red/settings");
|
||||
|
||||
|
||||
describe("api auth middleware",function() {
|
||||
describe("authenticate",function() {
|
||||
it("does not trigger on auth paths", sinon.test(function(done) {
|
||||
this.stub(passport,"authenticate",function() {
|
||||
return function() {
|
||||
settings.reset();
|
||||
done(new Error("authentication not applied to auth path"));
|
||||
}
|
||||
});
|
||||
settings.init({adminAuth:{}});
|
||||
var req = {
|
||||
originalUrl: "/auth/token"
|
||||
};
|
||||
auth.authenticate(req,null,function() {
|
||||
settings.reset();
|
||||
done();
|
||||
});
|
||||
|
||||
}));
|
||||
it("does trigger on non-auth paths", sinon.test(function(done) {
|
||||
this.stub(passport,"authenticate",function() {
|
||||
return function() {
|
||||
settings.reset();
|
||||
done();
|
||||
}
|
||||
});
|
||||
settings.init({adminAuth:{}});
|
||||
var req = {
|
||||
originalUrl: "/"
|
||||
};
|
||||
auth.authenticate(req,null,function() {
|
||||
settings.reset();
|
||||
done(new Error("authentication applied to non-auth path"));
|
||||
});
|
||||
|
||||
}));
|
||||
it("does not trigger on non-auth paths with auth disabled", sinon.test(function(done) {
|
||||
this.stub(passport,"authenticate",function() {
|
||||
return function() {
|
||||
settings.reset();
|
||||
done(new Error("authentication applied when disabled"));
|
||||
}
|
||||
});
|
||||
settings.init({});
|
||||
var req = {
|
||||
originalUrl: "/"
|
||||
};
|
||||
auth.authenticate(req,null,function() {
|
||||
settings.reset();
|
||||
done();
|
||||
});
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe("ensureClientSecret", function() {
|
||||
it("leaves client_secret alone if not present",function(done) {
|
||||
|
@@ -35,27 +35,4 @@ describe("Auth permissions", function() {
|
||||
permissions.hasPermission({permissions:"read"},"node.write").should.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
describe("needsPermission middleware", function() {
|
||||
it('passes if no user on request',function(done) {
|
||||
var needsPermission = permissions.needsPermission("*");
|
||||
needsPermission({},null,function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('passes if user has required permission',function(done) {
|
||||
var needsPermission = permissions.needsPermission("read");
|
||||
needsPermission({user:{permissions:"read"}},null,function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('rejects if user does not have required permission',function(done) {
|
||||
var needsPermission = permissions.needsPermission("write");
|
||||
needsPermission({user:{permissions:"read"}},{send: function(code) {
|
||||
code.should.equal(401);
|
||||
done();
|
||||
}},null);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@@ -27,7 +27,8 @@ describe("Users", function() {
|
||||
type:"credentials",
|
||||
users:[{
|
||||
username:"fred",
|
||||
password:"5f4dcc3b5aa765d61d8327deb882cf99", // 'password'
|
||||
password:'$2a$08$LpYMefvGZ3MjAfZGzcoyR.1BcfHh4wy4NpbN.cEny5aHnWOqjKOXK',
|
||||
// 'password' -> require('bcryptjs').hashSync('password', 8);
|
||||
permissions:"*"
|
||||
}]
|
||||
});
|
||||
|
@@ -24,6 +24,7 @@ var app = express();
|
||||
var RED = require("../../../red/red.js");
|
||||
var storage = require("../../../red/storage");
|
||||
var library = require("../../../red/api/library");
|
||||
var auth = require("../../../red/api/auth");
|
||||
|
||||
describe("library api", function() {
|
||||
|
||||
@@ -166,6 +167,7 @@ describe("library api", function() {
|
||||
app = express();
|
||||
app.use(express.json());
|
||||
library.init(app);
|
||||
auth.init({});
|
||||
RED.library.register("test");
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user