diff --git a/.gitignore b/.gitignore index 5d69a553e4d..513921af691 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ target *.ipr *.iws .idea +.dccache .DS_Store .classpath .ekstazi diff --git a/.snyk b/.snyk new file mode 100644 index 00000000000..cc61c4dc110 --- /dev/null +++ b/.snyk @@ -0,0 +1,4 @@ +exclude: + global: + - "*IT.java" + - "*Test.java" diff --git a/components-starter/camel-ftp-starter/src/test/java/org/apache/camel/component/file/remote/springboot/ftp/FtpEmbeddedService.java b/components-starter/camel-ftp-starter/src/test/java/org/apache/camel/component/file/remote/springboot/ftp/FtpEmbeddedService.java index 3c76c9331fe..d4650956556 100644 --- a/components-starter/camel-ftp-starter/src/test/java/org/apache/camel/component/file/remote/springboot/ftp/FtpEmbeddedService.java +++ b/components-starter/camel-ftp-starter/src/test/java/org/apache/camel/component/file/remote/springboot/ftp/FtpEmbeddedService.java @@ -38,10 +38,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.function.BiConsumer; @@ -94,6 +96,12 @@ protected void createUser(UserManager userMgr, String name, String password, Pat } } + private static Properties loadAuthProperties() throws IOException { + Properties properties = new Properties(); + properties.load(FtpEmbeddedService.class.getClassLoader().getResourceAsStream("users.properties")); + return properties; + } + protected FtpServerFactory createFtpServerFactory() { NativeFileSystemFactory fsf = new NativeFileSystemFactory(); fsf.setCreateHome(true); @@ -103,13 +111,17 @@ protected FtpServerFactory createFtpServerFactory() { pumf.setPasswordEncryptor(new ClearTextPasswordEncryptor()); pumf.setFile(null); UserManager userMgr = pumf.createUserManager(); - createUser(userMgr, "admin", "admin", rootDir, true); - createUser(userMgr, "scott", "tiger", rootDir, true); - createUser(userMgr, "dummy", "foo", rootDir, false); - createUser(userMgr, "us@r", "t%st", rootDir, true); + Properties users; + try { + users = loadAuthProperties(); + } catch (IOException ioe) { + throw new IllegalStateException(ioe); + } + for (String username : users.stringPropertyNames()) { + createUser(userMgr, username, users.getProperty(username), rootDir, true); + } createUser(userMgr, "anonymous", null, rootDir, false); - createUser(userMgr, "joe", "p+%w0&r)d", rootDir, true); - createUser(userMgr, "jane", "%j#7%c6i", rootDir, true); + createUser(userMgr, "dummy", "foo", rootDir, false); ListenerFactory factory = new ListenerFactory(); factory.setPort(port); diff --git a/components-starter/camel-ftp-starter/src/test/resources/users.properties b/components-starter/camel-ftp-starter/src/test/resources/users.properties new file mode 100644 index 00000000000..022bcefedbc --- /dev/null +++ b/components-starter/camel-ftp-starter/src/test/resources/users.properties @@ -0,0 +1,5 @@ +admin=admin +scott=tiger +us@r=t%st +joe=p+%w0&r)d +jane=%j#7%c6i \ No newline at end of file diff --git a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/AbstractEncryptedPropertiesIvGeneratorAutoDetectionTest.java b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/AbstractEncryptedPropertiesIvGeneratorAutoDetectionTest.java index 64458ecdc1b..7a20c73717c 100644 --- a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/AbstractEncryptedPropertiesIvGeneratorAutoDetectionTest.java +++ b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/AbstractEncryptedPropertiesIvGeneratorAutoDetectionTest.java @@ -27,7 +27,9 @@ import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.PrintStream; +import java.util.Properties; import static org.apache.camel.component.jasypt.springboot.JasyptEncryptedPropertiesUtils.isIVNeeded; import static org.assertj.core.api.Assertions.assertThat; @@ -41,18 +43,24 @@ public abstract class AbstractEncryptedPropertiesIvGeneratorAutoDetectionTest { String stringToEncrypt = "A password-cracker walks into a bar. Orders a beer. Then a Beer. Then a BEER. beer. b33r. BeeR. Be3r. bEeR. bE3R. BeEr"; - String password = "s0m3R@nD0mP@ssW0rD"; - - + //String password = "s0m3R@nD0mP@ssW0rD"; protected String provider; + public static Properties loadAuthProperties() throws IOException { + Properties properties = new Properties(); + properties.load(AbstractEncryptedPropertiesIvGeneratorAutoDetectionTest.class.getClassLoader().getResourceAsStream("test.properties")); + return properties; + } + @ParameterizedTest @MethodSource("data") - public void testEncryptionAndDecryption(String algorithm) { + public void testEncryptionAndDecryption(String algorithm) throws IOException { LOG.info("Testing Algorithm: '{}', requires IV: {}", algorithm, isIVNeeded(algorithm)); + Properties properties = loadAuthProperties(); + // Create a ByteArrayOutputStream so that we can get the output // from the call to print ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -64,7 +72,7 @@ public void testEncryptionAndDecryption(String algorithm) { environmentStringPBEConfig.setIvGenerator(isIVNeeded(algorithm)?new RandomIvGenerator():new NoIvGenerator()); environmentStringPBEConfig.setSaltGenerator(new RandomSaltGenerator()); environmentStringPBEConfig.setProviderName(provider); - environmentStringPBEConfig.setPassword(password); + environmentStringPBEConfig.setPassword(properties.getProperty("password")); StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); standardPBEStringEncryptor.setConfig(environmentStringPBEConfig); diff --git a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesCustomConfigurationBeansTest.java b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesCustomConfigurationBeansTest.java index ccfe835dc28..5250527c6c1 100644 --- a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesCustomConfigurationBeansTest.java +++ b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesCustomConfigurationBeansTest.java @@ -16,6 +16,9 @@ */ package org.apache.camel.component.jasypt.springboot; +import java.io.IOException; +import java.util.Properties; + import org.apache.camel.spring.boot.CamelAutoConfiguration; import org.apache.camel.test.spring.junit5.CamelSpringBootTest; import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; @@ -38,9 +41,13 @@ @SpringBootTest( classes = {EncryptedPropertiesCustomConfigurationBeansTest.TestConfiguration.class}, properties = {"encrypted.password=ENC(6q7H+bWqPbSZVW1hUzDVgnl7iSnC04zRmKwD31ounBMPM/2CtDS7fwb4u1OGZ2Q4)"}) -public class EncryptedPropertiesCustomConfigurationBeansTest extends EncryptedProperiesTestBase { - +public class EncryptedPropertiesCustomConfigurationBeansTest extends EncryptedPropertiesTestBase { + public static Properties loadAuthProperties() throws IOException { + Properties properties = new Properties(); + properties.load(EncryptedPropertiesCustomConfigurationBeansTest.class.getClassLoader().getResourceAsStream("test.properties")); + return properties; + } @Test public void testCustomEnvironmentVariablesConfiguration() { @@ -68,12 +75,14 @@ private String getSecureRandomAlgorithm() { } @Bean("customEnvironmentStringPBEConfig") - public EnvironmentStringPBEConfig environmentVariablesConfiguration() { + public EnvironmentStringPBEConfig environmentVariablesConfiguration() throws IOException { + Properties props = loadAuthProperties(); + EnvironmentStringPBEConfig environmentStringPBEConfig = new EnvironmentStringPBEConfig(); environmentStringPBEConfig.setAlgorithm("PBEWITHHMACSHA512ANDAES_256"); environmentStringPBEConfig.setIvGenerator(new RandomIvGenerator(getSecureRandomAlgorithm())); environmentStringPBEConfig.setSaltGenerator(new RandomSaltGenerator(getSecureRandomAlgorithm())); - environmentStringPBEConfig.setPassword("mainpassword"); + environmentStringPBEConfig.setPassword(props.getProperty("mainpassword")); return environmentStringPBEConfig; } diff --git a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesDisabledCustomConfigurationBeansTest.java b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesDisabledCustomConfigurationBeansTest.java index b4157f14897..eea078e55f9 100644 --- a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesDisabledCustomConfigurationBeansTest.java +++ b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesDisabledCustomConfigurationBeansTest.java @@ -36,7 +36,7 @@ properties = { "camel.component.jasypt.enabled = false", "encrypted.password=ENC(6q7H+bWqPbSZVW1hUzDVgnl7iSnC04zRmKwD31ounBMPM/2CtDS7fwb4u1OGZ2Q4)"}) -public class EncryptedPropertiesDisabledCustomConfigurationBeansTest extends EncryptedProperiesTestBase { +public class EncryptedPropertiesDisabledCustomConfigurationBeansTest extends EncryptedPropertiesTestBase { @Test public void testCustomEnvironmentVariablesConfiguration() { diff --git a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesDisabledTest.java b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesDisabledTest.java index 1ab7aee5451..af7fe190805 100644 --- a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesDisabledTest.java +++ b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesDisabledTest.java @@ -34,7 +34,7 @@ @SpringBootTest( properties = {"camel.component.jasypt.enabled = false"}, classes = {EncryptedPropertiesCustomConfigurationBeansTest.TestConfiguration.class}) -public class EncryptedPropertiesDisabledTest extends EncryptedProperiesTestBase{ +public class EncryptedPropertiesDisabledTest extends EncryptedPropertiesTestBase{ /** diff --git a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesTest.java b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesTest.java index e4d696115cf..21231f584e1 100644 --- a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesTest.java +++ b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesTest.java @@ -35,7 +35,7 @@ @DirtiesContext @SpringBootApplication @SpringBootTest(classes = {EncryptedPropertiesTest.TestConfiguration.class}) -public class EncryptedPropertiesTest extends EncryptedProperiesTestBase { +public class EncryptedPropertiesTest extends EncryptedPropertiesTestBase { @Test public void testEncryptionInsideCamelContext() { diff --git a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedProperiesTestBase.java b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesTestBase.java similarity index 97% rename from components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedProperiesTestBase.java rename to components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesTestBase.java index e921d29af3e..0d9f19388d7 100644 --- a/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedProperiesTestBase.java +++ b/components-starter/camel-jasypt-starter/src/test/java/org/apache/camel/component/jasypt/springboot/EncryptedPropertiesTestBase.java @@ -30,7 +30,7 @@ import static org.apache.camel.component.jasypt.springboot.Constants.START_URI_TEST_UNENCRYPTED_PROPS_OUT_CC; import static org.junit.jupiter.api.Assertions.assertEquals; -public abstract class EncryptedProperiesTestBase { +public abstract class EncryptedPropertiesTestBase { @EndpointInject(MOCK_URI) diff --git a/components-starter/camel-jasypt-starter/src/test/resources/test.properties b/components-starter/camel-jasypt-starter/src/test/resources/test.properties new file mode 100644 index 00000000000..8b7f453b095 --- /dev/null +++ b/components-starter/camel-jasypt-starter/src/test/resources/test.properties @@ -0,0 +1,2 @@ +password=s0m3R@nD0mP@ssW0rD +mainpassword=mainpassword \ No newline at end of file diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddCommentProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddCommentProducerTest.java index 80b8dd8ddad..5de7a9cd2de 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddCommentProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddCommentProducerTest.java @@ -19,7 +19,6 @@ import static org.apache.camel.component.jira.JiraConstants.ISSUE_KEY; import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.Utils.createIssueWithComments; import static org.apache.camel.component.jira.springboot.test.Utils.newComment; import static org.mockito.ArgumentMatchers.any; @@ -27,6 +26,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -151,16 +151,14 @@ public void verifyLastComment() throws InterruptedException { @Configuration public class TestConfiguration { - - @Bean public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { + public void configure() throws IOException { comment = "A new test comment " + new Date(); from("direct:start") - .to("jira://addComment?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://addComment?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddIssueLinkProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddIssueLinkProducerTest.java index 4a6d4576454..1ff95a27cd4 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddIssueLinkProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddIssueLinkProducerTest.java @@ -21,7 +21,6 @@ import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; import static org.apache.camel.component.jira.JiraConstants.LINK_TYPE; import static org.apache.camel.component.jira.JiraConstants.PARENT_ISSUE_KEY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.Utils.createIssue; import static org.apache.camel.component.jira.springboot.test.Utils.createIssueWithLinks; import static org.apache.camel.component.jira.springboot.test.Utils.newIssueLink; @@ -32,6 +31,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -254,9 +254,9 @@ public class TestConfiguration { public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { + public void configure() throws IOException { from("direct:start") - .to("jira://addIssueLink?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://addIssueLink?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddIssueProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddIssueProducerTest.java index b7449d3f214..7ab35b07b1a 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddIssueProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddIssueProducerTest.java @@ -25,7 +25,6 @@ import static org.apache.camel.component.jira.JiraConstants.ISSUE_TYPE_ID; import static org.apache.camel.component.jira.JiraConstants.ISSUE_TYPE_NAME; import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.KEY; import static org.apache.camel.component.jira.springboot.test.Utils.createIssue; import static org.apache.camel.component.jira.springboot.test.Utils.userAssignee; @@ -33,6 +32,7 @@ import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; +import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -222,9 +222,9 @@ public class TestConfiguration { public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { + public void configure() throws IOException { from("direct:start") - .to("jira://addIssue?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://addIssue?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddWorkLogProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddWorkLogProducerTest.java index 1191736bc83..54d8cae99d0 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddWorkLogProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AddWorkLogProducerTest.java @@ -23,7 +23,6 @@ import static org.apache.camel.component.jira.springboot.test.Utils.createIssueWithComments; import static org.apache.camel.component.jira.springboot.test.Utils.createIssueWithWorkLogs; import static org.apache.camel.component.jira.springboot.test.Utils.newWorkLog; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.lenient; @@ -236,7 +235,7 @@ public RouteBuilder routeBuilder() { @Override public void configure() throws Exception { from("direct:start") - .to("jira://addWorkLog?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://addWorkLog?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AttachFileProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AttachFileProducerTest.java index 7b15884fe87..2d0e6682b7b 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AttachFileProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/AttachFileProducerTest.java @@ -19,7 +19,6 @@ import static org.apache.camel.component.jira.JiraConstants.ISSUE_KEY; import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.KEY; import static org.apache.camel.component.jira.springboot.test.Utils.createIssue; import static org.apache.camel.component.jira.springboot.test.Utils.createIssueWithAttachment; @@ -178,10 +177,10 @@ public class TestConfiguration { public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { + public void configure() throws IOException { from("direct:start") .setHeader(ISSUE_KEY, () -> KEY + "-1") - .to("jira://attach?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://attach?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/DeleteIssueProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/DeleteIssueProducerTest.java index d4c5a6df376..83a99f9227d 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/DeleteIssueProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/DeleteIssueProducerTest.java @@ -19,7 +19,6 @@ import static org.apache.camel.component.jira.JiraConstants.ISSUE_KEY; import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.KEY; import static org.apache.camel.component.jira.springboot.test.Utils.createIssue; import static org.mockito.ArgumentMatchers.any; @@ -148,7 +147,7 @@ public RouteBuilder routeBuilder() { public void configure() throws IOException { from("direct:start") .setHeader(ISSUE_KEY, () -> KEY + "-1") - .to("jira://deleteIssue?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://deleteIssue?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/FetchCommentsProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/FetchCommentsProducerTest.java index 8fa90852527..d5514616ccb 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/FetchCommentsProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/FetchCommentsProducerTest.java @@ -19,7 +19,6 @@ import static org.apache.camel.component.jira.JiraConstants.ISSUE_KEY; import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; @@ -27,6 +26,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.io.IOException; import com.atlassian.jira.rest.client.api.IssueRestClient; import com.atlassian.jira.rest.client.api.JiraRestClient; @@ -160,9 +160,9 @@ public class TestConfiguration { public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { + public void configure() throws IOException { from("direct:start") - .to("jira://fetchComments?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://fetchComments?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/FetchIssueProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/FetchIssueProducerTest.java index 7e717712bc3..8e241c1da77 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/FetchIssueProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/FetchIssueProducerTest.java @@ -19,7 +19,6 @@ import static org.apache.camel.component.jira.JiraConstants.ISSUE_KEY; import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; @@ -159,7 +158,7 @@ public RouteBuilder routeBuilder() { @Override public void configure() throws Exception { from("direct:start") - .to("jira://fetchIssue?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://fetchIssue?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/JiraTestConstants.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/JiraTestConstants.java index a21e135d381..c554d9f529e 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/JiraTestConstants.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/JiraTestConstants.java @@ -16,13 +16,24 @@ */ package org.apache.camel.component.jira.springboot.test; -public interface JiraTestConstants { +import java.io.IOException; +import java.util.Properties; - String KEY = "TST"; - String TEST_JIRA_URL = "https://somerepo.atlassian.net"; - String PROJECT = "TST"; - String USERNAME = "someguy"; - String PASSWORD = "my_password"; - String JIRA_CREDENTIALS = TEST_JIRA_URL + "&username=" + USERNAME + "&password=" + PASSWORD; - String WATCHED_COMPONENTS = "Priority,Status,Resolution"; +public class JiraTestConstants { + + static String KEY = "TST"; + static String TEST_JIRA_URL = "https://somerepo.atlassian.net"; + static String PROJECT = "TST"; + static String WATCHED_COMPONENTS = "Priority,Status,Resolution"; + + private static Properties loadAuthProperties() throws IOException { + Properties properties = new Properties(); + properties.load(JiraTestConstants.class.getClassLoader().getResourceAsStream("jiraauth.properties")); + return properties; + } + + public static String getJiraCredentials() throws IOException { + Properties props = loadAuthProperties(); + return TEST_JIRA_URL + "&username=" + props.getProperty("username") + "&password=" + props.getProperty("password"); + } } diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/NewCommentsConsumerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/NewCommentsConsumerTest.java index a814c2fdb41..f85c160f384 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/NewCommentsConsumerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/NewCommentsConsumerTest.java @@ -20,7 +20,6 @@ import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; import static org.apache.camel.component.jira.springboot.test.Utils.createIssueWithComments; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.PROJECT; import static org.apache.camel.component.jira.springboot.test.Utils.createIssue; import static org.mockito.ArgumentMatchers.any; @@ -29,6 +28,7 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -220,8 +220,8 @@ public class TestConfiguration { public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { - from("jira://newComments?jiraUrl=" + JIRA_CREDENTIALS + "&jql=project=" + PROJECT + "&delay=1000") + public void configure() throws IOException { + from("jira://newComments?jiraUrl=" + JiraTestConstants.getJiraCredentials() + "&jql=project=" + PROJECT + "&delay=1000") .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/NewIssuesConsumerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/NewIssuesConsumerTest.java index 69acd3bac3b..425720d1372 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/NewIssuesConsumerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/NewIssuesConsumerTest.java @@ -18,7 +18,6 @@ import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.PROJECT; import static org.apache.camel.component.jira.springboot.test.Utils.createIssue; import static org.mockito.ArgumentMatchers.any; @@ -26,6 +25,7 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -189,8 +189,8 @@ public class TestConfiguration { public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { - from("jira://newIssues?jiraUrl=" + JIRA_CREDENTIALS + "&jql=project=" + PROJECT + "&delay=5000") + public void configure() throws IOException { + from("jira://newIssues?jiraUrl=" + JiraTestConstants.getJiraCredentials() + "&jql=project=" + PROJECT + "&delay=5000") .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/TransitionIssueProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/TransitionIssueProducerTest.java index 71e092ea91b..4b51ec79531 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/TransitionIssueProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/TransitionIssueProducerTest.java @@ -23,7 +23,6 @@ import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.TEST_JIRA_URL; import static org.apache.camel.component.jira.springboot.test.Utils.createIssue; import static org.apache.camel.component.jira.springboot.test.Utils.transitionIssueDone; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.KEY; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.lenient; @@ -158,7 +157,7 @@ public void configure() throws IOException { from("direct:start") .setHeader(ISSUE_KEY, () -> KEY + "-1") .setHeader(ISSUE_TRANSITION_ID, () -> 31) - .to("jira://transitionIssue?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://transitionIssue?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/UpdateIssueProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/UpdateIssueProducerTest.java index ae736ff7212..0069d21151c 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/UpdateIssueProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/UpdateIssueProducerTest.java @@ -23,7 +23,6 @@ import static org.apache.camel.component.jira.JiraConstants.ISSUE_SUMMARY; import static org.apache.camel.component.jira.JiraConstants.ISSUE_TYPE_NAME; import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.Utils.createIssue; import static org.apache.camel.component.jira.springboot.test.Utils.userAssignee; @@ -32,6 +31,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -199,9 +199,9 @@ public class TestConfiguration { public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { + public void configure() throws IOException { from("direct:start") - .to("jira://updateIssue?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://updateIssue?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/WatchUpdatesConsumerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/WatchUpdatesConsumerTest.java index cdb6a7045c0..b55b1ab0573 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/WatchUpdatesConsumerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/WatchUpdatesConsumerTest.java @@ -18,7 +18,6 @@ import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.PROJECT; import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.WATCHED_COMPONENTS; import static org.apache.camel.component.jira.springboot.test.Utils.createIssue; @@ -29,6 +28,7 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -203,8 +203,8 @@ public class TestConfiguration { public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { - from("jira://watchUpdates?jiraUrl=" + JIRA_CREDENTIALS + public void configure() throws IOException { + from("jira://watchUpdates?jiraUrl=" + JiraTestConstants.getJiraCredentials() + "&jql=project=" + PROJECT + "&delay=5000&watchedFields=" + WATCHED_COMPONENTS) .to(mockResult); } diff --git a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/WatcherProducerTest.java b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/WatcherProducerTest.java index 5fe8fc45c78..a599a90cb82 100644 --- a/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/WatcherProducerTest.java +++ b/components-starter/camel-jira-starter/src/test/java/org/apache/camel/component/jira/springboot/test/WatcherProducerTest.java @@ -21,7 +21,6 @@ import static org.apache.camel.component.jira.JiraConstants.ISSUE_WATCHERS_ADD; import static org.apache.camel.component.jira.JiraConstants.ISSUE_WATCHERS_REMOVE; import static org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FACTORY; -import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.JIRA_CREDENTIALS; import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.KEY; import static org.apache.camel.component.jira.springboot.test.JiraTestConstants.TEST_JIRA_URL; import static org.apache.camel.component.jira.springboot.test.Utils.createIssue; @@ -30,6 +29,7 @@ import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; +import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.Collection; @@ -247,9 +247,9 @@ public class TestConfiguration { public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { + public void configure() throws IOException { from("direct:start") - .to("jira://watchers?jiraUrl=" + JIRA_CREDENTIALS) + .to("jira://watchers?jiraUrl=" + JiraTestConstants.getJiraCredentials()) .to(mockResult); } }; diff --git a/components-starter/camel-jira-starter/src/test/resources/jiraauth.properties b/components-starter/camel-jira-starter/src/test/resources/jiraauth.properties new file mode 100644 index 00000000000..5222ad7edd6 --- /dev/null +++ b/components-starter/camel-jira-starter/src/test/resources/jiraauth.properties @@ -0,0 +1,3 @@ +username=someguy +password=my_password + diff --git a/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/integration/AbstractMongoDbITSupport.java b/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/integration/AbstractMongoDbITSupport.java index 46ac9aa4090..d4c3585e0ea 100644 --- a/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/integration/AbstractMongoDbITSupport.java +++ b/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/integration/AbstractMongoDbITSupport.java @@ -46,15 +46,15 @@ import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; +import java.io.IOException; import java.util.Formatter; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Properties; public abstract class AbstractMongoDbITSupport { protected static final String SCHEME = "mongodb"; - protected static final String USER = "test-user"; - protected static final String PASSWORD = "test-pwd"; @RegisterExtension public static MongoDBService service = MongoDBServiceFactory.createService(); protected static MongoClient mongo; @@ -101,11 +101,18 @@ public void tearDown() throws Exception { dynamicCollection.drop(); } + public static Properties loadAuthProperties() throws IOException { + Properties properties = new Properties(); + properties.load(AbstractMongoDbITSupport.class.getClassLoader().getResourceAsStream("test.properties")); + return properties; + } + /** * Useful to simulate the presence of an authenticated user with name {@value #USER} and password {@value #PASSWORD} */ - protected void createAuthorizationUser() { - createAuthorizationUser("admin", USER, PASSWORD); + protected void createAuthorizationUser() throws IOException { + Properties properties = loadAuthProperties(); + createAuthorizationUser("admin", properties.getProperty("testusername"), properties.getProperty("testpassword")); } protected void createAuthorizationUser(String database, String user, String password) { diff --git a/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/integration/MongoDbCredentialsFromUriConnectionIT.java b/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/integration/MongoDbCredentialsFromUriConnectionIT.java index be5f1a86e83..62099d12d8a 100644 --- a/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/integration/MongoDbCredentialsFromUriConnectionIT.java +++ b/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/integration/MongoDbCredentialsFromUriConnectionIT.java @@ -17,6 +17,9 @@ package org.apache.camel.component.mongodb.integration; +import java.io.IOException; +import java.util.Properties; + import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mongodb.MongoDbConstants; @@ -49,9 +52,6 @@ ) public class MongoDbCredentialsFromUriConnectionIT extends MongoDbOperationsIT { - protected static final String AUTH_SOURCE_USER = "auth-source-user"; - protected static final String AUTH_SOURCE_PASSWORD = "auth-source-password"; - @Configuration public class TestConfiguration { @@ -59,14 +59,15 @@ public class TestConfiguration { public RouteBuilder routeBuilder() { return new RouteBuilder() { @Override - public void configure() { + public void configure() throws IOException { + Properties properties = loadAuthProperties(); String uriHostnameOnly = String.format("mongodb:mongo?hosts=%s&", service.getConnectionAddress()); //connecting with credentials for created user - String uriWithCredentials = String.format("%susername=%s&password=%s&", uriHostnameOnly, USER, PASSWORD); + String uriWithCredentials = String.format("%susername=%s&password=%s&", uriHostnameOnly, properties.getProperty("testusername"), properties.getProperty("testpassword")); String uriWithAuthSource = String.format( "%susername=%s&password=%s&authSource=%s&", - uriHostnameOnly, AUTH_SOURCE_USER, AUTH_SOURCE_PASSWORD, dbName); + uriHostnameOnly, properties.getProperty("authsourceusername"), properties.getProperty("authsourceuserpassword"), dbName); from("direct:count").to( uriHostnameOnly + "database={{mongodb.testDb}}&collection={{mongodb.testCollection}}&operation=count&dynamicity=true"); @@ -107,9 +108,10 @@ public void configure() { } @BeforeEach - public void before() { + public void before() throws IOException { + Properties properties = loadAuthProperties(); createAuthorizationUser(); - createAuthorizationUser(dbName, AUTH_SOURCE_USER, AUTH_SOURCE_PASSWORD); + createAuthorizationUser(dbName, properties.getProperty("authsourceusername"), properties.getProperty("authsourcepassword")); } @Test diff --git a/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/meta/integration/MongoDbMetaExtensionIT.java b/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/meta/integration/MongoDbMetaExtensionIT.java index d21e4665a9b..8db5016e616 100644 --- a/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/meta/integration/MongoDbMetaExtensionIT.java +++ b/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/meta/integration/MongoDbMetaExtensionIT.java @@ -16,9 +16,11 @@ */ package org.apache.camel.component.mongodb.meta.integration; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.Properties; import com.fasterxml.jackson.databind.JsonNode; import com.mongodb.client.model.CreateCollectionOptions; @@ -54,7 +56,7 @@ public class MongoDbMetaExtensionIT extends AbstractMongoDbITSupport { // We simulate the presence of an authenticated user @BeforeEach - public void createAuthorizationUser() { + public void createAuthorizationUser() throws IOException { super.createAuthorizationUser(); } @@ -63,7 +65,8 @@ protected MongoDbComponent getComponent() { } @Test - public void testValidMetaData() { + public void testValidMetaData() throws IOException { + Properties properties = loadAuthProperties(); // When final String database = "test"; final String collection = "validatedCollection"; @@ -99,8 +102,8 @@ public void testValidMetaData() { parameters.put("database", database); parameters.put("collection", collection); parameters.put("host", service.getConnectionAddress()); - parameters.put("user", USER); - parameters.put("password", PASSWORD); + parameters.put("user", properties.getProperty("testusername")); + parameters.put("password", properties.getProperty("testpassword")); MetaDataExtension.MetaData result = component.getExtension(MetaDataExtension.class).get().meta(parameters) .orElseThrow(UnsupportedOperationException::new); @@ -116,7 +119,9 @@ public void testValidMetaData() { } @Test - public void testMissingCollection() { + public void testMissingCollection() throws IOException { + Properties properties = loadAuthProperties(); + // When final String database = "test"; final String collection = "missingCollection"; @@ -126,8 +131,8 @@ public void testMissingCollection() { parameters.put("database", database); parameters.put("collection", collection); parameters.put("host", service.getConnectionAddress()); - parameters.put("user", USER); - parameters.put("password", PASSWORD); + parameters.put("user", properties.getProperty("testusername")); + parameters.put("password", properties.getProperty("testpassword")); final Optional meta = component.getExtension(MetaDataExtension.class).get().meta(parameters); @@ -150,7 +155,8 @@ public void testMissingParameters() { } @Test - public void testNotValidatedCollection() { + public void testNotValidatedCollection() throws IOException { + Properties properties = loadAuthProperties(); // When final String database = "test"; final String collection = "notValidatedCollection"; @@ -161,8 +167,8 @@ public void testNotValidatedCollection() { parameters.put("database", database); parameters.put("collection", collection); parameters.put("host", service.getConnectionAddress()); - parameters.put("user", USER); - parameters.put("password", PASSWORD); + parameters.put("user", properties.getProperty("testusername")); + parameters.put("password", properties.getProperty("testpassword")); final Optional meta = component.getExtension(MetaDataExtension.class).get().meta(parameters); diff --git a/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/verifier/integration/MongoDbVerifierExtensionIT.java b/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/verifier/integration/MongoDbVerifierExtensionIT.java index 2e543dc6018..bb9d525f869 100644 --- a/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/verifier/integration/MongoDbVerifierExtensionIT.java +++ b/components-starter/camel-mongodb-starter/src/test/java/org/apache/camel/component/mongodb/verifier/integration/MongoDbVerifierExtensionIT.java @@ -16,8 +16,10 @@ */ package org.apache.camel.component.mongodb.verifier.integration; +import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.Properties; import org.apache.camel.Component; import org.apache.camel.component.extension.ComponentVerifierExtension; @@ -47,7 +49,7 @@ public class MongoDbVerifierExtensionIT extends AbstractMongoDbITSupport { // We simulate the presence of an authenticated user @BeforeEach - public void createAuthorizationUser() { + public void createAuthorizationUser() throws IOException { super.createAuthorizationUser(); } @@ -60,12 +62,13 @@ protected ComponentVerifierExtension getExtension() { } @Test - public void verifyConnectionOK() { + public void verifyConnectionOK() throws IOException { + Properties properties = loadAuthProperties(); //When Map parameters = new HashMap<>(); parameters.put("host", service.getConnectionAddress()); - parameters.put("user", USER); - parameters.put("password", PASSWORD); + parameters.put("user", properties.getProperty("testusername")); + parameters.put("password", properties.getProperty("testpassword")); //Given ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters); @@ -74,12 +77,13 @@ public void verifyConnectionOK() { } @Test - public void verifyConnectionKO() { + public void verifyConnectionKO() throws IOException { + Properties properties = loadAuthProperties(); //When Map parameters = new HashMap<>(); parameters.put("host", "notReachable.host"); - parameters.put("user", USER); - parameters.put("password", PASSWORD); + parameters.put("user", properties.getProperty("testusername")); + parameters.put("password", properties.getProperty("testpassword")); //Given ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters); @@ -89,11 +93,13 @@ public void verifyConnectionKO() { } @Test - public void verifyConnectionMissingParams() { + public void verifyConnectionMissingParams() throws IOException { + Properties properties = loadAuthProperties(); + //When Map parameters = new HashMap<>(); parameters.put("host", service.getConnectionAddress()); - parameters.put("user", USER); + parameters.put("user", properties.getProperty("testusername")); //Given ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.PARAMETERS, parameters); @@ -103,12 +109,14 @@ public void verifyConnectionMissingParams() { } @Test - public void verifyConnectionNotAuthenticated() { + public void verifyConnectionNotAuthenticated() throws IOException { + Properties properties = loadAuthProperties(); + //When Map parameters = new HashMap<>(); parameters.put("host", service.getConnectionAddress()); - parameters.put("user", USER); - parameters.put("password", "wrongPassword"); + parameters.put("user", properties.getProperty("wrongusername")); + parameters.put("password", properties.getProperty("wrongpassword")); //Given ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters); @@ -118,12 +126,14 @@ public void verifyConnectionNotAuthenticated() { } @Test - public void verifyConnectionAdminDBKO() { + public void verifyConnectionAdminDBKO() throws IOException { + Properties properties = loadAuthProperties(); + //When Map parameters = new HashMap<>(); parameters.put("host", service.getConnectionAddress()); - parameters.put("user", USER); - parameters.put("password", PASSWORD); + parameters.put("user", properties.getProperty("testusername")); + parameters.put("password", properties.getProperty("testpassword")); parameters.put("adminDB", "someAdminDB"); //Given ComponentVerifierExtension.Result result @@ -134,12 +144,14 @@ public void verifyConnectionAdminDBKO() { } @Test - public void verifyConnectionPortKO() { + public void verifyConnectionPortKO() throws IOException { + Properties properties = loadAuthProperties(); + //When Map parameters = new HashMap<>(); parameters.put("host", "localhost:12343"); - parameters.put("user", USER); - parameters.put("password", PASSWORD); + parameters.put("user", properties.getProperty("testusername")); + parameters.put("password", properties.getProperty("testpassword")); //Given ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters); diff --git a/components-starter/camel-mongodb-starter/src/test/resources/test.properties b/components-starter/camel-mongodb-starter/src/test/resources/test.properties new file mode 100644 index 00000000000..c8b7390f690 --- /dev/null +++ b/components-starter/camel-mongodb-starter/src/test/resources/test.properties @@ -0,0 +1,11 @@ +testusername=test-user +testpassword=test-pwd + +wrongusername=test-user +wrongpassword=wrongPassword + +adminusername=test-user +adminpassword=test-pwd + +authsourceusername=auth-source-user +authsourcepassword=auth-source-password \ No newline at end of file diff --git a/components-starter/camel-netty-starter/src/test/java/org/apache/camel/component/netty/springboot/NettyComponentConfigurationTest.java b/components-starter/camel-netty-starter/src/test/java/org/apache/camel/component/netty/springboot/NettyComponentConfigurationTest.java index 8a9c9a139cd..a56b71b5352 100644 --- a/components-starter/camel-netty-starter/src/test/java/org/apache/camel/component/netty/springboot/NettyComponentConfigurationTest.java +++ b/components-starter/camel-netty-starter/src/test/java/org/apache/camel/component/netty/springboot/NettyComponentConfigurationTest.java @@ -18,6 +18,9 @@ import static org.junit.jupiter.api.Assertions.*; +import java.io.IOException; +import java.util.Properties; + import javax.net.ssl.SSLSession; import org.apache.camel.CamelContext; @@ -66,9 +69,16 @@ class NettyComponentConfigurationTest { @EndpointInject("mock:result") private MockEndpoint mockResult; + + private static Properties loadAuthProperties() throws IOException { + Properties properties = new Properties(); + properties.load(NettyComponentConfigurationTest.class.getClassLoader().getResourceAsStream("nettycomponentconfigurationtest.properties")); + return properties; + } @Test - void testAutoConfiguration() { + void testAutoConfiguration() throws IOException { + Properties properties = loadAuthProperties(); NettyComponent component = context.getComponent("netty", NettyComponent.class); assertNotNull(component); assertNotNull(component.getConfiguration()); @@ -77,7 +87,7 @@ void testAutoConfiguration() { assertNotNull(scp); assertEquals(TLSv13, scp.getSecureSocketProtocol()); KeyManagersParameters kmp = scp.getKeyManagers(); - assertEquals("changeit", kmp.getKeyPassword()); + assertEquals(properties.getProperty("password"), kmp.getKeyPassword()); } @Test @@ -96,16 +106,16 @@ void testRoute() { public static class TestConfiguration { @Bean(name = "sslContextParameters") - public SSLContextParameters getSSLContextParameters() { + public SSLContextParameters getSSLContextParameters() throws IOException { + Properties authProperties = loadAuthProperties(); SSLContextParameters scp = new SSLContextParameters(); scp.setSecureSocketProtocol(TLSv13); KeyStoreParameters ksp = new KeyStoreParameters(); ksp.setResource(this.getClass().getClassLoader().getResource("keystore.jks").toString()); - ksp.setPassword("changeit"); - + ksp.setPassword(authProperties.getProperty("password")); KeyManagersParameters kmp = new KeyManagersParameters(); kmp.setKeyStore(ksp); - kmp.setKeyPassword("changeit"); + kmp.setKeyPassword(authProperties.getProperty("password")); TrustManagersParameters tmp = new TrustManagersParameters(); tmp.setKeyStore(ksp); scp.setKeyManagers(kmp); diff --git a/components-starter/camel-netty-starter/src/test/resources/nettycomponentconfigurationtest.properties b/components-starter/camel-netty-starter/src/test/resources/nettycomponentconfigurationtest.properties new file mode 100644 index 00000000000..e2db9f632dc --- /dev/null +++ b/components-starter/camel-netty-starter/src/test/resources/nettycomponentconfigurationtest.properties @@ -0,0 +1 @@ +password=changeit diff --git a/components-starter/camel-salesforce-starter/src/test/java/org/apache/camel/component/salesforce/springboot/RawPayloadTest.java b/components-starter/camel-salesforce-starter/src/test/java/org/apache/camel/component/salesforce/springboot/RawPayloadTest.java index 16b1c231bdc..8c45bf8601c 100644 --- a/components-starter/camel-salesforce-starter/src/test/java/org/apache/camel/component/salesforce/springboot/RawPayloadTest.java +++ b/components-starter/camel-salesforce-starter/src/test/java/org/apache/camel/component/salesforce/springboot/RawPayloadTest.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -77,7 +78,6 @@ public class RawPayloadTest extends AbstractSalesforceTestBase { public static String endpointUri; - private static final String OAUTH2_TOKEN_PATH = "/services/oauth2/token"; private static final String XML_RESPONSE = ""; private static final String JSON_RESPONSE = "{ \"response\" : \"mock\" }"; @@ -89,6 +89,12 @@ public class RawPayloadTest extends AbstractSalesforceTestBase { private static String requestBody; private static Map headers; + private static Properties loadProperties() throws IOException { + Properties properties = new Properties(); + properties.load(RawPayloadTest.class.getClassLoader().getResourceAsStream("rawpayload.properties")); + return properties; + } + @Override @Bean("salesforce") protected SalesforceComponent createComponent() throws Exception { @@ -128,7 +134,14 @@ public static void startServer() throws IOException { server.setDispatcher(new Dispatcher() { @Override public MockResponse dispatch(RecordedRequest recordedRequest) throws InterruptedException { - if (recordedRequest.getPath().equals(OAUTH2_TOKEN_PATH)) { + + Properties props; + try { + props = loadProperties(); + } catch (IOException ioe) { + throw new IllegalStateException(ioe); + } + if (recordedRequest.getPath().equals(props.getProperty("tokenpath"))) { return new MockResponse().setResponseCode(200) .setBody("{ \"access_token\": \"mock_token\", \"instance_url\": \"" + loginUrl + "\"}"); } else { diff --git a/components-starter/camel-salesforce-starter/src/test/resources/rawpayload.properties b/components-starter/camel-salesforce-starter/src/test/resources/rawpayload.properties new file mode 100644 index 00000000000..ee90a155dcc --- /dev/null +++ b/components-starter/camel-salesforce-starter/src/test/resources/rawpayload.properties @@ -0,0 +1 @@ +tokenpath=/services/oauth2/token diff --git a/components-starter/camel-zipfile-starter/src/test/java/org/apache/camel/dataformat/zipfile/springboot/ZipFileDataFormatTest.java b/components-starter/camel-zipfile-starter/src/test/java/org/apache/camel/dataformat/zipfile/springboot/ZipFileDataFormatTest.java index 1e5ddaa0902..63236668b79 100644 --- a/components-starter/camel-zipfile-starter/src/test/java/org/apache/camel/dataformat/zipfile/springboot/ZipFileDataFormatTest.java +++ b/components-starter/camel-zipfile-starter/src/test/java/org/apache/camel/dataformat/zipfile/springboot/ZipFileDataFormatTest.java @@ -368,7 +368,17 @@ public void configure() { public void process(Exchange exchange) throws Exception { ZipFile zfile = new ZipFile(new File("src/test/resources/hello.odt")); ZipEntry entry = new ZipEntry((String) exchange.getIn().getHeader(Exchange.FILE_NAME)); - File file = new File("hello_out", entry.getName()); + String outputDirectory = "hello_out"; + File file = new File(outputDirectory, entry.getName()); + + // Check for Path Traversal + File destDirectory = new File(outputDirectory); + String destCanonicalPath = destDirectory.getCanonicalPath(); + String outputCanonicalPath = file.getCanonicalPath(); + if (!outputCanonicalPath.startsWith(destCanonicalPath)) { + throw new Exception("Zip path traversal found, expected " + destCanonicalPath + " but found " + outputCanonicalPath); + } + if (entry.isDirectory()) { file.mkdirs(); } else { diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java index 2b0cbe6e80a..e140b38d958 100644 --- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java +++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java @@ -151,6 +151,9 @@ private static String getParentVersion(File pom) throws Exception { } private static String xpath(File pom, String expression) throws Exception { + factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + factory.setFeature("http://xml.org/sax/features/external-general-entities", false); + factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(pom); XPath xpath = xPathfactory.newXPath(); diff --git a/tooling/camel-spring-boot-generator-maven-plugin/src/main/java/org/apache/camel/springboot/maven/SpringBootStarterMojo.java b/tooling/camel-spring-boot-generator-maven-plugin/src/main/java/org/apache/camel/springboot/maven/SpringBootStarterMojo.java index 556d8ef2cf8..249bf8eeeaa 100644 --- a/tooling/camel-spring-boot-generator-maven-plugin/src/main/java/org/apache/camel/springboot/maven/SpringBootStarterMojo.java +++ b/tooling/camel-spring-boot-generator-maven-plugin/src/main/java/org/apache/camel/springboot/maven/SpringBootStarterMojo.java @@ -327,7 +327,12 @@ private Document createBasePom() { boolean editablePom = content.contains(GENERATED_SECTION_START_COMMENT); if (editablePom) { content = removeGeneratedSections(content, 10); - DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl",true); + documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities",false); + documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities",false); + + DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); Document pom; try (InputStream contentIn = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) {