配置Java安全策略以允许JUnit?

时间:2016-03-07 01:53:16

标签: java java-security

我正在开发一个Java应用程序。我想在安全限制的JVM中运行其单元测试,以阻止网络访问。

我向JVM添加了-Djava.security.manager=default -Djava.security.policy=...file...个选项,安全管理器也很有效。

我通过运行测试迭代了几次,查看发生了哪些安全违规,并将其授予策略文件。但现在,我不再受到任何安全违规行为的侵害。相反,这个:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.onebusaway.alexa.AuthedSpeechletTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.143 sec <<< FAILURE! - in org.onebusaway.alexa.AuthedSpeechletTest
org.onebusaway.alexa.AuthedSpeechletTest  Time elapsed: 0.06 sec  <<< ERROR!
java.lang.NoClassDefFoundError: org.junit.runner.Runner
  at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:364)
  at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)
  at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
  at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)

Running org.onebusaway.alexa.MainSpeechletEmptyTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.001 sec <<< FAILURE! - in org.onebusaway.alexa.MainSpeechletEmptyTest
org.onebusaway.alexa.MainSpeechletEmptyTest  Time elapsed: 0 sec  <<< ERROR!
java.lang.NoClassDefFoundError: org.junit.runner.Runner
  at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:364)
  at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)
  at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
  at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)


Results :

Tests in error:
  JUnit4Provider.invoke:161->executeTestSet:238->executeWithRerun:274->execute:364 » NoClassDefFound
  JUnit4Provider.invoke:161->executeTestSet:238->executeWithRerun:274->execute:364 » NoClassDefFound

Tests run: 2, Failures: 0, Errors: 2, Skipped: 0

如何确切地查看此处违反了哪些安全策略? (我尝试用-X重新运行,但这并没有透露任何新​​内容。)

0 个答案:

没有答案