Add a test for #776 - Infinite loop on permissions check