Skip to content

Commit

Permalink
[RESTEASY-2992] Fix the ClientConfigProviderTestJarHelper to work on …
Browse files Browse the repository at this point in the history
…Windows
  • Loading branch information
Dimitris Kafetzis committed May 22, 2023
1 parent eebda29 commit d221bb9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
Expand Up @@ -35,7 +35,6 @@
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down Expand Up @@ -336,7 +335,6 @@ public void testWithClientRequestFilterUnauthorizedUser() {
*/
@Test
public void testClientConfigProviderCredentials() throws IOException {
Assume.assumeFalse("Skip on Windows due to large class path. See RESTEASY-2992.", TestUtil.isWindows());
String jarPath = ClientConfigProviderTestJarHelper.createClientConfigProviderTestJarWithBASIC();

Process process = ClientConfigProviderTestJarHelper.runClientConfigProviderTestJar(
Expand Down
Expand Up @@ -3,9 +3,7 @@
import java.io.File;
import java.io.IOException;

import org.jboss.resteasy.utils.TestUtil;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;

/**
Expand All @@ -17,7 +15,6 @@ public class ClientConfigProviderBearerTokenTest {

@Test
public void testClientConfigProviderBearerToken() throws IOException {
Assume.assumeFalse("Skip on Windows due to large class path. See RESTEASY-2992.", TestUtil.isWindows());
String jarPath = ClientConfigProviderTestJarHelper.createClientConfigProviderTestJarWithBearerToken();

Process process = ClientConfigProviderTestJarHelper.runClientConfigProviderBearerTestJar(
Expand Down
Expand Up @@ -9,11 +9,14 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Objects;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.regex.Pattern;

/**
* Contains utility methods used for creating, running and getting results of jars meant to test ClientConfigProvider
Expand Down Expand Up @@ -41,7 +44,7 @@ private static class ConfigProviderProperties {

private static final String PACKAGE_NAME = "org.jboss.resteasy.test.security.testjar";
private static final String PACKAGE_PATH = "org/jboss/resteasy/test/security/testjar/";
private static final String JAR_NAME = "client-config-provider-test.jar";
private static final String JAR_NAME = "clientconf.jar";

private static ConfigProviderProperties bearerJarConfigProperties = new ConfigProviderProperties();
private static ConfigProviderProperties basicAuthJarConfigProperties = new ConfigProviderProperties();
Expand Down Expand Up @@ -120,13 +123,28 @@ static Process runClientConfigProviderBearerTestJar(TestType testType, String ja
}

static Process runClientConfigProviderTestJar(String jarPath, String[] args) throws IOException {
final Pattern pattern = Pattern.compile(
".*(maven|plexus|sisu|xnio|jsoup|compress|shrinkwrap|IntelliJ|mockito|arquillian|aether|wildfly|glassfish|hibernate|netty|xerces|xalan|hamcrest|io7m|slf4j|objenesis|sshd|marshalling|remoting|bytebuddy).*");

final String cp = jarPath + File.pathSeparator + System.getProperty("java.class.path");
final String[] paths = cp.split(Pattern.quote(File.pathSeparator));
final StringBuilder newCp = new StringBuilder();
for (String s : paths) {
final Path path = Path.of(s);
if (pattern.matcher(path.toString()).matches()) {
continue;
}
newCp.append(path).append(File.pathSeparator);
}
// use quotation marks for classpath on windows because folder names can have spaces
String classPath = System.getProperty("os.name").contains("indows")
? "\"" + jarPath + ";" + System.getProperty("java.class.path") + "\""
: jarPath + ":" + System.getProperty("java.class.path");
return Runtime.getRuntime()
.exec("java -cp " + classPath + " " + ClientConfigProviderTestJarHelper.PACKAGE_NAME + "."
+ String.join(" ", args));
ProcessBuilder pb;
String[] rest = Arrays.copyOfRange(args, 1, args.length);
pb = new ProcessBuilder("java", "-ea", "-cp", newCp.toString(),
ClientConfigProviderTestJarHelper.PACKAGE_NAME + "." + args[0]);
for (String arg : rest) {
pb.command().add(arg);
}
return pb.start();
}

static String getResultOfProcess(Process proc) throws IOException {
Expand Down
Expand Up @@ -32,7 +32,6 @@
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -250,8 +249,7 @@ public void testIsTrustSelfSignedCertificatesTrue() {
}

@Test
public void testTrustedServerWithClientConfigProvider() throws IOException, InterruptedException {
Assume.assumeFalse("Skip on Windows due to large class path. See RESTEASY-2992.", TestUtil.isWindows());
public void testTrustedServerWithClientConfigProvider() throws IOException {
String jarPath = ClientConfigProviderTestJarHelper.createClientConfigProviderTestJarWithSSL();
File clientTruststore = new File(CLIENT_TRUSTSTORE_PATH);
Process process = ClientConfigProviderTestJarHelper.runClientConfigProviderTestJar(
Expand Down

0 comments on commit d221bb9

Please sign in to comment.