This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit ccd78cbe2ee37671ee1ebc8e9564c86185adda65 Author: Andrea Cosentino <[email protected]> AuthorDate: Thu Jul 14 10:25:15 2022 +0200 CAMEL-17688 - Support ability to load properties from Vault/Secrets cloud services - Hashicorp Vault --- .../HashicorpVaultPropertiesSourceTestIT.java | 393 +++++++++++++++++++++ 1 file changed, 393 insertions(+) diff --git a/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/HashicorpVaultPropertiesSourceTestIT.java b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/HashicorpVaultPropertiesSourceTestIT.java index beacf7b95cc..1675ce2f6bd 100644 --- a/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/HashicorpVaultPropertiesSourceTestIT.java +++ b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/HashicorpVaultPropertiesSourceTestIT.java @@ -69,4 +69,397 @@ public class HashicorpVaultPropertiesSourceTestIT extends CamelTestSupport { assertMockEndpointsSatisfied(); } + + @EnabledIfEnvironmentVariable(named = "CAMEL_HASHICORP_VAULT_TOKEN_ENV", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_HASHICORP_VAULT_ENGINE_ENV", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_HASHICORP_VAULT_HOST_ENV", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_HASHICORP_VAULT_PORT_ENV", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_HASHICORP_VAULT_SCHEME_ENV", matches = ".*") + @Test + public void testComplexCustomPropertiesFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{hashicorp:hello/username}}")).to("mock:bar"); + from("direct:password").setBody(simple("{{hashicorp:hello/password}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("pippo", "pippo"); + + template.sendBody("direct:username", "Hello World"); + template.sendBody("direct:password", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testSecretNotFoundFunction() { + Exception exception = assertThrows(FailedToCreateRouteException.class, () -> { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:start").setBody(simple("{{aws:testExample}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("hello"); + + template.sendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + }); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testComplexNoSubkeyPropertiesFunction() { + Exception exception = assertThrows(FailedToCreateRouteException.class, () -> { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:database_sample/not_existent}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("admin"); + + template.sendBody("direct:username", "Hello World"); + assertMockEndpointsSatisfied(); + }); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testComplexCustomPropertiesDefaultValueFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:postgresql/additional1:admin}}")).to("mock:bar"); + from("direct:password").setBody(simple("{{aws:postgresql/additional2:secret}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret"); + + template.sendBody("direct:username", "Hello World"); + template.sendBody("direct:password", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testComplexCustomPropertiesDefaultValueExceptionFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:test-3/additional1:admin}}")).to("mock:bar"); + from("direct:password").setBody(simple("{{aws:test-3/additional2:secret}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret"); + + template.sendBody("direct:username", "Hello World"); + template.sendBody("direct:password", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testComplexCustomPropertiesExceptionFunction() { + Exception exception = assertThrows(FailedToCreateRouteException.class, () -> { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:test-3/additional1}}")).to("mock:bar"); + from("direct:password").setBody(simple("{{aws:test-3/additional2}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret"); + + template.sendBody("direct:username", "Hello World"); + template.sendBody("direct:password", "Hello World"); + assertMockEndpointsSatisfied(); + }); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testComplexSimpleDefaultValueExceptionFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:test-3:admin}}")).to("mock:bar"); + from("direct:password").setBody(simple("{{aws:test-1:secret}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret"); + + template.sendBody("direct:username", "Hello World"); + template.sendBody("direct:password", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testComplexSimpleNoDefaultValueExceptionFunction() { + Exception exception = assertThrows(FailedToCreateRouteException.class, () -> { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:secretsuper}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("admin"); + + template.sendBody("direct:username", "Hello World"); + assertMockEndpointsSatisfied(); + }); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testComplexCustomPropertiesNoDefaultValueFunction() { + Exception exception = assertThrows(FailedToCreateRouteException.class, () -> { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:postgresql/additional1}}")).to("mock:bar"); + from("direct:password").setBody(simple("{{aws:postgresql/additional2}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret"); + + template.sendBody("direct:username", "Hello World"); + template.sendBody("direct:password", "Hello World"); + assertMockEndpointsSatisfied(); + }); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testComplexCustomPropertiesNotExistentDefaultValueFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:newsecret/additional1:admin}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("admin"); + + template.sendBody("direct:username", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_USE_DEFAULT_CREDENTIALS_PROVIDER", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testComplexCustomPropertiesDefaultCredsDefaultValueFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:newsecret/additional1:admin}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("admin"); + + template.sendBody("direct:username", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testPropertiesWithDefaultFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:postgresql/username:oscerd}}")).to("mock:bar"); + from("direct:password").setBody(simple("{{aws:postgresql/password:password}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("postgres", "secret"); + + template.sendBody("direct:username", "Hello World"); + template.sendBody("direct:password", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testPropertiesWithDefaultNotExistentFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:username").setBody(simple("{{aws:db_sample/username:oscerd}}")).to("mock:bar"); + from("direct:password").setBody(simple("{{aws:db_sample/password:password}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("oscerd", "password"); + + template.sendBody("direct:username", "Hello World"); + template.sendBody("direct:password", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testPropertiesWithVersionFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:version").setBody(simple("{{aws:test/id@e8d0e680-a504-4b70-a9b2-acf5efe0ba23}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("27"); + + template.sendBody("direct:version", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testPropertiesWithVersionAndNoFieldFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:version").setBody(simple("{{aws:test@e8d0e680-a504-4b70-a9b2-acf5efe0ba23}}")).to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("{\"id\":\"27\"}"); + + template.sendBody("direct:version", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testPropertiesWithVersionNoFieldAndDefaultValueFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:version").setBody(simple("{{aws:test:pippo@e8d0e680-a504-4b70-a9b2-acf5efe0ba23}}")) + .to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("{\"id\":\"27\"}"); + + template.sendBody("direct:version", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testPropertiesWithVersionNoFieldDefaultValueNotExistentSecretFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:version").setBody(simple("{{aws:test1:pippo@e8d0e680-a504-4b70-a9b2-acf5efe0ba23}}")) + .to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("pippo"); + + template.sendBody("direct:version", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testPropertiesWithVersionNoFieldDefaultValueNotExistentVersionFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:version").setBody(simple("{{aws:test1:pippo@e8d0e680-a504-4b70-a9b2-acf5efe0ba29}}")) + .to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("pippo"); + + template.sendBody("direct:version", "Hello World"); + assertMockEndpointsSatisfied(); + } + + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_ACCESS_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_SECRET_KEY", matches = ".*") + @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_AWS_REGION", matches = ".*") + @Test + public void testPropertiesWithVersionFieldAndDefaultValueFunction() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:version").setBody(simple("{{aws:test/id:pippo@e8d0e680-a504-4b70-a9b2-acf5efe0ba23}}")) + .to("mock:bar"); + } + }); + context.start(); + + getMockEndpoint("mock:bar").expectedBodiesReceived("27"); + + template.sendBody("direct:version", "Hello World"); + assertMockEndpointsSatisfied(); + } }
