当TrustManagerFactory不是TrustManagerFactory(Java)时 [英] When a TrustManagerFactory is not a TrustManagerFactory (Java)

查看:619
本文介绍了当TrustManagerFactory不是TrustManagerFactory(Java)时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向现有的App-Server(TomCat)产品中添加一些其他JUnit测试.我遇到了(现有和已配置的)自定义TrustManager的问题.这个东西在生产中可以正常工作,但是在JUnit期间会产生异常.

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.

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

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");    

例外:

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

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

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

任何见识将不胜感激.

推荐答案

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

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.*")

此内容取自 https://groups.google.com/forum/#!topic/powermock /v4nreP2AnOQ

这篇关于当TrustManagerFactory不是TrustManagerFactory(Java)时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