当TrustManagerFactory不是TrustManagerFactory(Java)时

Dav*_*dge 18 java security ssl junit pkix

我正在尝试向现有的App-Server(TomCat)产品添加一些额外的JUnit测试.我遇到了(现有的和已部署的)自定义TrustManager的问题.这个东西在生产中工作正常,但在JUnit期间,给出异常.

自定义的TrustManager仅从路径加载密钥库,并隐式信任我们自己的公共证书.出于某种原因,在JUnits中使用它会导致以下行出现异常:

TrustManagerFactory tmFactory = TrustManagerFactory.getInstance("PKIX");    
Run Code Online (Sandbox Code Playgroud)

例外:

java.security.NoSuchAlgorithmException:  class configured for TrustManagerFactory: com.sun.net.ssl.internal.ssl.TrustManagerFactoryImpl$PKIXFactory not a TrustManagerFactory
Run Code Online (Sandbox Code Playgroud)

无论使用哪种提供者/算法组合("SunX509",.getDefaultAlgorithm()等),都会发生此异常.

任何见解将不胜感激.

GBa*_*GBa 43

好吧,看起来PowerMock搞砸了SSL问题,因此,你会遇到错误的工厂.解决方案是在测试类上使用注释:

@PowerMockIgnore("javax.net.ssl.*")
Run Code Online (Sandbox Code Playgroud)

这取自https://groups.google.com/forum/#!topic/powermock/v4nreP2AnOQ