Fix a couple of bugs in permission handling and introduce unit tests for role permissions.