Skip to content

better proxy management to be able to execute tests behind a proxy #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions jsign-core/src/main/java/net/jsign/SignerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private AuthenticodeSigner build() throws SignerException {
}

try {
initializeProxy(proxyUrl, proxyUser, proxyPass);
initializeProxy(proxyUrl, proxyUser, proxyPass, console);
} catch (Exception e) {
throw new SignerException("Couldn't initialize proxy", e);
}
Expand Down Expand Up @@ -452,14 +452,29 @@ private Certificate[] loadCertificateChain(File file) throws IOException, Certif
}
}

/**
* Initialize the proxy. Information is get from env:
* -Dhttp.proxyUrl proxy url http://proxy-server:port (optional)
* -Dhttp.proxyUser proxy username (optional, but considered only if proxyUrl and proxyPassword set)
* -Dhttp.proxyPassword proxy password (optional, but considered only if proxyUrl and proxyUser set)
*/
public static void initializeProxy() throws MalformedURLException {
initializeProxy(
System.getProperty("http.proxyUrl"),
System.getProperty("http.proxyUser"),
System.getProperty("http.proxyPassword"),
null);
}

/**
* Initializes the proxy.
*
* @param proxyUrl the url of the proxy (either as hostname:port or http[s]://hostname:port)
* @param proxyUser the username for the proxy authentication
* @param proxyPassword the password for the proxy authentication
* @param console console for log. Can be null
*/
private void initializeProxy(String proxyUrl, final String proxyUser, final String proxyPassword) throws MalformedURLException {
private static void initializeProxy(String proxyUrl, final String proxyUser, final String proxyPassword, Console console) throws MalformedURLException {
// Do nothing if there is no proxy url.
if (proxyUrl != null && proxyUrl.trim().length() > 0) {
if (!proxyUrl.trim().startsWith("http")) {
Expand Down
8 changes: 8 additions & 0 deletions jsign-core/src/test/java/net/jsign/PESignerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.Security;
Expand All @@ -39,6 +40,8 @@
import org.bouncycastle.cms.SignerInformation;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.tsp.TSPAlgorithms;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import net.jsign.pe.PEFile;
Expand All @@ -59,6 +62,11 @@ private KeyStore getKeyStore() throws Exception {
return keystore;
}

@Before
public void initProxy() throws MalformedURLException {
SignerHelper.initializeProxy();
}

@Test
public void testSign() throws Exception {
File sourceFile = new File("target/test-classes/wineyes.exe");
Expand Down
7 changes: 7 additions & 0 deletions jsign-core/src/test/java/net/jsign/ScriptSignerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore;
Expand All @@ -27,6 +28,7 @@
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.FileUtils;
import org.bouncycastle.cms.CMSSignedData;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

Expand All @@ -45,6 +47,11 @@ protected KeyStore getKeyStore() throws Exception {
return keystore;
}

@BeforeClass
public static void initProxy() throws MalformedURLException {
SignerHelper.initializeProxy();
}

@Test
public void testSign() throws Exception {
File sourceFile = new File("target/test-classes/hello-world." + getFileExtension());
Expand Down