From 3df45c808abcd7dc45282c1136818446a1baa9bf Mon Sep 17 00:00:00 2001 From: Andreas Kuhtz Date: Wed, 17 Nov 2021 18:21:17 +0100 Subject: [PATCH] #36: Support firefox profile for firefox 67 or newer. --- CHANGELOG.md | 4 + pom.xml | 4 +- .../markusbernhardt/proxy/ProxySearch.java | 523 +++++++++--------- .../browser/firefox/FirefoxSettingParser.java | 201 ++++--- .../proxy/search/browser/FirefoxTest.java | 17 + .../proxy/selector/pac/PacProxyDebugging.java | 165 +++--- .../firefox/bk6on8rm.default-release/prefs.js | 76 +++ .../firefox/p6y3k23k.default/prefs.js | 76 +++ .../ff67_manual/.mozilla/firefox/profiles.ini | 20 + 9 files changed, 653 insertions(+), 433 deletions(-) create mode 100644 src/test/resources/ff67_manual/.mozilla/firefox/bk6on8rm.default-release/prefs.js create mode 100644 src/test/resources/ff67_manual/.mozilla/firefox/p6y3k23k.default/prefs.js create mode 100644 src/test/resources/ff67_manual/.mozilla/firefox/profiles.ini diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ae6c6d3..8eb02790 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log This file contains the change log. +## 1.0.16 +* Fixed issue #35: NullPointerException in OsxProxySearchStrategy.getProxySelector +* Fixed issue #36: FirefoxProxySearchStrategy incorrectly detects active user profile + ## 1.0.15 * Fixed issue #32: Add new property "proxy-vole.xml.factory.feature.secure.processing" to activate the FEATURE_SECURE_PROCESSING on DocumentBuilderFactory. diff --git a/pom.xml b/pom.xml index bd48987e..0a661147 100644 --- a/pom.xml +++ b/pom.xml @@ -24,8 +24,8 @@ false 5.6.0 - 5.7.1 - 3.18.1 + 5.7.2 + 3.19.0 1.2.0 1.7.30 diff --git a/src/main/java/com/github/markusbernhardt/proxy/ProxySearch.java b/src/main/java/com/github/markusbernhardt/proxy/ProxySearch.java index 12c40fd1..24a88d78 100644 --- a/src/main/java/com/github/markusbernhardt/proxy/ProxySearch.java +++ b/src/main/java/com/github/markusbernhardt/proxy/ProxySearch.java @@ -2,10 +2,11 @@ import java.awt.GraphicsEnvironment; import java.net.ProxySelector; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; +import org.slf4j.helpers.MessageFormatter; + import com.github.markusbernhardt.proxy.search.browser.firefox.FirefoxProxySearchStrategy; import com.github.markusbernhardt.proxy.search.browser.ie.IEProxySearchStrategy; import com.github.markusbernhardt.proxy.search.desktop.DesktopProxySearchStrategy; @@ -32,11 +33,9 @@ * Implements the "Builder" pattern.
* Use addStrategy to add one or more search strategies.
* If you are done call the getProxySelector method.
- * Then the strategies are asked one after the other for a ProxySelector until - * an valid selector is found.
+ * Then the strategies are asked one after the other for a ProxySelector until an valid selector is found.
*

- * Invoke the static getDefaultProxySearch method to use a default - * search strategy. + * Invoke the static getDefaultProxySearch method to use a default search strategy. *

