OptimalBits / node_acl

Access control lists for node applications
2.62k stars 369 forks source link

Problem when any of ACL Middleware argument is null or undefined | Solved #213

Closed akashdeepsinghal closed 7 years ago

akashdeepsinghal commented 8 years ago

This is the solution for my the issue #212 I had filed earlier

In my used case, I wanted to send a custom userId and it was breaking down and the middleware throws Broke parameter contract. Problem was with the contract.js code in which, in the checkParams function, it straight-away starts comparing the type of incoming arguments with the allowed contract types

Old Code:-

      type = typeOf(args[i]);
      fulfilled = false;
      for(j=0; j<types.length; j++){
        if (type === types[j]){
          fulfilled = true;
          break;
        }
      }
      if(fulfilled===false){
        return false;
      }
    }

New Code:-

      if (args[i]) {
        type = typeOf(args[i]);
        fulfilled = false;
        for(j=0; j<types.length; j++){
          if (type === types[j]){
            fulfilled = true;
            break;
          }
        }
      }
      if(fulfilled===false){
        return false;
      }
    }

After this, this works perfectly. This is pretty common issue people must be facing since, one might need to send a custom userId or actions without specifying numPathComponents