From a7be1f5a1c91665d5ac6dba2ae5ad3ddeb5dead8 Mon Sep 17 00:00:00 2001 From: Lampei Date: Tue, 27 Aug 2019 09:35:30 -0400 Subject: [PATCH 1/7] changed the get latest chromedriver to use the URL getting the latest first, then downloading that specific version. --- lib/binaries/chrome_xml.ts | 44 ++++++-------------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index e79063fc..8cb33614 100644 --- a/lib/binaries/chrome_xml.ts +++ b/lib/binaries/chrome_xml.ts @@ -5,6 +5,8 @@ import {Config} from '../config'; import {BinaryUrl} from './binary'; import {XmlConfigSource} from './config_source'; +import {request} from '../utils'; + export class ChromeXml extends XmlConfigSource { maxVersion = Config.binaryVersions().maxChrome; @@ -62,43 +64,11 @@ export class ChromeXml extends XmlConfigSource { * Gets the latest item from the XML. */ private getLatestChromeDriverVersion(): Promise { - return this.getVersionList().then(list => { - let chromedriverVersion: string = null; - let latest = ''; - let latestVersion = ''; - for (let item of list) { - // Get a semantic version - const version = item.split('/')[0]; - if (semver.valid(version) == null) { - const iterVersion = getValidSemver(version); - - if (!semver.valid(iterVersion)) { - throw new Error('invalid Chromedriver version'); - } - // First time: use the version found. - if (chromedriverVersion == null) { - chromedriverVersion = iterVersion; - latest = item; - latestVersion = item.split('/')[0]; - } else if ( - iterVersion.startsWith(this.maxVersion) && - semver.gt(iterVersion, chromedriverVersion)) { - // After the first time, make sure the semantic version is greater. - chromedriverVersion = iterVersion; - latest = item; - latestVersion = item.split('/')[0]; - } else if (iterVersion === chromedriverVersion) { - // If the semantic version is the same, check os arch. - // For 64-bit systems, prefer the 64-bit version. - if (this.osarch === 'x64') { - if (item.includes(this.getOsTypeName() + '64')) { - latest = item; - } - } - } - } - } - return {url: Config.cdnUrls().chrome + latest, version: latestVersion}; + const latestReleaseUrl = + 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE_'; + const downloadUrlVersion = `${latestReleaseUrl}${this.maxVersion}`; + return request('GET', '80', downloadUrlVersion).then(latestVersion => { + return this.getSpecificChromeDriverVersion(latestVersion); }); } From 3c7543f97b2d4681c31688e9e685858a6048b1c0 Mon Sep 17 00:00:00 2001 From: Lampei Date: Tue, 27 Aug 2019 09:41:54 -0400 Subject: [PATCH 2/7] removed unused imports. Trimmed blank lines between import statements --- lib/binaries/chrome_xml.ts | 3 --- spec/binaries/chrome_xml_spec.ts | 1 - spec/binaries/standalone_xml_spec.ts | 1 - spec/cmds/status_spec.ts | 1 - spec/cmds/update_spec.ts | 1 - spec/files/downloader_spec.ts | 2 -- 6 files changed, 9 deletions(-) diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index 8cb33614..5fd53e90 100644 --- a/lib/binaries/chrome_xml.ts +++ b/lib/binaries/chrome_xml.ts @@ -1,10 +1,7 @@ import * as semver from 'semver'; - import {Config} from '../config'; - import {BinaryUrl} from './binary'; import {XmlConfigSource} from './config_source'; - import {request} from '../utils'; export class ChromeXml extends XmlConfigSource { diff --git a/spec/binaries/chrome_xml_spec.ts b/spec/binaries/chrome_xml_spec.ts index a607d089..5a8ab8a7 100644 --- a/spec/binaries/chrome_xml_spec.ts +++ b/spec/binaries/chrome_xml_spec.ts @@ -1,7 +1,6 @@ import * as path from 'path'; import * as rimraf from 'rimraf'; import {ChromeXml} from '../../lib/binaries/chrome_xml'; -import {Config} from '../../lib/config'; describe('chrome xml reader', () => { let out_dir = path.resolve('selenium_test'); diff --git a/spec/binaries/standalone_xml_spec.ts b/spec/binaries/standalone_xml_spec.ts index 101e946c..adba4095 100644 --- a/spec/binaries/standalone_xml_spec.ts +++ b/spec/binaries/standalone_xml_spec.ts @@ -1,7 +1,6 @@ import * as path from 'path'; import * as rimraf from 'rimraf'; import {StandaloneXml} from '../../lib/binaries/standalone_xml'; -import {Config} from '../../lib/config'; describe('standalone xml reader', () => { let out_dir = path.resolve('selenium_test'); diff --git a/spec/cmds/status_spec.ts b/spec/cmds/status_spec.ts index 9c1a987b..ffd28b3a 100644 --- a/spec/cmds/status_spec.ts +++ b/spec/cmds/status_spec.ts @@ -2,7 +2,6 @@ import * as path from 'path'; import {Logger, WriteTo} from '../../lib/cli/logger'; import {program} from '../../lib/cmds/update'; -import {Config} from '../../lib/config'; import {spawnSync} from '../../lib/utils'; function getVersions(line: string): string[] { diff --git a/spec/cmds/update_spec.ts b/spec/cmds/update_spec.ts index 3aad559a..90e8a7f5 100644 --- a/spec/cmds/update_spec.ts +++ b/spec/cmds/update_spec.ts @@ -1,6 +1,5 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as process from 'process'; import * as rimraf from 'rimraf'; import {Logger, WriteTo} from '../../lib/cli/logger'; diff --git a/spec/files/downloader_spec.ts b/spec/files/downloader_spec.ts index faa134ad..622481a2 100644 --- a/spec/files/downloader_spec.ts +++ b/spec/files/downloader_spec.ts @@ -2,9 +2,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as rimraf from 'rimraf'; -import {Config} from '../../lib/config'; import {Downloader} from '../../lib/files'; -import {HttpUtils} from '../../lib/http_utils'; describe('downloader', () => { describe('get file', () => { From c7df714e7ae461a51f8b2abb7962cc33e31ff1c8 Mon Sep 17 00:00:00 2001 From: Lampei Date: Tue, 27 Aug 2019 13:09:01 -0400 Subject: [PATCH 3/7] added way to download latest release for chrome --- lib/binaries/chrome_xml.ts | 4 ++-- lib/http_utils.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index 5fd53e90..0f9bad28 100644 --- a/lib/binaries/chrome_xml.ts +++ b/lib/binaries/chrome_xml.ts @@ -2,7 +2,7 @@ import * as semver from 'semver'; import {Config} from '../config'; import {BinaryUrl} from './binary'; import {XmlConfigSource} from './config_source'; -import {request} from '../utils'; +import {requestBody} from "../http_utils"; export class ChromeXml extends XmlConfigSource { maxVersion = Config.binaryVersions().maxChrome; @@ -64,7 +64,7 @@ export class ChromeXml extends XmlConfigSource { const latestReleaseUrl = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE_'; const downloadUrlVersion = `${latestReleaseUrl}${this.maxVersion}`; - return request('GET', '80', downloadUrlVersion).then(latestVersion => { + return requestBody(downloadUrlVersion).then(latestVersion => { return this.getSpecificChromeDriverVersion(latestVersion); }); } diff --git a/lib/http_utils.ts b/lib/http_utils.ts index 31528c3e..aa62980e 100644 --- a/lib/http_utils.ts +++ b/lib/http_utils.ts @@ -3,6 +3,7 @@ import * as url from 'url'; import {Logger} from './cli/logger'; import {Config} from './config'; +import * as request from 'request'; let logger = new Logger('http_utils'); @@ -96,4 +97,36 @@ export class HttpUtils { } return undefined; } + +} + +/** +* Request the body from the url. +* @param requestUrl The request url. +* @returns A promise string of the response body. +*/ +export function requestBody( + requestUrl: string): Promise { + const options = HttpUtils.initOptions(requestUrl); + options.followRedirect = true; + return new Promise((resolve, reject) => { + const req = request(options); + req.on('response', response => { + if (response.statusCode === 200) { + let output = ''; + response.on('data', (data) => { + output += data; + }); + response.on('end', () => { + resolve(output); + }); + } else { + reject(new Error('response status code is not 200')); + } + }); + req.on('error', error => { + reject(error); + }); + }); } + From c30e94a75ba605582c3f9624203b985b9dcc53c7 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Sat, 14 Sep 2019 00:31:28 -0700 Subject: [PATCH 4/7] Remove extra underscore --- lib/binaries/chrome_xml.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index 0f9bad28..9064dfef 100644 --- a/lib/binaries/chrome_xml.ts +++ b/lib/binaries/chrome_xml.ts @@ -62,7 +62,7 @@ export class ChromeXml extends XmlConfigSource { */ private getLatestChromeDriverVersion(): Promise { const latestReleaseUrl = - 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE_'; + 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE'; const downloadUrlVersion = `${latestReleaseUrl}${this.maxVersion}`; return requestBody(downloadUrlVersion).then(latestVersion => { return this.getSpecificChromeDriverVersion(latestVersion); From a92ea888d9bb51a7ce86df331470245b47d70f26 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Mon, 16 Sep 2019 11:54:55 -0700 Subject: [PATCH 5/7] Fix: latest version is just the version number Also update import order --- lib/binaries/chrome_xml.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index 9064dfef..3ab6fca8 100644 --- a/lib/binaries/chrome_xml.ts +++ b/lib/binaries/chrome_xml.ts @@ -1,8 +1,10 @@ import * as semver from 'semver'; + import {Config} from '../config'; +import {requestBody} from '../http_utils'; + import {BinaryUrl} from './binary'; import {XmlConfigSource} from './config_source'; -import {requestBody} from "../http_utils"; export class ChromeXml extends XmlConfigSource { maxVersion = Config.binaryVersions().maxChrome; @@ -61,10 +63,8 @@ export class ChromeXml extends XmlConfigSource { * Gets the latest item from the XML. */ private getLatestChromeDriverVersion(): Promise { - const latestReleaseUrl = - 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE'; - const downloadUrlVersion = `${latestReleaseUrl}${this.maxVersion}`; - return requestBody(downloadUrlVersion).then(latestVersion => { + const latestReleaseUrl = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE'; + return requestBody(latestReleaseUrl).then(latestVersion => { return this.getSpecificChromeDriverVersion(latestVersion); }); } From ccb50d0011be8a815c6746436028a9551840aafe Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Mon, 16 Sep 2019 11:55:25 -0700 Subject: [PATCH 6/7] Update import order --- lib/http_utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http_utils.ts b/lib/http_utils.ts index aa62980e..9a0c9e4e 100644 --- a/lib/http_utils.ts +++ b/lib/http_utils.ts @@ -1,9 +1,9 @@ +import * as request from 'request'; import {OptionsWithUrl} from 'request'; import * as url from 'url'; import {Logger} from './cli/logger'; import {Config} from './config'; -import * as request from 'request'; let logger = new Logger('http_utils'); From 5e57f61ad18f97221b347af21822683ebce33484 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Mon, 16 Sep 2019 11:55:41 -0700 Subject: [PATCH 7/7] Update import order