mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Ensure context.flow/global cannot be deleted or enumerated
This commit is contained in:
parent
fc0cf1ff51
commit
75e7c0e50d
@ -221,8 +221,9 @@ function createContext(id,seed) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
obj.get = function(key, storage, callback) {
|
||||
Object.defineProperties(obj, {
|
||||
get: {
|
||||
value: function(key, storage, callback) {
|
||||
var context;
|
||||
if (!storage && !callback) {
|
||||
context = stores["_"];
|
||||
@ -264,8 +265,10 @@ function createContext(id,seed) {
|
||||
}
|
||||
return results;
|
||||
}
|
||||
};
|
||||
obj.set = function(key, value, storage, callback) {
|
||||
}
|
||||
},
|
||||
set: {
|
||||
value: function(key, value, storage, callback) {
|
||||
var context;
|
||||
if (!storage && !callback) {
|
||||
context = stores["_"];
|
||||
@ -280,8 +283,10 @@ function createContext(id,seed) {
|
||||
context = getContextStorage(storage);
|
||||
}
|
||||
context.set(scope, key, value, callback);
|
||||
};
|
||||
obj.keys = function(storage, callback) {
|
||||
}
|
||||
},
|
||||
keys: {
|
||||
value: function(storage, callback) {
|
||||
var context;
|
||||
if (!storage && !callback) {
|
||||
context = stores["_"];
|
||||
@ -307,7 +312,9 @@ function createContext(id,seed) {
|
||||
} else {
|
||||
return context.keys(scope, callback);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
@ -321,9 +328,13 @@ function getContext(localId,flowId) {
|
||||
}
|
||||
var newContext = createContext(contextId);
|
||||
if (flowId) {
|
||||
newContext.flow = getContext(flowId);
|
||||
Object.defineProperty(newContext, 'flow', {
|
||||
value: getContext(flowId)
|
||||
});
|
||||
}
|
||||
newContext.global = contexts['global'];
|
||||
Object.defineProperty(newContext, 'global', {
|
||||
value: contexts['global']
|
||||
})
|
||||
contexts[contextId] = newContext;
|
||||
return newContext;
|
||||
}
|
||||
|
@ -113,6 +113,21 @@ describe('context', function() {
|
||||
context2.global.get("foo").should.equal("test");
|
||||
});
|
||||
|
||||
it('context.flow/global are not enumerable', function() {
|
||||
var context1 = Context.get("1","flowA");
|
||||
Object.keys(context1).length.should.equal(0);
|
||||
Object.keys(context1.flow).length.should.equal(0);
|
||||
Object.keys(context1.global).length.should.equal(0);
|
||||
})
|
||||
|
||||
it('context.flow/global cannot be deleted', function() {
|
||||
var context1 = Context.get("1","flowA");
|
||||
delete context1.flow;
|
||||
should.exist(context1.flow);
|
||||
delete context1.global;
|
||||
should.exist(context1.global);
|
||||
})
|
||||
|
||||
it('deletes context',function() {
|
||||
var context = Context.get("1","flowA");
|
||||
should.not.exist(context.get("foo"));
|
||||
|
Loading…
Reference in New Issue
Block a user