diff --git a/config/neodymium.properties b/config/neodymium.properties index 17ba144c3..e9b68470a 100644 --- a/config/neodymium.properties +++ b/config/neodymium.properties @@ -107,10 +107,10 @@ # ############################# # -# SelenidetAddons properties +# SelenideAddons properties # ############################# -# The following properties are taken into account if you use functions form the SelenidUtils class. +# The following properties are taken into account if you use functions form the SelenideUtils class. # # How often should Selenide try to match a condition if the element is affected by staleness # neodymium.selenideAddons.staleElement.retry.count = 3 @@ -245,7 +245,7 @@ neodymium.webDriver.keepBrowserOpenOnFailure = false # ############################# -# Create a local proxy to use it for basic authentication, header manipulations or similar things +# Create a local proxy to use it for basic authentication, header manipulations or similar things # neodymium.localproxy = false # The following settings are required if a (self signed) certificate is used to authenticate the man in the middle(MITM) proxy diff --git a/pom.xml b/pom.xml index 92c6ec798..831a78d55 100644 --- a/pom.xml +++ b/pom.xml @@ -51,8 +51,8 @@ UTF-8 - 1.8 - 1.8 + 11 + 11 2.22.2 2.13.5 5.7.0 @@ -135,6 +135,7 @@ 8 + false @@ -298,7 +299,6 @@ com.browserup browserup-proxy-mitm 2.1.1 - compile \ No newline at end of file diff --git a/src/main/java/com/xceptance/neodymium/module/StatementBuilder.java b/src/main/java/com/xceptance/neodymium/module/StatementBuilder.java index 035168ced..4f61f04ee 100644 --- a/src/main/java/com/xceptance/neodymium/module/StatementBuilder.java +++ b/src/main/java/com/xceptance/neodymium/module/StatementBuilder.java @@ -25,13 +25,9 @@ public static T instantiate(Class clazz) { try { - return clazz.newInstance(); + return clazz.getDeclaredConstructor().newInstance(); } - catch (InstantiationException e) - { - throw new RuntimeException(e); - } - catch (IllegalAccessException e) + catch (ReflectiveOperationException e) { throw new RuntimeException(e); } @@ -56,7 +52,7 @@ public static List getAnnotations(AnnotatedElement obj { annotations.addAll(Arrays.asList((T[]) annotation.getClass().getMethod("value").invoke(annotation))); } - catch (Exception e) + catch (ReflectiveOperationException e) { throw new RuntimeException(e); } @@ -92,7 +88,7 @@ public static List getDeclaredAnnotations(AnnotatedEle { annotations.addAll(Arrays.asList((T[]) annotation.getClass().getMethod("value").invoke(annotation))); } - catch (Exception e) + catch (ReflectiveOperationException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/BrowserRunnerHelper.java b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/BrowserRunnerHelper.java index 922096efd..2a672db67 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/BrowserRunnerHelper.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/browser/multibrowser/BrowserRunnerHelper.java @@ -60,6 +60,8 @@ public final class BrowserRunnerHelper private static List safariBrowsers = new LinkedList(); + private final static Object mutex = new Object(); + static { chromeBrowsers.add(BrowserType.ANDROID); @@ -278,44 +280,12 @@ else if (safariBrowsers.contains(browserName)) private static BrowserUpProxy setupEmbeddedProxy() { // instantiate the proxy - BrowserUpProxy proxy = new BrowserUpProxyServer(); + final BrowserUpProxy proxy = new BrowserUpProxyServer(); if (Neodymium.configuration().useLocalProxyWithSelfSignedCertificate()) { - ImpersonatingMitmManager mitmManager = null; - if (Neodymium.configuration().localProxyGenerateSelfSignedCertificate()) - { - CertificateAndKeySource certSource; - File certFile = new File("./config/embeddedLocalProxySelfSignedRootCertificate.p12"); - if (certFile.canRead()) - { - certSource = new KeyStoreFileCertificateSource(CERT_FORMAT, certFile, CERT_NAME, CERT_PASSWORD); - } - else - { - // create a dynamic CA root certificate generator using default settings (2048-bit RSA keys) - RootCertificateGenerator rootCertificateGenerator = RootCertificateGenerator.builder().build(); - // save the dynamically-generated CA root certificate for installation in a browser - rootCertificateGenerator.saveRootCertificateAndKey(CERT_FORMAT, certFile, CERT_NAME, CERT_PASSWORD); - certSource = rootCertificateGenerator; - } - // tell the MitmManager to use the root certificate we just generated - mitmManager = ImpersonatingMitmManager.builder().rootCertificateSource(certSource).build(); - } - else - { - // configure the MITM using the provided certificate - String type = Neodymium.configuration().localProxyCertificateArchiveType(); - String file = Neodymium.configuration().localProxyCertificateArchiveFile(); - String cName = Neodymium.configuration().localProxyCertificateName(); - String cPassword = Neodymium.configuration().localProxyCertificatePassword(); - if (StringUtils.isAnyBlank(type, file, cName, cPassword)) - { - throw new RuntimeException("The local proxy certificate isn't fully configured. Please check: certificate archive type, certificate archive file, certificate name and certificate password."); - } - KeyStoreFileCertificateSource fileCertificateSource = new KeyStoreFileCertificateSource(type, new File(file), cName, cPassword); - mitmManager = ImpersonatingMitmManager.builder().rootCertificateSource(fileCertificateSource).build(); - } + final CertificateAndKeySource rootCertificateSource = createLocalProxyRootCertSource(); + final ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder().rootCertificateSource(rootCertificateSource).build(); proxy.setMitmManager(mitmManager); } else @@ -328,9 +298,9 @@ private static BrowserUpProxy setupEmbeddedProxy() proxy.start(); // default basic authentication via the proxy - String host = Neodymium.configuration().host(); - String bUsername = Neodymium.configuration().basicAuthUsername(); - String bPassword = Neodymium.configuration().basicAuthPassword(); + final String host = Neodymium.configuration().host(); + final String bUsername = Neodymium.configuration().basicAuthUsername(); + final String bPassword = Neodymium.configuration().basicAuthPassword(); if (StringUtils.isNoneBlank(host, bUsername, bPassword)) { proxy.autoAuthorization(host, bUsername, bPassword, AuthType.BASIC); @@ -339,6 +309,43 @@ private static BrowserUpProxy setupEmbeddedProxy() return proxy; } + private static CertificateAndKeySource createLocalProxyRootCertSource() + { + if (Neodymium.configuration().localProxyGenerateSelfSignedCertificate()) + { + synchronized (mutex) + { + final File certFile = new File("./config/embeddedLocalProxySelfSignedRootCertificate.p12"); + certFile.deleteOnExit(); + if (certFile.canRead()) + { + return new KeyStoreFileCertificateSource(CERT_FORMAT, certFile, CERT_NAME, CERT_PASSWORD); + } + else + { + // create a dynamic CA root certificate generator using default settings (2048-bit RSA keys) + final RootCertificateGenerator rootCertificateGenerator = RootCertificateGenerator.builder().build(); + // save the dynamically-generated CA root certificate for installation in a browser + rootCertificateGenerator.saveRootCertificateAndKey(CERT_FORMAT, certFile, CERT_NAME, CERT_PASSWORD); + return rootCertificateGenerator; + } + } + } + else + { + // configure the MITM using the provided certificate + final String type = Neodymium.configuration().localProxyCertificateArchiveType(); + final String file = Neodymium.configuration().localProxyCertificateArchiveFile(); + final String cName = Neodymium.configuration().localProxyCertificateName(); + final String cPassword = Neodymium.configuration().localProxyCertificatePassword(); + if (StringUtils.isAnyBlank(type, file, cName, cPassword)) + { + throw new RuntimeException("The local proxy certificate isn't fully configured. Please check: certificate archive type, certificate archive file, certificate name and certificate password."); + } + return new KeyStoreFileCertificateSource(type, new File(file), cName, cPassword); + } + } + public static Proxy createProxyCapabilities() { final String proxyHost = Neodymium.configuration().getProxyHost() + ":" + Neodymium.configuration().getProxyPort(); diff --git a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java index 9de8d1baf..89f1899a3 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java @@ -210,7 +210,7 @@ public void testGetClass() throws Exception Assert.assertEquals("1234567890", testCompound.getClubCardNumber()); Assert.assertEquals(null, testCompound.getNotSet()); Assert.assertEquals(null, testCompound.getNullValue()); - Assert.assertEquals(new Double(12.34), testCompound.getNumberValue()); + Assert.assertEquals(Double.valueOf(12.34), testCompound.getNumberValue()); Assert.assertEquals("containing strange things like spaces and äüø", testCompound.getDescription()); Assert.assertEquals("4111111111111111", testCompound.getCreditCard().getCardNumber()); Assert.assertEquals("123", testCompound.getCreditCard().getCcv()); @@ -235,7 +235,7 @@ public void testGetClass() throws Exception public void testGetByPath() throws Exception { Double numberValue = DataUtils.get("$.numberValue", Double.class); - Assert.assertEquals(new Double(12.34), numberValue); + Assert.assertEquals(Double.valueOf(12.34), numberValue); String description = DataUtils.get("$.description", String.class); Assert.assertEquals("containing strange things like spaces and äüø", description); @@ -276,7 +276,7 @@ public void testGetClassByPath() throws Exception Assert.assertEquals("1234567890", testCompound.getClubCardNumber()); Assert.assertEquals(null, testCompound.getNotSet()); Assert.assertEquals(null, testCompound.getNullValue()); - Assert.assertEquals(new Double(12.34), testCompound.getNumberValue()); + Assert.assertEquals(Double.valueOf(12.34), testCompound.getNumberValue()); Assert.assertEquals("containing strange things like spaces and äüø", testCompound.getDescription()); Assert.assertEquals("4111111111111111", testCompound.getCreditCard().getCardNumber()); Assert.assertEquals("123", testCompound.getCreditCard().getCcv()); diff --git a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java index acdd98051..704ce1aa0 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java @@ -210,7 +210,7 @@ public void testGetClass() throws Exception Assert.assertEquals(null, testCompound.getNotSet()); // our XML parer does not support explicit null value // Assert.assertEquals(null, testCompound.getNullValue()); - Assert.assertEquals(new Double(12.34), testCompound.getNumberValue()); + Assert.assertEquals(Double.valueOf(12.34), testCompound.getNumberValue()); Assert.assertEquals("containing strange things like spaces and äüø", testCompound.getDescription()); Assert.assertEquals("4111111111111111", testCompound.getCreditCard().getCardNumber()); Assert.assertEquals("123", testCompound.getCreditCard().getCcv()); @@ -235,7 +235,7 @@ public void testGetClass() throws Exception public void testGetByPath() throws Exception { Double numberValue = DataUtils.get("$.numberValue", Double.class); - Assert.assertEquals(new Double(12.34), numberValue); + Assert.assertEquals(Double.valueOf(12.34), numberValue); String description = DataUtils.get("$.description", String.class); Assert.assertEquals("containing strange things like spaces and äüø", description); @@ -277,7 +277,7 @@ public void testGetClassByPath() throws Exception Assert.assertEquals(null, testCompound.getNotSet()); // our XML parer does not support explicit null value // Assert.assertEquals(null, testCompound.getNullValue()); - Assert.assertEquals(new Double(12.34), testCompound.getNumberValue()); + Assert.assertEquals(Double.valueOf(12.34), testCompound.getNumberValue()); Assert.assertEquals("containing strange things like spaces and äüø", testCompound.getDescription()); Assert.assertEquals("4111111111111111", testCompound.getCreditCard().getCardNumber()); Assert.assertEquals("123", testCompound.getCreditCard().getCcv()); diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index 5fdb15532..311617da9 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -1,7 +1,8 @@ package com.xceptance.neodymium.tests; import java.io.File; -import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.text.MessageFormat; import java.util.ArrayList; @@ -13,6 +14,7 @@ import java.util.Optional; import java.util.stream.Collectors; +import org.apache.commons.io.FileUtils; import org.junit.AfterClass; import org.junit.Assert; import org.junit.runner.Description; @@ -54,7 +56,6 @@ public static void deleteTempFile(final File tempFile) } } - // TODO JavaDoc public void check(final Result result, final boolean expectedSuccessful, final int expectedRunCount, final int expectedIgnoreCount, final int expectedFailCount, final Map expectedFailureMessages) @@ -190,17 +191,15 @@ public void checkDescription(final Class clazz, final String[] expectedTestDe */ public static void writeMapToPropertiesFile(final Map map, final File file) { + String propertiesString = map.entrySet().stream() + .map(entry -> entry.getKey() + "=" + entry.getValue()) + .collect(Collectors.joining(System.lineSeparator())); + try { - final String propertiesString = map.keySet().stream() - .map(key -> key + "=" + map.get(key)) - .collect(Collectors.joining("\r\n")); - - final FileOutputStream outputStream = new FileOutputStream(file); - outputStream.write(propertiesString.getBytes()); - outputStream.close(); + FileUtils.writeStringToFile(file, propertiesString, StandardCharsets.UTF_8); } - catch (Exception e) + catch (IOException e) { throw new RuntimeException(e); }