Skip to content

Commit

Permalink
Merge branch 'develop' into #121-print-stack-trace
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java
  • Loading branch information
Marcel Pfotenhauer committed Aug 31, 2020
2 parents 7d95390 + 184f0bb commit 761865a
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 68 deletions.
6 changes: 3 additions & 3 deletions config/neodymium.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source.version>1.8</maven.compiler.source.version>
<maven.compiler.target.version>1.8</maven.compiler.target.version>
<maven.compiler.source.version>11</maven.compiler.source.version>
<maven.compiler.target.version>11</maven.compiler.target.version>
<surefire.version>2.22.2</surefire.version>
<allure.version>2.13.5</allure.version>
<cucumber.version>5.7.0</cucumber.version>
Expand Down Expand Up @@ -135,6 +135,7 @@
</executions>
<configuration>
<source>8</source>
<detectJavaApiLink>false</detectJavaApiLink>
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -298,7 +299,6 @@
<groupId>com.browserup</groupId>
<artifactId>browserup-proxy-mitm</artifactId>
<version>2.1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ public static <T extends StatementBuilder> T instantiate(Class<T> 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);
}
Expand All @@ -56,7 +52,7 @@ public static <T extends Annotation> List<T> getAnnotations(AnnotatedElement obj
{
annotations.addAll(Arrays.asList((T[]) annotation.getClass().getMethod("value").invoke(annotation)));
}
catch (Exception e)
catch (ReflectiveOperationException e)
{
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -92,7 +88,7 @@ public static <T extends Annotation> List<T> getDeclaredAnnotations(AnnotatedEle
{
annotations.addAll(Arrays.asList((T[]) annotation.getClass().getMethod("value").invoke(annotation)));
}
catch (Exception e)
catch (ReflectiveOperationException e)
{
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public final class BrowserRunnerHelper

private static List<String> safariBrowsers = new LinkedList<String>();

private final static Object mutex = new Object();

static
{
chromeBrowsers.add(BrowserType.ANDROID);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
19 changes: 9 additions & 10 deletions src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, String> expectedFailureMessages)
Expand Down Expand Up @@ -190,17 +191,15 @@ public void checkDescription(final Class<?> clazz, final String[] expectedTestDe
*/
public static void writeMapToPropertiesFile(final Map<String, String> 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);
}
Expand Down

0 comments on commit 761865a

Please sign in to comment.