I am using jasypt for encrypting application.properties in a Spring Boot application. My goal is to update my integration tests so that jasypt is used with test encryptor password. My problem is that my test is not overriding the test properties.
Dependencies:
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
I have two application.properties, one in src/main/resources/application.properties and another in src/test/application-test.properties. In the test property I am setting jasypt.encryptor.password=test and I override the spring.data.mongodb.uri with the jasypt ENC value using the test password. My test looks like this:
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@SpringBootTest
@ActiveProfiles("test")
@TestPropertySource("classpath:application-test.properties")
public class SpringBootAppTest{
@Test
public void shouldLoadContext(){
//nothing to test
}
}
As you can see, I am using JUnit5 for my Spring Boot test. I've tried multiple ways of writing this test with custom test properties, but I get the same exception:
Unable to decrypt: ENC(JsHRQaQN0cuHgrq/0o ...)
The value it's the spring.data.mongodb.uri property value from src/main/resources/application.properties not the value from application-test.properties. What am I doing wrong and how can I override my "main" properties with the test properties?