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

Disallow store names that are not A-Za-z0-9_

This commit is contained in:
Nick O'Leary 2018-07-16 16:44:33 +01:00
parent d9d15e41c7
commit 75c29f1cb7
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 13 additions and 20 deletions

View File

@ -161,6 +161,7 @@
"error-module-not-loaded": "'__module__' could not be loaded",
"error-loading-module": "Error loading context module '__module__': __message__ ",
"error-module-not-defined": "'module' is not defined in '__storage__' of settings.contextStorage",
"error-invalid-module-name": "Invalid context store name: '__name__'",
"error-invalid-default-module": "Invalid storage '__storage__' is specified as a default storage",
"error-use-undefined-storage": "Undefined storage '__storage__' is specified"
}

View File

@ -56,6 +56,9 @@ function load() {
if (pluginName === "_") {
continue;
}
if (!/^[a-zA-Z0-9_]+$/.test(pluginName)) {
return reject(new Error(log._("context.error-invalid-module-name", {name:pluginName})));
}
// Check if this is setting the 'default' context to be a named plugin
if (pluginName === "default" && typeof plugins[pluginName] === "string") {

View File

@ -292,26 +292,6 @@ describe('context', function() {
Context.init({contextStorage:{file:{module:"localfilesystem",config:{dir:resourcesDir}}}});
Context.load();
});
it('should accept special storage name', function(done) {
Context.init({
contextStorage:{
"#%&":{module:testPlugin},
\u3042:{module:testPlugin},
1:{module:testPlugin},
}
});
Context.load().then(function(){
var context = Context.get("1","flow");
var cb = function(){done("An error occurred")}
context.set("sign","sign1","#%&",cb);
context.set("file","file2","\u3042",cb);
context.set("num","num3","1",cb);
stubSet.calledWithExactly("1:flow","sign","sign1",cb).should.be.true();
stubSet.calledWithExactly("1:flow","file","file2",cb).should.be.true();
stubSet.calledWithExactly("1:flow","num","num3",cb).should.be.true();
done();
}).catch(done);
});
it('should ignore reserved storage name `_`', function(done) {
Context.init({contextStorage:{_:{module:testPlugin}}});
Context.load().then(function(){
@ -326,6 +306,15 @@ describe('context', function() {
done();
}).catch(done);
});
it('should fail when using invalid store name', function(done) {
Context.init({contextStorage:{'Invalid name':"noexist"}});
Context.load().then(function(){
done("An error was not thrown");
}).catch(function(){
done();
});
});
it('should fail when using invalid default context', function(done) {
Context.init({contextStorage:{default:"noexist"}});
Context.load().then(function(){