* * @author Markus Bernhardt, Copyright 2016 @@ -45,262 +44,262 @@ public class ProxySearch implements ProxySearchStrategy { - private static final int DEFAULT_PAC_CACHE_SIZE = 20; - - private static final long DEFAULT_PAC_CACHE_TTL = 1000 * 60 * 10; // 10 - // Minutes - - private static final CacheScope DEFAULT_PAC_CACHE_SCOPE = CacheScope.CACHE_SCOPE_HOST; - - private List strategies; - private int pacCacheSize; - private long pacCacheTTL; - private CacheScope pacCacheScope; - - /***************************************************************************** - * Types of proxy detection supported by the builder. - ****************************************************************************/ - - public enum Strategy { - /// Use the platform settings. - OS_DEFAULT, - /// Use WPAD resolution - WPAD, - /// Use the settings of the platforms default browser. - BROWSER, - /// Use Firefox settings - FIREFOX, - /// Use InternetExplorer settings - IE, - /// Use environment variables for proxy settings. - ENV_VAR, - /// Use windows default proxy settings. - WIN, - /// Use KDE desktop default proxy settings. - KDE, - /// Use KDE desktop default proxy settings. - GNOME, - /// Use Java Networking system properties - JAVA - } - - /************************************************************************* - * Constructor - ************************************************************************/ - - public ProxySearch() { - super(); - this.strategies = new ArrayList(); - this.pacCacheSize = DEFAULT_PAC_CACHE_SIZE; - this.pacCacheTTL = DEFAULT_PAC_CACHE_TTL; - this.pacCacheScope = DEFAULT_PAC_CACHE_SCOPE; - } - - /************************************************************************* - * Sets up a ProxySearch that uses a default search strategy suitable for - * every platform. - * - * @return a ProxySearch initialized with default settings. - ************************************************************************/ - - public static ProxySearch getDefaultProxySearch() { - ProxySearch s = new ProxySearch(); - - // Test if we are a server or a client. - boolean headless = GraphicsEnvironment.isHeadless(); - - if (headless) { - s.addStrategy(Strategy.JAVA); - s.addStrategy(Strategy.OS_DEFAULT); - s.addStrategy(Strategy.ENV_VAR); - } else { - s.addStrategy(Strategy.JAVA); - s.addStrategy(Strategy.BROWSER); - s.addStrategy(Strategy.OS_DEFAULT); - s.addStrategy(Strategy.ENV_VAR); - } - Logger.log(ProxySearch.class, LogLevel.TRACE, "Using default search priority: {}", s); - - return s; - } - - /************************************************************************* - * Adds an search strategy to the list of proxy searches strategies. - * - * @param strategy - * the search strategy to add. - ************************************************************************/ - - public void addStrategy(Strategy strategy) { - switch (strategy) { - case OS_DEFAULT: - this.strategies.add(new DesktopProxySearchStrategy()); - break; - case WPAD: - this.strategies.add(new WpadProxySearchStrategy()); - break; - case BROWSER: - this.strategies.add(getDefaultBrowserStrategy()); - break; - case FIREFOX: - this.strategies.add(new FirefoxProxySearchStrategy()); - break; - case IE: - this.strategies.add(new IEProxySearchStrategy()); - break; - case ENV_VAR: - this.strategies.add(new EnvProxySearchStrategy()); - break; - case WIN: - this.strategies.add(new WinProxySearchStrategy()); - break; - case KDE: - this.strategies.add(new KdeProxySearchStrategy()); - break; - case GNOME: - this.strategies.add(new GnomeDConfProxySearchStrategy()); - this.strategies.add(new GnomeProxySearchStrategy()); - break; - case JAVA: - this.strategies.add(new JavaProxySearchStrategy()); - break; - default: - throw new IllegalArgumentException("Unknown strategy code!"); - } - } - - /************************************************************************* - * Sets the cache size of the PAC proxy selector cache. This defines the - * number of URLs that are cached together with the PAC script result. This - * improves performance because for URLs that are in the cache the script is - * not executed again. You have to set this before you add any strategies - * that may create a PAC script proxy selector. - * - * @param size - * of the cache. Set it to 0 to disable caching. - * @param ttl - * is the time to live of the cache entries as amount of - * milliseconds. - * @param cacheScope - * the desired cache scope. - ************************************************************************/ - - public void setPacCacheSettings(int size, long ttl, CacheScope cacheScope) { - this.pacCacheSize = size; - this.pacCacheTTL = ttl; - this.pacCacheScope = cacheScope; - } - - /************************************************************************* - * Gets the search strategy for the platforms default browser. - * - * @return a ProxySearchStrategy, null if no supported browser was found. - ************************************************************************/ - - private ProxySearchStrategy getDefaultBrowserStrategy() { - switch (PlatformUtil.getDefaultBrowser()) { - case IE: - return new IEProxySearchStrategy(); - case FIREFOX: - return new FirefoxProxySearchStrategy(); - } - return null; - } - - /************************************************************************* - * Gets the proxy selector that will use the configured search order. - * - * @return a ProxySelector, null if none was found for the current builder - * configuration. - ************************************************************************/ - - @Override - public ProxySelector getProxySelector() { - Logger.log(getClass(), LogLevel.TRACE, "Executing search strategies to find proxy selector"); - for (ProxySearchStrategy strat : this.strategies) { - try { - ProxySelector selector = strat.getProxySelector(); - if (selector != null) { - selector = installBufferingAndFallbackBehaviour(selector); - Logger.log(getClass(), LogLevel.INFO, "Proxy found for " + strat.getName()); - - return selector; - } else { - Logger.log(getClass(), LogLevel.INFO, - "No proxy found for " + strat.getName() + ". Trying next one."); - } - } catch (ProxyException e) { - Logger.log(getClass(), LogLevel.DEBUG, "Strategy {} failed trying next one.", e); - // Ignore and try next strategy. - } - } - - return null; - } - - /************************************************************************* - * Gets the printable name of the search strategy. - * - * @return the printable name of the search strategy - ************************************************************************/ - - @Override - public String getName() { - return "default"; - } - - /************************************************************************* - * If it is PAC and we have caching enabled set it here. - * - * @param selector - * the proxy selector to wrap - * @return the wrapped proxy selector or the passed in selector if nothing - * is done. - ************************************************************************/ - - private ProxySelector installBufferingAndFallbackBehaviour(ProxySelector selector) { - if (selector instanceof PacProxySelector) { - if (this.pacCacheSize > 0) { - selector = new BufferedProxySelector(this.pacCacheSize, this.pacCacheTTL, selector, pacCacheScope); - } - selector = new ProxyListFallbackSelector(selector); - } - return selector; - } - - /************************************************************************* - * toString - * - * @see java.lang.Object#toString() - ************************************************************************/ - @Override - public String toString() { - StringBuilder sb = new StringBuilder("Proxy search: "); - for (ProxySearchStrategy strat : this.strategies) { - sb.append(strat); - sb.append(" "); - } - return sb.toString(); - } - - /************************************************************************* - * For testing only. Will print the logging & proxy information to the - * console. - * - * @param args - * the command line arguments. - ************************************************************************/ - - public static void main(String[] args) { - ProxySearch ps = ProxySearch.getDefaultProxySearch(); - Logger.setBackend(new LogBackEnd() { - - public void log(Class clazz, LogLevel loglevel, String msg, Object... params) { - System.out.println(MessageFormat.format(msg, params)); - } - - }); - ps.getProxySelector(); - } + private static final int DEFAULT_PAC_CACHE_SIZE = 20; + + private static final long DEFAULT_PAC_CACHE_TTL = 1000 * 60 * 10; // 10 + // Minutes + + private static final CacheScope DEFAULT_PAC_CACHE_SCOPE = CacheScope.CACHE_SCOPE_HOST; + + private List strategies; + + private int pacCacheSize; + + private long pacCacheTTL; + + private CacheScope pacCacheScope; + + /***************************************************************************** + * Types of proxy detection supported by the builder. + ****************************************************************************/ + + public enum Strategy { + /// Use the platform settings. + OS_DEFAULT, + /// Use WPAD resolution + WPAD, + /// Use the settings of the platforms default browser. + BROWSER, + /// Use Firefox settings + FIREFOX, + /// Use InternetExplorer settings + IE, + /// Use environment variables for proxy settings. + ENV_VAR, + /// Use windows default proxy settings. + WIN, + /// Use KDE desktop default proxy settings. + KDE, + /// Use KDE desktop default proxy settings. + GNOME, + /// Use Java Networking system properties + JAVA + } + + /************************************************************************* + * Constructor + ************************************************************************/ + + public ProxySearch() { + super(); + this.strategies = new ArrayList(); + this.pacCacheSize = DEFAULT_PAC_CACHE_SIZE; + this.pacCacheTTL = DEFAULT_PAC_CACHE_TTL; + this.pacCacheScope = DEFAULT_PAC_CACHE_SCOPE; + } + + /************************************************************************* + * Sets up a ProxySearch that uses a default search strategy suitable for every platform. + * + * @return a ProxySearch initialized with default settings. + ************************************************************************/ + + public static ProxySearch getDefaultProxySearch() { + ProxySearch s = new ProxySearch(); + + // Test if we are a server or a client. + boolean headless = GraphicsEnvironment.isHeadless(); + + if (headless) { + s.addStrategy(Strategy.JAVA); + s.addStrategy(Strategy.OS_DEFAULT); + s.addStrategy(Strategy.ENV_VAR); + } + else { + s.addStrategy(Strategy.JAVA); + s.addStrategy(Strategy.BROWSER); + s.addStrategy(Strategy.OS_DEFAULT); + s.addStrategy(Strategy.ENV_VAR); + } + Logger.log(ProxySearch.class, LogLevel.TRACE, "Using default search priority: {}", s); + + return s; + } + + /************************************************************************* + * Adds an search strategy to the list of proxy searches strategies. + * + * @param strategy + * the search strategy to add. + ************************************************************************/ + + public void addStrategy(Strategy strategy) { + switch (strategy) { + case OS_DEFAULT: + this.strategies.add(new DesktopProxySearchStrategy()); + break; + case WPAD: + this.strategies.add(new WpadProxySearchStrategy()); + break; + case BROWSER: + this.strategies.add(getDefaultBrowserStrategy()); + break; + case FIREFOX: + this.strategies.add(new FirefoxProxySearchStrategy()); + break; + case IE: + this.strategies.add(new IEProxySearchStrategy()); + break; + case ENV_VAR: + this.strategies.add(new EnvProxySearchStrategy()); + break; + case WIN: + this.strategies.add(new WinProxySearchStrategy()); + break; + case KDE: + this.strategies.add(new KdeProxySearchStrategy()); + break; + case GNOME: + this.strategies.add(new GnomeDConfProxySearchStrategy()); + this.strategies.add(new GnomeProxySearchStrategy()); + break; + case JAVA: + this.strategies.add(new JavaProxySearchStrategy()); + break; + default: + throw new IllegalArgumentException("Unknown strategy code!"); + } + } + + /************************************************************************* + * Sets the cache size of the PAC proxy selector cache. This defines the number of URLs that are cached together + * with the PAC script result. This improves performance because for URLs that are in the cache the script is not + * executed again. You have to set this before you add any strategies that may create a PAC script proxy selector. + * + * @param size + * of the cache. Set it to 0 to disable caching. + * @param ttl + * is the time to live of the cache entries as amount of milliseconds. + * @param cacheScope + * the desired cache scope. + ************************************************************************/ + + public void setPacCacheSettings(int size, long ttl, CacheScope cacheScope) { + this.pacCacheSize = size; + this.pacCacheTTL = ttl; + this.pacCacheScope = cacheScope; + } + + /************************************************************************* + * Gets the search strategy for the platforms default browser. + * + * @return a ProxySearchStrategy, null if no supported browser was found. + ************************************************************************/ + + private ProxySearchStrategy getDefaultBrowserStrategy() { + switch (PlatformUtil.getDefaultBrowser()) { + case IE: + return new IEProxySearchStrategy(); + case FIREFOX: + return new FirefoxProxySearchStrategy(); + } + return null; + } + + /************************************************************************* + * Gets the proxy selector that will use the configured search order. + * + * @return a ProxySelector, null if none was found for the current builder configuration. + ************************************************************************/ + + @Override + public ProxySelector getProxySelector() { + Logger.log(getClass(), LogLevel.TRACE, "Executing search strategies to find proxy selector"); + for (ProxySearchStrategy strat : this.strategies) { + try { + ProxySelector selector = strat.getProxySelector(); + if (selector != null) { + selector = installBufferingAndFallbackBehaviour(selector); + Logger.log(getClass(), LogLevel.INFO, "Proxy found for " + strat.getName()); + + return selector; + } + else { + Logger + .log(getClass(), LogLevel.INFO, "No proxy found for " + strat.getName() + ". Trying next one."); + } + } + catch (ProxyException e) { + Logger.log(getClass(), LogLevel.DEBUG, "Strategy {} failed trying next one.", e); + // Ignore and try next strategy. + } + } + + return null; + } + + /************************************************************************* + * Gets the printable name of the search strategy. + * + * @return the printable name of the search strategy + ************************************************************************/ + + @Override + public String getName() { + return "default"; + } + + /************************************************************************* + * If it is PAC and we have caching enabled set it here. + * + * @param selector + * the proxy selector to wrap + * @return the wrapped proxy selector or the passed in selector if nothing is done. + ************************************************************************/ + + private ProxySelector installBufferingAndFallbackBehaviour(ProxySelector selector) { + if (selector instanceof PacProxySelector) { + if (this.pacCacheSize > 0) { + selector = new BufferedProxySelector(this.pacCacheSize, this.pacCacheTTL, selector, pacCacheScope); + } + selector = new ProxyListFallbackSelector(selector); + } + return selector; + } + + /************************************************************************* + * toString + * + * @see java.lang.Object#toString() + ************************************************************************/ + @Override + public String toString() { + StringBuilder sb = new StringBuilder("Proxy search: "); + for (ProxySearchStrategy strat : this.strategies) { + sb.append(strat); + sb.append(" "); + } + return sb.toString(); + } + + /************************************************************************* + * For testing only. Will print the logging & proxy information to the console. + * + * @param args + * the command line arguments. + ************************************************************************/ + + public static void main(String[] args) { + ProxySearch ps = ProxySearch.getDefaultProxySearch(); + Logger.setBackend(new LogBackEnd() { + + @Override + public void log(Class clazz, LogLevel loglevel, String msg, Object... params) { + System.out.println(MessageFormatter.format(msg, params)); + } + + }); + ps.getProxySelector(); + } } diff --git a/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/FirefoxSettingParser.java b/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/FirefoxSettingParser.java index 73c58b23..bd3c4842 100644 --- a/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/FirefoxSettingParser.java +++ b/src/main/java/com/github/markusbernhardt/proxy/search/browser/firefox/FirefoxSettingParser.java @@ -15,8 +15,7 @@ import com.github.markusbernhardt.proxy.util.Logger.LogLevel; /***************************************************************************** - * Parser for the Firefox settings file. Will extract all relevant proxy - * settings form the configuration file. + * Parser for the Firefox settings file. Will extract all relevant proxy settings form the configuration file. * * @author Markus Bernhardt, Copyright 2016 * @author Bernd Rosstauscher, Copyright 2009 @@ -24,90 +23,118 @@ class FirefoxSettingParser { - /************************************************************************* - * Constructor - ************************************************************************/ - - public FirefoxSettingParser() { - super(); - } - - /************************************************************************* - * Parse the settings file and extract all network.proxy.* settings from it. - * - * @param source - * of the Firefox profiles. - * @return the parsed properties. - * @throws IOException - * on read error. - ************************************************************************/ - - public Properties parseSettings(FirefoxProfileSource source) throws IOException { - File settingsFile = getSettingsFile(source); - - Properties result = new Properties(); - if (settingsFile == null) { - return result; - } - - try (BufferedReader fin = new BufferedReader(new InputStreamReader(new FileInputStream(settingsFile)))) { - String line; - while ((line = fin.readLine()) != null) { - line = line.trim(); - if (line.startsWith("user_pref(\"network.proxy")) { - line = line.substring(10, line.length() - 2); - int index = line.indexOf(","); - String key = removeDoubleQuotes(line.substring(0, index).trim()); - String value = removeDoubleQuotes(line.substring(index + 1).trim()); - result.put(key, value); - } - } - } - - return result; - } - - /** - * Removes leading and trailing double quotes. - * - * @param string - * @return - */ - private String removeDoubleQuotes(String string) { - if (string.startsWith("\"")) { - string = string.substring(1); - } - if (string.endsWith("\"")) { - string = string.substring(0, string.length() - 1); - } - return string; - } - - /** - * Reads the profile.ini, searches for the profiles directory and returns a file - * object pointing to the settings file. - * - * @param source of the Firefox profiles. - * @return {@link File} object pointing to the settings file - * @throws IOException on read error. - */ - private File getSettingsFile(FirefoxProfileSource source) throws IOException { - // Read profiles.ini - File profilesIniFile = source.getProfilesIni(); - if (profilesIniFile.exists()) { - Ini profilesIni = new Ini(profilesIniFile); - for (Entry entry : profilesIni.entrySet()) { - if ("default".equals(entry.getValue().get("Name")) && "1".equals(entry.getValue().get("IsRelative"))) { - File profileFolder = new File(profilesIniFile.getParentFile().getAbsolutePath(), entry.getValue().get("Path")); - Logger.log(getClass(), LogLevel.DEBUG, "Firefox settings folder is {}", profileFolder); - - File settingsFile = new File(profileFolder, "prefs.js"); - return settingsFile; - } - } - } - Logger.log(getClass(), LogLevel.DEBUG, "Firefox settings folder not found!"); - return null; - } + /************************************************************************* + * Constructor + ************************************************************************/ + + public FirefoxSettingParser() { + super(); + } + + /************************************************************************* + * Parse the settings file and extract all network.proxy.* settings from it. + * + * @param source + * of the Firefox profiles. + * @return the parsed properties. + * @throws IOException + * on read error. + ************************************************************************/ + + public Properties parseSettings(FirefoxProfileSource source) throws IOException { + File settingsFile = getSettingsFile(source); + + Properties result = new Properties(); + if (settingsFile == null) { + return result; + } + + try (BufferedReader fin = new BufferedReader(new InputStreamReader(new FileInputStream(settingsFile)))) { + String line; + while ((line = fin.readLine()) != null) { + line = line.trim(); + if (line.startsWith("user_pref(\"network.proxy")) { + line = line.substring(10, line.length() - 2); + int index = line.indexOf(","); + String key = removeDoubleQuotes(line.substring(0, index).trim()); + String value = removeDoubleQuotes(line.substring(index + 1).trim()); + result.put(key, value); + } + } + } + + return result; + } + + /** + * Removes leading and trailing double quotes. + * + * @param string + * @return + */ + private String removeDoubleQuotes(String string) { + if (string.startsWith("\"")) { + string = string.substring(1); + } + if (string.endsWith("\"")) { + string = string.substring(0, string.length() - 1); + } + return string; + } + + /** + * Reads the profile.ini, searches for the profiles directory and returns a file object pointing to the settings + * file. + * + * @param source + * of the Firefox profiles. + * @return {@link File} object pointing to the settings file + * @throws IOException + * on read error. + */ + protected File getSettingsFile(FirefoxProfileSource source) throws IOException { + // Read profiles.ini + File profilesIniFile = source.getProfilesIni(); + if (profilesIniFile.exists()) { + Ini profilesIni = new Ini(profilesIniFile); + + String keyFF67 = + profilesIni.keySet().stream().filter(s -> s.startsWith("Install")).findFirst().orElse(null); + if (keyFF67 != null) { + Logger + .log(getClass(), LogLevel.DEBUG, "Firefox settings for F67+ detected, section key is: {}", keyFF67); + Section section = profilesIni.get(keyFF67); + + if ("1".equals(section.get("Locked"))) { + File profileFolder = + new File(profilesIniFile.getParentFile().getAbsolutePath(), section.get("Default")); + Logger.log(getClass(), LogLevel.DEBUG, "Firefox settings folder is {}", profileFolder); + + File settingsFile = new File(profileFolder, "prefs.js"); + return settingsFile; + } + } + else { + for (Entry entry : profilesIni.entrySet()) { + + Logger + .log(getClass(), LogLevel.TRACE, "Current entry, key: {}, value: {}", entry.getKey(), + entry.getValue()); + + if ("default".equals(entry.getValue().get("Name")) + && "1".equals(entry.getValue().get("IsRelative"))) { + File profileFolder = + new File(profilesIniFile.getParentFile().getAbsolutePath(), entry.getValue().get("Path")); + Logger.log(getClass(), LogLevel.DEBUG, "Firefox settings folder is {}", profileFolder); + + File settingsFile = new File(profileFolder, "prefs.js"); + return settingsFile; + } + } + } + } + Logger.log(getClass(), LogLevel.DEBUG, "Firefox settings folder not found!"); + return null; + } } diff --git a/src/test/java/com/github/markusbernhardt/proxy/search/browser/FirefoxTest.java b/src/test/java/com/github/markusbernhardt/proxy/search/browser/FirefoxTest.java index 8a422d93..1238f42b 100644 --- a/src/test/java/com/github/markusbernhardt/proxy/search/browser/FirefoxTest.java +++ b/src/test/java/com/github/markusbernhardt/proxy/search/browser/FirefoxTest.java @@ -167,4 +167,21 @@ public void testWhiteList() throws ProxyException, URISyntaxException { assertEquals(Proxy.NO_PROXY, result.get(0)); } + /************************************************************************* + * Test method + * + * @throws ProxyException + * on proxy detection error. + * @throws URISyntaxException + * on invalid URL syntax. + ************************************************************************/ + @Test + public void testManualHttpFF67() throws ProxyException, URISyntaxException { + TestUtil.setTestDataFolder("ff67_manual"); + + ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector(); + + List result = ps.select(TestUtil.HTTP_TEST_URI); + assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0)); + } } diff --git a/src/test/java/com/github/markusbernhardt/proxy/selector/pac/PacProxyDebugging.java b/src/test/java/com/github/markusbernhardt/proxy/selector/pac/PacProxyDebugging.java index 7e95cf98..3af7f653 100644 --- a/src/test/java/com/github/markusbernhardt/proxy/selector/pac/PacProxyDebugging.java +++ b/src/test/java/com/github/markusbernhardt/proxy/selector/pac/PacProxyDebugging.java @@ -6,17 +6,16 @@ import java.net.ProxySelector; import java.net.URL; import java.net.URLConnection; -import java.text.MessageFormat; + +import org.slf4j.helpers.MessageFormatter; import com.github.markusbernhardt.proxy.ProxySearch; import com.github.markusbernhardt.proxy.util.Logger; import com.github.markusbernhardt.proxy.util.Logger.LogLevel; /***************************************************************************** - * Test program submitted to test the issue 27 with PAC proxy selector that is - * while downloading the PAC file invoking itself. This has lead to a endless - * loop. The issue is now solved but I keep this test program for future PAC - * testing. + * Test program submitted to test the issue 27 with PAC proxy selector that is while downloading the PAC file invoking + * itself. This has lead to a endless loop. The issue is now solved but I keep this test program for future PAC testing. * * @author Markus Bernhardt, Copyright 2016 * @author Bernd Rosstauscher, Copyright 2009 @@ -24,81 +23,83 @@ public class PacProxyDebugging { - private static final String TEST_URL = "http://www.asetune.com"; - - /************************************************************************* - * Setup a console logger. - ************************************************************************/ - - private void installLogger() { - Logger.setBackend(new Logger.LogBackEnd() { - - public void log(Class clazz, LogLevel loglevel, String msg, Object... params) { - System.out.println(loglevel + "\t" + MessageFormat.format(msg, params)); - } - - }); - } - - /************************************************************************* - * Main entry point for the test application. - * - * @param args - * the command line arguments. - ************************************************************************/ - - public static void main(String[] args) { - // System.setProperty("http.proxyHost", "10.65.12.21"); - // System.setProperty("http.proxyPort", "8080"); - // System.setProperty("java.net.useSystemProxies", "true"); - - PacProxyDebugging pt = new PacProxyDebugging(); - pt.installLogger(); - - ProxySearch proxySearch = ProxySearch.getDefaultProxySearch(); - - // ProxySearch proxySearch = new ProxySearch(); - // proxySearch.addStrategy(Strategy.JAVA); - // proxySearch.addStrategy(Strategy.BROWSER); - // proxySearch.addStrategy(Strategy.OS_DEFAULT); - // proxySearch.addStrategy(Strategy.ENV_VAR); - - ProxySelector myProxySelector = proxySearch.getProxySelector(); - - ProxySelector.setDefault(myProxySelector); - System.out.println("Using proxy selector: " + myProxySelector); - - // String webAddress = "http://www.google.com"; - String webAddress = TEST_URL; - try { - URL url = new URL(webAddress); - // List result = myProxySelector.select(url.toURI()); - // if (result == null || result.size() == 0) - // { - // System.out.println("No proxy found for this url."); - // return; - // } - // System.out.println("Proxy Settings found using 'xxx' strategy.\n" - // + - // "Proxy used for URL is: "+result.get(0)); - - System.out.println("Now open a connection to the url: " + webAddress); - System.out.println("=============================================="); - - // open the connection and prepare it to POST - URLConnection conn = url.openConnection(); - conn.setConnectTimeout(10 * 1000); - - // Return the response - InputStream in = conn.getInputStream(); - LineNumberReader lr = new LineNumberReader(new InputStreamReader(in)); - String line; - while ((line = lr.readLine()) != null) { - System.out.println("response line " + lr.getLineNumber() + ": " + line); - } - System.out.println("---- END -------------------------------------"); - } catch (Exception e) { - e.printStackTrace(); - } - } + private static final String TEST_URL = "http://www.asetune.com"; + + /************************************************************************* + * Setup a console logger. + ************************************************************************/ + + private void installLogger() { + Logger.setBackend(new Logger.LogBackEnd() { + + @Override + public void log(Class clazz, LogLevel loglevel, String msg, Object... params) { + System.out.println(loglevel + "\t" + MessageFormatter.format(msg, params)); + } + + }); + } + + /************************************************************************* + * Main entry point for the test application. + * + * @param args + * the command line arguments. + ************************************************************************/ + + public static void main(String[] args) { + // System.setProperty("http.proxyHost", "10.65.12.21"); + // System.setProperty("http.proxyPort", "8080"); + // System.setProperty("java.net.useSystemProxies", "true"); + + PacProxyDebugging pt = new PacProxyDebugging(); + pt.installLogger(); + + ProxySearch proxySearch = ProxySearch.getDefaultProxySearch(); + + // ProxySearch proxySearch = new ProxySearch(); + // proxySearch.addStrategy(Strategy.JAVA); + // proxySearch.addStrategy(Strategy.BROWSER); + // proxySearch.addStrategy(Strategy.OS_DEFAULT); + // proxySearch.addStrategy(Strategy.ENV_VAR); + + ProxySelector myProxySelector = proxySearch.getProxySelector(); + + ProxySelector.setDefault(myProxySelector); + System.out.println("Using proxy selector: " + myProxySelector); + + // String webAddress = "http://www.google.com"; + String webAddress = TEST_URL; + try { + URL url = new URL(webAddress); + // List result = myProxySelector.select(url.toURI()); + // if (result == null || result.size() == 0) + // { + // System.out.println("No proxy found for this url."); + // return; + // } + // System.out.println("Proxy Settings found using 'xxx' strategy.\n" + // + + // "Proxy used for URL is: "+result.get(0)); + + System.out.println("Now open a connection to the url: " + webAddress); + System.out.println("=============================================="); + + // open the connection and prepare it to POST + URLConnection conn = url.openConnection(); + conn.setConnectTimeout(10 * 1000); + + // Return the response + InputStream in = conn.getInputStream(); + LineNumberReader lr = new LineNumberReader(new InputStreamReader(in)); + String line; + while ((line = lr.readLine()) != null) { + System.out.println("response line " + lr.getLineNumber() + ": " + line); + } + System.out.println("---- END -------------------------------------"); + } + catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/src/test/resources/ff67_manual/.mozilla/firefox/bk6on8rm.default-release/prefs.js b/src/test/resources/ff67_manual/.mozilla/firefox/bk6on8rm.default-release/prefs.js new file mode 100644 index 00000000..568d96e3 --- /dev/null +++ b/src/test/resources/ff67_manual/.mozilla/firefox/bk6on8rm.default-release/prefs.js @@ -0,0 +1,76 @@ +# Mozilla User Preferences + +/* Do not edit this file. + * + * If you make changes to this file while the application is running, + * the changes will be overwritten when the application exits. + * + * To make a manual change to preferences, you can visit the URL about:config + * For more information, see http://www.mozilla.org/unix/customizing.html#prefs + */ + +user_pref("accessibility.typeaheadfind.flashBar", 0); +user_pref("app.update.auto", false); +user_pref("app.update.lastUpdateTime.addon-background-update-timer", 1243108090); +user_pref("app.update.lastUpdateTime.background-update-timer", 1243108090); +user_pref("app.update.lastUpdateTime.blocklist-background-update-timer", 1243108090); +user_pref("app.update.lastUpdateTime.microsummary-generator-update-timer", 1242676783); +user_pref("app.update.lastUpdateTime.search-engine-update-timer", 1243156646); +user_pref("browser.download.dir", "/home/rossi/Downloads"); +user_pref("browser.download.folderList", 2); +user_pref("browser.download.lastDir", "/home/rossi/Dokumente"); +user_pref("browser.download.save_converter_index", 0); +user_pref("browser.feeds.showFirstRunUI", false); +user_pref("browser.history_expire_days.mirror", 180); +user_pref("browser.history_expire_days_min", 3); +user_pref("browser.migration.version", 1); +user_pref("browser.places.importBookmarksHTML", false); +user_pref("browser.places.importDefaults", false); +user_pref("browser.places.leftPaneFolderId", -1); +user_pref("browser.places.migratePostDataAnnotations", false); +user_pref("browser.places.smartBookmarksVersion", 1); +user_pref("browser.places.updateRecentTagsUri", false); +user_pref("browser.preferences.advanced.selectedTabIndex", 1); +user_pref("browser.rights.3.shown", true); +user_pref("browser.startup.homepage_override.mstone", "rv:1.9.0.10"); +user_pref("browser.startup.page", 0); +user_pref("capability.policy.maonoscript.javascript.enabled", "allAccess"); +user_pref("capability.policy.maonoscript.sites", "addons.mozilla.org cineplex.de flashgot.net google.com googlesyndication.com hotmail.com informaction.com live.com maone.net msn.com noscript.net passport.com passport.net passportimages.com yahoo.com yimg.com about: about:blank about:certerror about:config about:credits about:neterror about:plugins about:privatebrowsing about:sessionrestore chrome: file://cineplex.de file://flashgot.net file://google.com file://googlesyndication.com file://hotmail.com file://informaction.com file://live.com file://maone.net file://msn.com file://noscript.net file://passport.com file://passport.net file://passportimages.com file://yahoo.com file://yimg.com http://cineplex.de http://flashgot.net http://google.com http://googlesyndication.com http://hotmail.com http://informaction.com http://live.com http://maone.net http://msn.com http://noscript.net http://passport.com http://passport.net http://passportimages.com http://yahoo.com http://yimg.com https://cineplex.de https://flashgot.net https://google.com https://googlesyndication.com https://hotmail.com https://informaction.com https://live.com https://maone.net https://msn.com https://noscript.net https://passport.com https://passport.net https://passportimages.com https://yahoo.com https://yimg.com resource:"); +user_pref("distribution.canonical.bookmarksProcessed", true); +user_pref("dom.disable_window_move_resize", true); +user_pref("dom.event.contextmenu.enabled", false); +user_pref("extensions.adblockplus.currentVersion", "1.0.2"); +user_pref("extensions.enabledItems", "{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}:1.0.2,langpack-de@firefox-3.0.ubuntu.com:3.0.7,langpack-en-GB@firefox-3.0.ubuntu.com:3.0.7,{73a6fe31-595d-460b-a920-fcc0f8843232}:1.9.2.8,langpack-de@xulrunner-1.9.ubuntu.com:1.9.0.8,langpack-en-GB@xulrunner-1.9.ubuntu.com:1.9.0.8,{972ce4c6-7e08-4474-a285-3208198ce6fd}:3.0.10"); +user_pref("extensions.lastAppVersion", "3.0.10"); +user_pref("extensions.update.notifyUser", false); +user_pref("intl.charsetmenu.browser.cache", "us-ascii, ISO-8859-15, ISO-8859-1, UTF-8, windows-1252"); +user_pref("javascript.enabled", true); +user_pref("network.cookie.lifetimePolicy", 2); +user_pref("network.cookie.prefsMigrated", true); +user_pref("network.proxy.autoconfig_url", "http://www.xxx.de/"); +user_pref("network.proxy.ftp", "ftp_proxy.unit-test.invalid"); +user_pref("network.proxy.ftp_port", 8092); +user_pref("network.proxy.gopher", "gopher_proxy.unit-test.invalid"); +user_pref("network.proxy.gopher_port", 8093); +user_pref("network.proxy.http", "http_proxy.unit-test.invalid"); +user_pref("network.proxy.http_port", 8090); +user_pref("network.proxy.socks", "socks_proxy.unit-test.invalid"); +user_pref("network.proxy.socks_port", 8095); +user_pref("network.proxy.socks_version", 4); +user_pref("network.proxy.ssl", "https_proxy.unit-test.invalid"); +user_pref("network.proxy.ssl_port", 8091); +user_pref("network.proxy.type", 1); +user_pref("noscript.badInstall", false); +user_pref("noscript.global", true); +user_pref("noscript.gtemp", ""); +user_pref("noscript.notify", false); +user_pref("noscript.options.tabSelectedIndexes", "5,4,1"); +user_pref("noscript.policynames", ""); +user_pref("noscript.temp", ""); +user_pref("noscript.version", "1.9.2.8"); +user_pref("pref.advanced.javascript.disable_button.advanced", false); +user_pref("pref.downloads.disable_button.edit_actions", false); +user_pref("privacy.item.offlineApps", true); +user_pref("signon.rememberSignons", false); +user_pref("spellchecker.dictionary", "de_AT"); +user_pref("urlclassifier.keyupdatetime.https://sb-ssl.google.com/safebrowsing/newkey", 1243725238); diff --git a/src/test/resources/ff67_manual/.mozilla/firefox/p6y3k23k.default/prefs.js b/src/test/resources/ff67_manual/.mozilla/firefox/p6y3k23k.default/prefs.js new file mode 100644 index 00000000..fb2ac9e3 --- /dev/null +++ b/src/test/resources/ff67_manual/.mozilla/firefox/p6y3k23k.default/prefs.js @@ -0,0 +1,76 @@ +# Mozilla User Preferences + +/* Do not edit this file. + * + * If you make changes to this file while the application is running, + * the changes will be overwritten when the application exits. + * + * To make a manual change to preferences, you can visit the URL about:config + * For more information, see http://www.mozilla.org/unix/customizing.html#prefs + */ + +user_pref("accessibility.typeaheadfind.flashBar", 0); +user_pref("app.update.auto", false); +user_pref("app.update.lastUpdateTime.addon-background-update-timer", 1243108090); +user_pref("app.update.lastUpdateTime.background-update-timer", 1243108090); +user_pref("app.update.lastUpdateTime.blocklist-background-update-timer", 1243108090); +user_pref("app.update.lastUpdateTime.microsummary-generator-update-timer", 1242676783); +user_pref("app.update.lastUpdateTime.search-engine-update-timer", 1243156646); +user_pref("browser.download.dir", "/home/rossi/Downloads"); +user_pref("browser.download.folderList", 2); +user_pref("browser.download.lastDir", "/home/rossi/Dokumente"); +user_pref("browser.download.save_converter_index", 0); +user_pref("browser.feeds.showFirstRunUI", false); +user_pref("browser.history_expire_days.mirror", 180); +user_pref("browser.history_expire_days_min", 3); +user_pref("browser.migration.version", 1); +user_pref("browser.places.importBookmarksHTML", false); +user_pref("browser.places.importDefaults", false); +user_pref("browser.places.leftPaneFolderId", -1); +user_pref("browser.places.migratePostDataAnnotations", false); +user_pref("browser.places.smartBookmarksVersion", 1); +user_pref("browser.places.updateRecentTagsUri", false); +user_pref("browser.preferences.advanced.selectedTabIndex", 1); +user_pref("browser.rights.3.shown", true); +user_pref("browser.startup.homepage_override.mstone", "rv:1.9.0.10"); +user_pref("browser.startup.page", 0); +user_pref("capability.policy.maonoscript.javascript.enabled", "allAccess"); +user_pref("capability.policy.maonoscript.sites", "addons.mozilla.org cineplex.de flashgot.net google.com googlesyndication.com hotmail.com informaction.com live.com maone.net msn.com noscript.net passport.com passport.net passportimages.com yahoo.com yimg.com about: about:blank about:certerror about:config about:credits about:neterror about:plugins about:privatebrowsing about:sessionrestore chrome: file://cineplex.de file://flashgot.net file://google.com file://googlesyndication.com file://hotmail.com file://informaction.com file://live.com file://maone.net file://msn.com file://noscript.net file://passport.com file://passport.net file://passportimages.com file://yahoo.com file://yimg.com http://cineplex.de http://flashgot.net http://google.com http://googlesyndication.com http://hotmail.com http://informaction.com http://live.com http://maone.net http://msn.com http://noscript.net http://passport.com http://passport.net http://passportimages.com http://yahoo.com http://yimg.com https://cineplex.de https://flashgot.net https://google.com https://googlesyndication.com https://hotmail.com https://informaction.com https://live.com https://maone.net https://msn.com https://noscript.net https://passport.com https://passport.net https://passportimages.com https://yahoo.com https://yimg.com resource:"); +user_pref("distribution.canonical.bookmarksProcessed", true); +user_pref("dom.disable_window_move_resize", true); +user_pref("dom.event.contextmenu.enabled", false); +user_pref("extensions.adblockplus.currentVersion", "1.0.2"); +user_pref("extensions.enabledItems", "{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}:1.0.2,langpack-de@firefox-3.0.ubuntu.com:3.0.7,langpack-en-GB@firefox-3.0.ubuntu.com:3.0.7,{73a6fe31-595d-460b-a920-fcc0f8843232}:1.9.2.8,langpack-de@xulrunner-1.9.ubuntu.com:1.9.0.8,langpack-en-GB@xulrunner-1.9.ubuntu.com:1.9.0.8,{972ce4c6-7e08-4474-a285-3208198ce6fd}:3.0.10"); +user_pref("extensions.lastAppVersion", "3.0.10"); +user_pref("extensions.update.notifyUser", false); +user_pref("intl.charsetmenu.browser.cache", "us-ascii, ISO-8859-15, ISO-8859-1, UTF-8, windows-1252"); +user_pref("javascript.enabled", true); +user_pref("network.cookie.lifetimePolicy", 2); +user_pref("network.cookie.prefsMigrated", true); +user_pref("network.proxy.autoconfig_url", "http://www.xxx.de/"); +user_pref("network.proxy.ftp", "ftp_proxy.unit-test.invalid"); +user_pref("network.proxy.ftp_port", 8092); +user_pref("network.proxy.gopher", "gopher_proxy.unit-test.invalid"); +user_pref("network.proxy.gopher_port", 8093); +user_pref("network.proxy.http", "http_proxy.unit-test.invalid-wrong"); +user_pref("network.proxy.http_port", 8090); +user_pref("network.proxy.socks", "socks_proxy.unit-test.invalid"); +user_pref("network.proxy.socks_port", 8095); +user_pref("network.proxy.socks_version", 4); +user_pref("network.proxy.ssl", "https_proxy.unit-test.invalid"); +user_pref("network.proxy.ssl_port", 8091); +user_pref("network.proxy.type", 1); +user_pref("noscript.badInstall", false); +user_pref("noscript.global", true); +user_pref("noscript.gtemp", ""); +user_pref("noscript.notify", false); +user_pref("noscript.options.tabSelectedIndexes", "5,4,1"); +user_pref("noscript.policynames", ""); +user_pref("noscript.temp", ""); +user_pref("noscript.version", "1.9.2.8"); +user_pref("pref.advanced.javascript.disable_button.advanced", false); +user_pref("pref.downloads.disable_button.edit_actions", false); +user_pref("privacy.item.offlineApps", true); +user_pref("signon.rememberSignons", false); +user_pref("spellchecker.dictionary", "de_AT"); +user_pref("urlclassifier.keyupdatetime.https://sb-ssl.google.com/safebrowsing/newkey", 1243725238); diff --git a/src/test/resources/ff67_manual/.mozilla/firefox/profiles.ini b/src/test/resources/ff67_manual/.mozilla/firefox/profiles.ini new file mode 100644 index 00000000..5574e42f --- /dev/null +++ b/src/test/resources/ff67_manual/.mozilla/firefox/profiles.ini @@ -0,0 +1,20 @@ +[Install4F96D1932A9F858E] +Default=bk6on8rm.default-release +Locked=1 + +[Profile1] +Name=default +IsRelative=1 +Path=p6y3k23k.default +Default=1 + +[Profile0] +Name=default-release +IsRelative=1 +Path=bk6on8rm.default-release + +[General] +StartWithLastProfile=1 +Version=2 + +