springtestingcontainershashicorp-vaultspring-vault

Vault. Spring. Unrecognized SSL message, plaintext connection/


I'm trying to run vault container in bean and use it for creating VaultTemplate bean to futher using in tests

@TestConfiguration
@TestPropertySource("classpath:application.yml")
public class TestsConfiguration {

    @Container
    public static VaultContainer vaultContainer = new VaultContainer();


    @Bean
    @Order(1)
    public VaultEndpoint vaultEndpoint() {
        vaultContainer
                .withVaultToken("00000000-0000-0000-0000-000000000000")
                .withExposedPorts(8200);
        vaultContainer.start();
        return VaultEndpoint.create(vaultContainer.getContainerIpAddress(), vaultContainer.getMappedPort(8200));
    }

    @Bean
    @Order(2)
    public VaultTemplate vaultTemplate(VaultEndpoint vaultEndpoint) {
        return new VaultTemplate(vaultEndpoint, new TokenAuthentication("00000000-0000-0000-0000-000000000000"));
    }


}

But then, when I try to write some kv via VaultOperations, I get:

I/O error on GET request for "https://localhost:32998/v1/my/secret": Unrecognized SSL message, plaintext connection?; nested exception is javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

How can I solve this problem?


Solution

  • @TestConfiguration
    @TestPropertySource("classpath:application.yml")
    public class TestsConfiguration {
    
        @Container
        public static VaultContainer vaultContainer = new VaultContainer();
    
    
        @Bean
        public VaultEndpoint vaultEndpoint() {
            vaultContainer
                    .withVaultToken("00000000-0000-0000-0000-000000000000")
                    .withExposedPorts(8200);
            vaultContainer.start();
            return VaultEndpoint.create(vaultContainer.getContainerIpAddress(), vaultContainer.getMappedPort(8200));
        }
    
        @Bean
        public VaultTemplate vaultTemplate(VaultEndpoint vaultEndpoint) {
        vaultEndpoint.setScheme("http"); ////////////// this
        return new VaultTemplate(vaultEndpoint, new TokenAuthentication("00000000-0000-0000-0000-000000000000"));
        }
    
    
    }