27

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.

David Beveridge
  • 560
  • 1
  • 6
  • 17
  • AFAICT, Idea is using %JAVA_HOME%, which resolves to: `java version "1.6.0_23"` `Java(TM) SE Runtime Environment (build 1.6.0_23-b05)` `Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)` – David Beveridge Feb 01 '13 at 21:10
  • It looks like JUnit has somehow messed up the security providers configuration. – user207421 Feb 01 '13 at 21:39
  • If you mean the Providers, they seem OK (I can peruse them and find PKIX under both BC and SunX509, etc) . . . . which is strange. – David Beveridge Feb 01 '13 at 23:16
  • 1
    Do you by any chance have the old JSSE jar file from 1.3 days installed somewhere on the CLASSPATH where JUnit can see it but production can't? If so, remove it. – user207421 Feb 01 '13 at 23:40
  • Not as far as I can tell. Strange bit is: I moved the SSL init function into another class and the issue with the TrustManager went away. No idea of why. >_ – David Beveridge Feb 05 '13 at 20:15
  • A perfect example of ambiguous java exception messages. – Calicoder Jan 10 '21 at 08:20

1 Answers1

69

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

brasofilo
  • 25,496
  • 15
  • 91
  • 179
GBa
  • 976
  • 11
  • 16