Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerMock issues with ssl & StandardPBEStringEncryptor

Was trying to run the Junit tests

  1. Below is for the Password decryption using org.jasypt.encryption.pbe.StandardPBEStringEncryptor
>      Caused by: org.jasypt.exceptions.EncryptionInitializationException:
> java.security.NoSuchAlgorithmException: PBEWithMD5AndDES
> SecretKeyFactory not available
>             at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:716)
>             at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.initialize(StandardPBEStringEncryptor.java:553)
>             at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:705)
>             at com.optum.pdm.nameaddressstandardizer.PropertyFileLoader.getDecryptedValue(PropertyFileLoader.java:104)
>             ... 29 more
>         Caused by: java.security.NoSuchAlgorithmException: PBEWithMD5AndDES SecretKeyFactory not available
>             at javax.crypto.SecretKeyFactory.<init>(SecretKeyFactory.java:121)
>             at javax.crypto.SecretKeyFactory.getInstance(SecretKeyFactory.java:159)
>             at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:703)
>             ... 32 more
  1. TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
Caused by: java.security.NoSuchAlgorithmException: class configured for TrustManagerFactory: sun.security.ssl.TrustManagerFactoryImpl$PKIXFactory not a TrustManagerFactory
    at sun.security.jca.GetInstance.checkSuperClass(GetInstance.java:258)
    at sun.security.jca.GetInstance.getInstance(GetInstance.java:237)
    at sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
    at javax.net.ssl.TrustManagerFactory.getInstance(TrustManagerFactory.java:138)
    at com.optum.pdm.util.SSLConnectionHelper.getSslSocketFactory(SSLConnectionHelper.java:41)
    at com.optum.pdm.util.SSLConnectionHelper.getSSLContext(SSLConnectionHelper.java:31)
    ... 33 more
  1. When I tried with @PowerMockIgnore ("javax.crypto., javax.net.ssl.") on the Junit, It still fails with the Above Password decryption issue
  2. When I use one @PowerMockIgnore ("javax.crypto.*") on the Junit, it fails with Loading jks problem

Is there any way to fix this kind of issues

like image 739
Syed Rafi Avatar asked Sep 01 '17 04:09

Syed Rafi


People also ask

Why PowerMock is not recommended?

It can mock anything that might not be the correct way of accessing objects in Java. Still, Powermock is not recommended.

What is PowerMockIgnore?

Annotation Type PowerMockIgnoreThis annotation tells PowerMock to defer the loading of classes with the names supplied to value() to the system classloader. For example suppose you'd like to defer the loading of all classes in the org.


1 Answers

Annotation syntax correction is needed

Incorrect syntax:

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

Correct syntax that takes multiple items:

@PowerMockIgnore({"org.apache.http.conn.ssl.*", "javax.net.ssl.*" , "javax.crypto.*"})
like image 193
Syed Rafi Avatar answered Sep 23 '22 02:09

Syed Rafi