spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.96k stars 1.29k forks source link

Crypto stuff could be mocked in tests to prevent failures when there is no JCE #247

Open andsel opened 9 years ago

andsel commented 9 years ago

Hi, I've an Ubuntu 15.04 and run with JVM Oracle JDK 1.8.60 and I got the followinf excpetion in mvn clean test

Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.13 sec <<< FAILURE! - in org.springframework.cloud.config.server.encryption.EncryptionControllerMultiTextEncryptorTests
shouldEncryptUsingApplicationAndProfiles(org.springframework.cloud.config.server.encryption.EncryptionControllerMultiTextEncryptorTests)  Time elapsed: 0.13 sec  <<< ERROR!
java.lang.IllegalArgumentException: Unable to initialize due to invalid secret key
    at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1024)
    at javax.crypto.Cipher.implInit(Cipher.java:790)
    at javax.crypto.Cipher.chooseProvider(Cipher.java:849)
    at javax.crypto.Cipher.init(Cipher.java:1348)
    at javax.crypto.Cipher.init(Cipher.java:1282)
    at org.springframework.security.crypto.encrypt.CipherUtils.initCipher(CipherUtils.java:113)
    at org.springframework.security.crypto.encrypt.AesBytesEncryptor.encrypt(AesBytesEncryptor.java:115)
    at org.springframework.security.crypto.encrypt.HexEncodingTextEncryptor.encrypt(HexEncodingTextEncryptor.java:36)
    at org.springframework.cloud.config.server.encryption.EncryptionController.checkEncryptorInstalled(EncryptionController.java:169)
    at org.springframework.cloud.config.server.encryption.EncryptionController.encrypt(EncryptionController.java:127)
    at org.springframework.cloud.config.server.encryption.EncryptionControllerMultiTextEncryptorTests.shouldEncryptUsingApplicationAndProfiles(EncryptionControllerMultiTextEncryptorTests.java:30)

with maven results as:

Results :

Tests in error: 
  EncryptionControllerMultiTextEncryptorTests.shouldEncryptUsingApplicationAndProfiles:30 » IllegalArgument
  EncryptionControllerTests.appAndProfile:70 » IllegalArgument Unable to initial...
  EncryptionControllerTests.sunnyDayRsaKey:53 » IllegalArgument Unable to initia...
  EncryptionControllerTests.formDataIn:82 » IllegalArgument Unable to initialize...
  EncryptionControllerTests.addEnvironment:114 » IllegalArgument Unable to initi...
  EncryptionControllerTests.formDataInWithPrefix:94 » IllegalArgument Unable to ...
  KeyStoreTextEncryptorLocatorTests.testDifferentKeyDefaultSecret:60 » IllegalArgument
  KeyStoreTextEncryptorLocatorTests.testDifferentKeyAndSecret:69 » IllegalArgument
  KeyStoreTextEncryptorLocatorTests.testDefaults:44 » IllegalArgument Unable to ...
  CipherEnvironmentEncryptorTests.shouldDecryptEnvironment:48 » IllegalArgument ...
  CipherEnvironmentEncryptorTests.shouldDecryptEnvironmentWithKey:62 » IllegalArgument

Tests run: 119, Failures: 0, Errors: 11, Skipped: 0

What can should I try to fix it?

Thanks Andrea

spencergibb commented 9 years ago

./mvnw clean install works for me. Do you have the JCE installed?

dsyer commented 9 years ago

JCE probably. But it shouldn't be necessary for these tests (we don't have any crypto in this project, we just use bits from other projects that do it), so could be we can work around it by mocking the TextEncryptor. Doesn't help anyone who wants to use it I guess.

andsel commented 9 years ago

Hi @spencergibb and @dsyer it' JCE not installed and required by a Spring Crypto. The idea of mocking it in test sounds good, so if you want I can try create PR that fix and send it in next days.

Andrea