Add tests for permissions cache

Basic testcases for permission cache
It needs #1809 to run