From 0083cf14f1d0429c9ee5617b43806cb8c6a526f8 Mon Sep 17 00:00:00 2001 From: Elbert Alias <77259+AliasIO@users.noreply.github.com> Date: Fri, 29 Jun 2018 13:34:41 +1000 Subject: [PATCH] Add support for basic auth in NPM driver --- src/drivers/npm/README.md | 7 +++++-- src/drivers/npm/driver.js | 13 ++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/drivers/npm/README.md b/src/drivers/npm/README.md index a661bb198..8d7ea19f8 100644 --- a/src/drivers/npm/README.md +++ b/src/drivers/npm/README.md @@ -27,16 +27,19 @@ node index.js [url] [options] ### Options ``` + --password Password to be used for basic HTTP authentication + --proxy Proxy URL, e.g. 'http://user:pass@proxy:8080' + --username Username to be used for basic HTTP authentication --chunk-size=num Process links in chunks. --debug=0|1 Output debug messages. --delay=ms Wait for ms milliseconds between requests. + --html-max-cols=num Limit the number of HTML characters per line processed. + --html-max-rows=num Limit the number of HTML lines processed. --max-depth=num Don't analyse pages more than num levels deep. --max-urls=num Exit when num URLs have been analysed. --max-wait=ms Wait no more than ms milliseconds for page resources to load. --recursive=0|1 Follow links on pages (crawler). --user-agent=str Set the user agent string. - --html-max-cols=num Limit the number of HTML characters per line processed. - --html-max-rows=num Limit the number of HTML lines processed. ``` diff --git a/src/drivers/npm/driver.js b/src/drivers/npm/driver.js index 9e8f13dce..37cb80701 100644 --- a/src/drivers/npm/driver.js +++ b/src/drivers/npm/driver.js @@ -13,17 +13,19 @@ const extensions = /^([^.]+$|\.(asp|aspx|cgi|htm|html|jsp|php)$)/; class Driver { constructor(pageUrl, options) { this.options = Object.assign({}, { + password: '', + proxy: null, + username: '', chunkSize: 5, debug: false, delay: 500, + htmlMaxCols: 2000, + htmlMaxRows: 3000, maxDepth: 3, maxUrls: 10, maxWait: 5000, - proxy: null, recursive: false, userAgent: 'Mozilla/5.0 (compatible; Wappalyzer)', - htmlMaxCols: 2000, - htmlMaxRows: 3000, }, options || {}); this.options.debug = Boolean(+this.options.debug); @@ -121,6 +123,11 @@ class Driver { waitDuration: this.options.maxWait, }); + browser.on('authenticate', auth => { + auth.username = this.options.username; + auth.password = this.options.password; + }); + this.timer('browser.visit start; url: ' + pageUrl.href, timerScope); browser.visit(pageUrl.href, () => {