Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

AND condition does not await async custom conditions passed as args #54

@kang-sctg

Description

@kang-sctg

Hi- your library is really enjoyable and intuitive to use! I ran into an issue with the AND condition; if you pass it any async custom conditions as args, it does not await those conditions.

Example- given the following grant definition:

{
  role: 'manager',
  resource: 'customers',
  action: 'PUT',
  attributes: ['*'],
  condition: {
    Fn: 'AND',
    args: [
      { Fn: 'custom:sameCustomer }, //sync
      { Fn: 'custom:userCanAccessResource' }, // async
    ],
  },
},

custom:userCanAccessResource is not awaited before permission is evaluated- permission.granted evaluates to "true" as long as all other conditions are met.

Even if you remove custom:sameOwner, you get the same result, so it doesn't seem to be an issue with combining sync with async conditions.

Looks like && Promise.resolve(elm) == elm in the containsPromises method is the culprit; if you comment out that condition, async custom functions passed to AND get awaited properly.

It would seem that removing this logic is the fix, but is there a reason that it's there & should not be removed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions