Skip to content

Fixed user/pass preferences save for "manual" proxy settings. #9843

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

Merged
merged 1 commit into from
Mar 23, 2020
Merged
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
20 changes: 12 additions & 8 deletions app/src/cc/arduino/view/preferences/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,14 @@ private void savePreferencesData() {
PreferencesData.set(Constants.PREF_PROXY_MANUAL_TYPE, manualProxyTypeButtonGroup.getSelection().getActionCommand());
PreferencesData.set(Constants.PREF_PROXY_MANUAL_HOSTNAME, manualProxyHostName.getText());
PreferencesData.set(Constants.PREF_PROXY_MANUAL_PORT, manualProxyPort.getText());
PreferencesData.set(Constants.PREF_PROXY_MANUAL_USERNAME, manualProxyUsername.getText());
PreferencesData.set(Constants.PREF_PROXY_MANUAL_PASSWORD, String.valueOf(manualProxyPassword.getPassword()));
PreferencesData.set(Constants.PREF_PROXY_AUTO_USERNAME, autoProxyUsername.getText());
PreferencesData.set(Constants.PREF_PROXY_AUTO_PASSWORD, String.valueOf(autoProxyPassword.getPassword()));
if (PreferencesData.get(Constants.PREF_PROXY_TYPE).equals(Constants.PROXY_TYPE_MANUAL)) {
PreferencesData.set(Constants.PREF_PROXY_USERNAME, manualProxyUsername.getText());
PreferencesData.set(Constants.PREF_PROXY_PASSWORD, String.valueOf(manualProxyPassword.getPassword()));
}
if (PreferencesData.get(Constants.PREF_PROXY_TYPE).equals(Constants.PROXY_TYPE_AUTO)) {
PreferencesData.set(Constants.PREF_PROXY_USERNAME, autoProxyUsername.getText());
PreferencesData.set(Constants.PREF_PROXY_PASSWORD, String.valueOf(autoProxyPassword.getPassword()));
}
}

private void showPreferencesData() {
Expand Down Expand Up @@ -924,16 +928,16 @@ private void showPreferencesData() {
if (!PreferencesData.get(Constants.PREF_PROXY_PAC_URL, "").isEmpty()) {
autoProxyUsePAC.setSelected(true);
autoProxyPACURL.setText(PreferencesData.get(Constants.PREF_PROXY_PAC_URL));
autoProxyUsername.setText(PreferencesData.get(Constants.PREF_PROXY_AUTO_USERNAME));
autoProxyPassword.setText(PreferencesData.get(Constants.PREF_PROXY_AUTO_PASSWORD));
autoProxyUsername.setText(PreferencesData.get(Constants.PREF_PROXY_USERNAME));
autoProxyPassword.setText(PreferencesData.get(Constants.PREF_PROXY_PASSWORD));
}
} else {
manualProxy.setSelected(true);
manualProxyFieldsSetEnabled(true);
manualProxyHostName.setText(PreferencesData.get(Constants.PREF_PROXY_MANUAL_HOSTNAME));
manualProxyPort.setText(PreferencesData.get(Constants.PREF_PROXY_MANUAL_PORT));
manualProxyUsername.setText(PreferencesData.get(Constants.PREF_PROXY_MANUAL_USERNAME));
manualProxyPassword.setText(PreferencesData.get(Constants.PREF_PROXY_MANUAL_PASSWORD));
manualProxyUsername.setText(PreferencesData.get(Constants.PREF_PROXY_USERNAME));
manualProxyPassword.setText(PreferencesData.get(Constants.PREF_PROXY_PASSWORD));
}

String selectedManualProxyType = PreferencesData.get(Constants.PREF_PROXY_MANUAL_TYPE, Constants.PROXY_MANUAL_TYPE_HTTP);
Expand Down
8 changes: 4 additions & 4 deletions app/test/cc/arduino/net/CustomProxySelectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void testProxyPACHTTP() throws Exception {
public void testProxyPACHTTPWithLogin() throws Exception {
preferences.put(Constants.PREF_PROXY_TYPE, Constants.PROXY_TYPE_AUTO);
preferences.put(Constants.PREF_PROXY_PAC_URL, CustomProxySelectorTest.class.getResource("proxy_http.pac").toExternalForm());
preferences.put(Constants.PREF_PROXY_AUTO_USERNAME, "auto");
preferences.put(Constants.PREF_PROXY_AUTO_PASSWORD, "autopassword");
preferences.put(Constants.PREF_PROXY_USERNAME, "auto");
preferences.put(Constants.PREF_PROXY_PASSWORD, "autopassword");
CustomProxySelector proxySelector = new CustomProxySelector(preferences);
Proxy proxy = proxySelector.getProxyFor(uri);

Expand Down Expand Up @@ -154,8 +154,8 @@ public void testManualProxyWithLogin() throws Exception {
preferences.put(Constants.PREF_PROXY_MANUAL_TYPE, Constants.PROXY_MANUAL_TYPE_HTTP);
preferences.put(Constants.PREF_PROXY_MANUAL_HOSTNAME, "localhost");
preferences.put(Constants.PREF_PROXY_MANUAL_PORT, "8080");
preferences.put(Constants.PREF_PROXY_MANUAL_USERNAME, "username");
preferences.put(Constants.PREF_PROXY_MANUAL_PASSWORD, "pwd");
preferences.put(Constants.PREF_PROXY_USERNAME, "username");
preferences.put(Constants.PREF_PROXY_PASSWORD, "pwd");

CustomProxySelector proxySelector = new CustomProxySelector(preferences);
Proxy proxy = proxySelector.getProxyFor(uri);
Expand Down
6 changes: 2 additions & 4 deletions arduino-core/src/cc/arduino/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ public class Constants {
public static final String PREF_PROXY_PAC_URL = "proxy.pac.url";
public static final String PREF_PROXY_MANUAL_HOSTNAME = "proxy.manual.hostname";
public static final String PREF_PROXY_MANUAL_PORT = "proxy.manual.port";
public static final String PREF_PROXY_MANUAL_USERNAME = "proxy.manual.username";
public static final String PREF_PROXY_MANUAL_PASSWORD = "proxy.manual.password";
public static final String PREF_PROXY_AUTO_USERNAME = "proxy.manual.username";
public static final String PREF_PROXY_AUTO_PASSWORD = "proxy.manual.password";
public static final String PREF_PROXY_USERNAME = "proxy.manual.username";
public static final String PREF_PROXY_PASSWORD = "proxy.manual.password";

public static final String PACKAGE_INDEX_URL;
public static final String LIBRARY_INDEX_URL;
Expand Down
4 changes: 2 additions & 2 deletions arduino-core/src/cc/arduino/net/CustomProxySelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Proxy getProxyFor(URI uri) throws IOException, ScriptException, NoSuchMet
}

private Proxy pacProxy(String pac, URI uri) throws IOException, ScriptException, NoSuchMethodException {
setAuthenticator(preferences.get(Constants.PREF_PROXY_AUTO_USERNAME), preferences.get(Constants.PREF_PROXY_AUTO_PASSWORD));
setAuthenticator(preferences.get(Constants.PREF_PROXY_USERNAME), preferences.get(Constants.PREF_PROXY_PASSWORD));

URLConnection urlConnection = new URL(pac).openConnection();
urlConnection.connect();
Expand Down Expand Up @@ -141,7 +141,7 @@ private URL toUrl(URI uri) {
}

private Proxy manualProxy() {
setAuthenticator(preferences.get(Constants.PREF_PROXY_MANUAL_USERNAME), preferences.get(Constants.PREF_PROXY_MANUAL_PASSWORD));
setAuthenticator(preferences.get(Constants.PREF_PROXY_USERNAME), preferences.get(Constants.PREF_PROXY_PASSWORD));
Proxy.Type type = Proxy.Type.valueOf(preferences.get(Constants.PREF_PROXY_MANUAL_TYPE));
return new Proxy(type, new InetSocketAddress(preferences.get(Constants.PREF_PROXY_MANUAL_HOSTNAME), Integer.valueOf(preferences.get(Constants.PREF_PROXY_MANUAL_PORT))));
}
Expand Down