fix permissionsPlugin and add tests