Skip to content
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

Respect proxy whitelist #27

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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.420</version><!-- which version of Jenkins is this plugin built against? -->
<version>1.443</version><!-- which version of Jenkins is this plugin built against? -->
</parent>

<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/testflight/TestflightRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ private TestflightUploader.UploadRequest createPartialUploadRequest(TestflightTe
ur.lists = vars.expand(lists);
ur.notifyTeam = notifyTeam;
ProxyConfiguration proxy = getProxy();
ur.noProxyHostPatterns = proxy.getNoProxyHostPatterns();
ur.proxyHost = proxy.name;
ur.proxyPass = proxy.getPassword();
ur.proxyPort = proxy.port;
Expand Down
64 changes: 44 additions & 20 deletions src/main/java/testflight/TestflightUploader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package testflight;


import java.io.*;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
Expand All @@ -13,14 +22,6 @@
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.simple.parser.JSONParser;
import org.apache.commons.io.IOUtils;

import java.io.*;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Scanner;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
* A testflight uploader
Expand All @@ -45,8 +46,11 @@ static class UploadRequest implements Serializable {
String proxyUser;
String proxyPass;
int proxyPort;
List<Pattern> noProxyHostPatterns;
Boolean debug;

static final String apiDomain = "testflightapp.com";
static final String httpPost = "/api/builds.json";
@Override
public String toString() {
return new ToStringBuilder(this)
.append("filePaths", filePaths)
Expand Down Expand Up @@ -83,6 +87,7 @@ static UploadRequest copy(UploadRequest r) {
r2.proxyUser = r.proxyUser;
r2.proxyPort = r.proxyPort;
r2.proxyPass = r.proxyPass;
r2.noProxyHostPatterns = r.noProxyHostPatterns;
r2.debug = r.debug;

return r2;
Expand All @@ -95,22 +100,41 @@ public void setLogger(Logger logger) {
this.logger = logger;
}

private boolean ignoreProxy(UploadRequest ur){
for (Pattern pattern : ur.noProxyHostPatterns){
if(pattern.matcher(UploadRequest.apiDomain).matches()){
logDebug("Pattern '" + pattern.toString() + "' matches '" + UploadRequest.apiDomain +"'");
return true;
}
logDebug("Pattern '" + pattern.toString() + "' does not match '" + UploadRequest.apiDomain +"'");
}
return false;
}

public Map upload(UploadRequest ur) throws IOException, org.json.simple.parser.ParseException {
DefaultHttpClient httpClient = new DefaultHttpClient();

// Configure the proxy if necessary
if (ur.proxyHost != null && !ur.proxyHost.isEmpty() && ur.proxyPort > 0) {
Credentials cred = null;
if (ur.proxyUser != null && !ur.proxyUser.isEmpty())
cred = new UsernamePasswordCredentials(ur.proxyUser, ur.proxyPass);

httpClient.getCredentialsProvider().setCredentials(new AuthScope(ur.proxyHost, ur.proxyPort), cred);
HttpHost proxy = new HttpHost(ur.proxyHost, ur.proxyPort);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
if(ignoreProxy(ur)){
//clear proxy settings to provide correct debug messages
ur.proxyHost = "<ignored>";
ur.proxyPort = 0;
ur.proxyUser = "<ignored>";
ur.proxyPass = "<ignored>";
}else{
// Configure the proxy if necessary
if (ur.proxyHost != null && !ur.proxyHost.isEmpty() && ur.proxyPort > 0) {
Credentials cred = null;
if (ur.proxyUser != null && !ur.proxyUser.isEmpty())
cred = new UsernamePasswordCredentials(ur.proxyUser, ur.proxyPass);

httpClient.getCredentialsProvider().setCredentials(new AuthScope(ur.proxyHost, ur.proxyPort), cred);
HttpHost proxy = new HttpHost(ur.proxyHost, ur.proxyPort);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
}

HttpHost targetHost = new HttpHost("testflightapp.com");
HttpPost httpPost = new HttpPost("/api/builds.json");
HttpHost targetHost = new HttpHost(UploadRequest.apiDomain);
HttpPost httpPost = new HttpPost(UploadRequest.httpPost);
FileBody fileBody = new FileBody(ur.file);

MultipartEntity entity = new MultipartEntity();
Expand Down