mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Implement allow/denyList when loading/installing modules
This commit is contained in:
@@ -14,7 +14,54 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
const should = require("should");
|
||||
const NR_TEST_UTILS = require("nr-test-utils");
|
||||
const registryUtil = NR_TEST_UTILS.require("@node-red/registry/lib/util");
|
||||
|
||||
|
||||
describe("red/nodes/registry/util",function() {
|
||||
it.skip("NEEDS TESTS");
|
||||
describe("createNodeApi", function() {
|
||||
it.skip("needs tests");
|
||||
});
|
||||
describe("checkModuleAllowed", function() {
|
||||
function checkList(module, version, allowList, denyList) {
|
||||
return registryUtil.checkModuleAllowed(
|
||||
module,
|
||||
version,
|
||||
registryUtil.parseModuleList(allowList),
|
||||
registryUtil.parseModuleList(denyList)
|
||||
)
|
||||
}
|
||||
|
||||
it("allows module with no allow/deny list provided", function() {
|
||||
checkList("abc","1.2.3",[],[]).should.be.true();
|
||||
})
|
||||
it("defaults allow to * when only deny list is provided", function() {
|
||||
checkList("abc","1.2.3",["*"],["def"]).should.be.true();
|
||||
checkList("def","1.2.3",["*"],["def"]).should.be.false();
|
||||
})
|
||||
it("uses most specific matching rule", function() {
|
||||
checkList("abc","1.2.3",["ab*"],["a*"]).should.be.true();
|
||||
checkList("def","1.2.3",["d*"],["de*"]).should.be.false();
|
||||
})
|
||||
it("checks version string using semver rules", function() {
|
||||
// Deny
|
||||
checkList("abc","1.2.3",["abc@1.2.2"],["*"]).should.be.false();
|
||||
checkList("abc","1.2.3",["abc@1.2.4"],["*"]).should.be.false();
|
||||
checkList("abc","1.2.3",["abc@>1.2.3"],["*"]).should.be.false();
|
||||
checkList("abc","1.2.3",["abc@>=1.2.3"],["abc"]).should.be.false();
|
||||
|
||||
|
||||
checkList("node-red-contrib-foo","1.2.3",["*"],["*contrib*"]).should.be.false();
|
||||
|
||||
|
||||
// Allow
|
||||
checkList("abc","1.2.3",["abc@1.2.3"],["*"]).should.be.true();
|
||||
checkList("abc","1.2.3",["abc@<1.2.4"],["*"]).should.be.true();
|
||||
checkList("abc","1.2.3",["abc"],["abc@>1.2.3"]).should.be.true();
|
||||
checkList("abc","1.2.3",["abc"],["abc@<1.2.3||>1.2.3"]).should.be.true();
|
||||
checkList("node-red-contrib-foo","1.2.3",["*contrib*"],["*"]).should.be.true();
|
||||
})
|
||||
|
||||
})
|
||||
});
|
||||
|
Reference in New Issue
Block a user