How to unit test Java code that is expected to run within an applet Security Manager

会有一股神秘感。 提交于 2019-12-12 09:48:57

问题


I have some Java library code which sometimes runs as an unsigned applet. Because of this it is not always allowed to do some operations (for instance checking for system properties).

I would like to run some unit tests with an Applet-like security manager so that I can verify that the code is either not performing any restricted operations, or correctly handling any security exceptions.

What is the best way to run these unit-tests with a realistic Security-Manager configuration? Preferable the solution would be something that can integrate with JUnit.


回答1:


Not a solution as such, but couldn't you implement your own subclass of SecurityManager, perhaps delegating all calls to a 'pseudo security manager' which would in turn be mocked by EasyMock/similar? You could then set this SecurityManager using System.setSecurityManager().

Provided you know what your applet should be able to do, you can then fail the test depending on your requirements.

I may have missed what you want to achieve, but that seems like one possible approach.



来源:https://stackoverflow.com/questions/2138817/how-to-unit-test-java-code-that-is-expected-to-run-within-an-applet-security-man

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!