When a TrustManagerFactory is not a TrustManagerFactory (Java)

风格不统一 提交于 2019-12-06 17:04:22

问题


I am trying to add some additional JUnit test to an existing App-Server (TomCat) product. I have run into an issue with the (existing and fielded) custom TrustManager. This thing works fine in production, but during JUnit, gives exception.

The customized TrustManager merely loads a keystore from a path, and implicitly trusts our own public certs. For some reason, using this in JUnits causes an exception on the following line:

TrustManagerFactory tmFactory = TrustManagerFactory.getInstance("PKIX");    

Exception:

java.security.NoSuchAlgorithmException:  class configured for TrustManagerFactory: com.sun.net.ssl.internal.ssl.TrustManagerFactoryImpl$PKIXFactory not a TrustManagerFactory

This exception takes place regardless of what Provider/Algorithm combinations are used ("SunX509", .getDefaultAlgorithm(), et al.).

Any insight will be greatly appreciated.


回答1:


Well, looks like PowerMock messes up with SSL issues and thus, you run into loading a wrong factory. The solution for that is to use an annotation on the test class:

@PowerMockIgnore("javax.net.ssl.*")

this is taken from https://groups.google.com/forum/#!topic/powermock/v4nreP2AnOQ



来源:https://stackoverflow.com/questions/14654639/when-a-trustmanagerfactory-is-not-a-trustmanagerfactory-java

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