Add tests for permission leaking
Implement permission leaking