Skip to content

Commit

Permalink
webdrivers: use correct arch, prepare release
Browse files Browse the repository at this point in the history
Change `DownloadWebDriver` to use a custom `FirefoxDriverManager` to
ignore cached binaries of different architecture than the one being
requested, affects only geckodriver which has 32/64bits binaries for
Linux and Windows.
Update WebDriverManager to latest version.
Add release dates and links to tags.

Fix zaproxy/zaproxy#5763 - WebDriver add-ons might bundle binaries with
incorrect architecture

Signed-off-by: thc202 <thc202@gmail.com>
  • Loading branch information
thc202 committed Dec 16, 2019
1 parent b16859a commit dffccfd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
6 changes: 4 additions & 2 deletions addOns/webdrivers/webdriverlinux/CHANGELOG.md
Expand Up @@ -3,8 +3,9 @@ All notable changes to this add-on will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

## [15] - 2019-12-16
### Fixed
- Bundle correct geckodriver binary for respective architecture (Issue 5763).

## [14] - 2019-12-12
### Changed
Expand Down Expand Up @@ -76,6 +77,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- First release: Firefox v0.13.0 Chrome v2.27

[15]: https://github.com/zaproxy/zap-extensions/releases/webdriverlinux-v15
[14]: https://github.com/zaproxy/zap-extensions/releases/webdriverlinux-v14
[13]: https://github.com/zaproxy/zap-extensions/releases/webdriverlinux-v13
[12]: https://github.com/zaproxy/zap-extensions/releases/webdriverlinux-v12
Expand Down
6 changes: 4 additions & 2 deletions addOns/webdrivers/webdriverwindows/CHANGELOG.md
Expand Up @@ -3,8 +3,9 @@ All notable changes to this add-on will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

## [15] - 2019-12-16
### Fixed
- Bundle correct geckodriver binary for respective architecture (Issue 5763).

## [14] - 2019-12-12
### Changed
Expand Down Expand Up @@ -79,6 +80,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- First release: Firefox v0.13.0 Chrome v2.27 IE 3.0.0

[15]: https://github.com/zaproxy/zap-extensions/releases/webdriverwindows-v15
[14]: https://github.com/zaproxy/zap-extensions/releases/webdriverwindows-v14
[13]: https://github.com/zaproxy/zap-extensions/releases/webdriverwindows-v13
[12]: https://github.com/zaproxy/zap-extensions/releases/webdriverwindows-v12
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Expand Up @@ -24,7 +24,7 @@ tasks.withType<JavaCompile>().configureEach {
}

dependencies {
implementation("io.github.bonigarcia:webdrivermanager:3.3.0")
implementation("io.github.bonigarcia:webdrivermanager:3.7.1")
implementation("com.diffplug.spotless:spotless-plugin-gradle:3.20.0")
}

Expand Down
Expand Up @@ -21,6 +21,7 @@

import io.github.bonigarcia.wdm.Architecture;
import io.github.bonigarcia.wdm.DriverManagerType;
import io.github.bonigarcia.wdm.FirefoxDriverManager;
import io.github.bonigarcia.wdm.OperatingSystem;
import io.github.bonigarcia.wdm.WebDriverManager;
import java.io.IOException;
Expand All @@ -29,6 +30,7 @@
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Locale;
import java.util.Optional;
import javax.inject.Inject;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.RegularFileProperty;
Expand Down Expand Up @@ -144,7 +146,7 @@ public Download(

@Override
public void run() {
WebDriverManager wdm = WebDriverManager.getInstance(browser);
WebDriverManager wdm = getInstance(browser);
wdm.forceCache()
.avoidPreferences()
.avoidExport()
Expand All @@ -168,5 +170,47 @@ public void run() {
e);
}
}

private static WebDriverManager getInstance(DriverManagerType browser) {
switch (browser) {
case CHROME:
return WebDriverManager.chromedriver();
case FIREFOX:
return new FirefoxDriverManagerCustom();
default:
throw new UnsupportedOperationException(
"Only Chrome and Firefox are currently supported.");
}
}

private static class FirefoxDriverManagerCustom extends FirefoxDriverManager {

FirefoxDriverManagerCustom() {
instanceMap.put(DriverManagerType.FIREFOX, this);
}

@Override
protected Optional<String> getDriverFromCache(
String driverVersion, Architecture arch, String os) {
Optional<String> driver = super.getDriverFromCache(driverVersion, arch, os);
if (isRequestedArch(driver, os, arch)) {
return driver;
}
return Optional.empty();
}

private static boolean isRequestedArch(
Optional<String> driver, String os, Architecture arch) {
// macOS has only one geckodriver binary.
if ("MAC".equals(os)) {
return true;
}

return driver.isPresent()
&& driver.get()
.toLowerCase()
.contains(os.toLowerCase() + arch.toString().toLowerCase());
}
}
}
}

0 comments on commit dffccfd

Please sign in to comment.