我用两个 in
操作 &&
串联起来,如果是 true && true , 实际得到的结果是 false, 这个是什么问题呀?
将 多个 in
拆成单独的 matchers 是正常的,&&
起来就非预期了.
const fs = require ('fs') const path = require ('path') const Casbin = require ('casbin')
const model1Text = `request_definition r = sub, obj, act
policy_definition p = sub, obj, act
policy_effect e = some (where (p.eft == allow))
matchers m = r.act in "('In', 'Out')"`
const model2Text = `request_definition r = sub, obj, act
policy_definition p = sub, obj, act
policy_effect e = some (where (p.eft == allow))
matchers m = r.sub in "('root', 'guest')"`
const model3Text = `request_definition r = sub, obj, act
policy_definition p = sub, obj, act
policy_effect e = some (where (p.eft == allow))
matchers m = r.act in "('In', 'Out')" && r.sub in "('root', 'guest')"` ; (async () => { //initial models const path1 = path.resolve (dirname, './model1.conf') const path2 = path.resolve (dirname, './model2.conf') const path3 = path.resolve (__dirname, './model3.conf') fs.writeFileSync (path1, model1Text) fs.writeFileSync (path2, model2Text) fs.writeFileSync (path3, model3Text)
//loading enforcer const enforcer1 = await Casbin.newEnforcer (path1) const enforcer2 = await Casbin.newEnforcer (path2) const enforcer3 = await Casbin.newEnforcer (path3)
//test const result1 = await enforcer1.enforce ('root', {}, 'In') const result2 = await enforcer2.enforce ('root', {}, 'In') const result3 = await enforcer3.enforce ('root', {}, 'In') console.log ('result1 : ', result1) //true console.log ('result2 : ', result2) //true console.log ('result3 : ', result3) //false })();