BZ-991058: protecting code execution. Adding test cases.
(cherry picked from commit 6f4ad2f39e2c3deb2c7cbf2492c6f6be1391c614)