From 1677a377dcb50e146629030ebd27fdb25aa579a0 Mon Sep 17 00:00:00 2001 From: Rynat Sibahatau Date: Sat, 15 Jun 2019 19:01:10 -0400 Subject: [PATCH] Remove capability to load cookies from file --- lighthouse-cli/bin.js | 10 ++++------ lighthouse-cli/test/cli/bin-test.js | 9 +++------ lighthouse-cli/test/cli/index-test.js | 9 --------- lighthouse-cli/test/fixtures/extra-cookies/invalid.txt | 1 - lighthouse-cli/test/fixtures/extra-cookies/valid.json | 7 ------- 5 files changed, 7 insertions(+), 29 deletions(-) delete mode 100644 lighthouse-cli/test/fixtures/extra-cookies/invalid.txt delete mode 100644 lighthouse-cli/test/fixtures/extra-cookies/valid.json diff --git a/lighthouse-cli/bin.js b/lighthouse-cli/bin.js index 6278b7d24c4c..ed385963a7bd 100644 --- a/lighthouse-cli/bin.js +++ b/lighthouse-cli/bin.js @@ -128,13 +128,11 @@ async function begin() { // the conversion here, but long term either the CLI flag or the setting should have // a different name. // @ts-ignore - let extraCookiesStr = /** @type {string} */ (cliFlags.extraCookies); - // If not a JSON array, assume it's a path to a JSON file. - if (extraCookiesStr.substr(0, 1) !== '[') { - extraCookiesStr = fs.readFileSync(extraCookiesStr, 'utf-8'); - } - + const extraCookiesStr = /** @type {string} */ (cliFlags.extraCookies); cliFlags.extraCookies = JSON.parse(extraCookiesStr); + if (!Array.isArray(cliFlags.extraCookies)) { + throw new Error('extraCookies parameter must be a valid JSON array'); + } } if (cliFlags.precomputedLanternDataPath) { diff --git a/lighthouse-cli/test/cli/bin-test.js b/lighthouse-cli/test/cli/bin-test.js index d5708fab11d6..2f03d4967ae8 100644 --- a/lighthouse-cli/test/cli/bin-test.js +++ b/lighthouse-cli/test/cli/bin-test.js @@ -179,13 +179,10 @@ describe('CLI bin', function() { expect(getRunLighthouseArgs()[1]).toHaveProperty('extraCookies', [{'name': 'foo', 'value': 'bar', 'url': 'http://localhost'}]); }); - it('should read extra cookies from file', async () => { - const headersFile = require.resolve('../fixtures/extra-cookies/valid.json'); + it('should throw when invalid array is used', async () => { // @ts-ignore - see TODO: in bin.js - cliFlags = {...cliFlags, extraCookies: headersFile}; - await bin.begin(); - - expect(getRunLighthouseArgs()[1]).toHaveProperty('extraCookies', require(headersFile)); + cliFlags = {...cliFlags, extraCookies: 'INVALID_JSON_ARRAY'}; + await expect(bin.begin()).rejects.toBeTruthy(); }); }); diff --git a/lighthouse-cli/test/cli/index-test.js b/lighthouse-cli/test/cli/index-test.js index b4f46ab92a70..11d31388b313 100644 --- a/lighthouse-cli/test/cli/index-test.js +++ b/lighthouse-cli/test/cli/index-test.js @@ -59,15 +59,6 @@ describe('CLI Tests', function() { assert.equal(ret.status, 1); }); - it('should exit with a error if the file does not contain valid JSON', () => { - const ret = spawnSync('node', [indexPath, 'https://www.google.com', - '--extra-cookies', - path.resolve(__dirname, '../fixtures/extra-cookies/invalid.txt')], {encoding: 'utf8'}); - - assert.ok(ret.stderr.includes('Unexpected token')); - assert.equal(ret.status, 1); - }); - it('should exit with a error if the passsed in string is not valid JSON', () => { const ret = spawnSync('node', [indexPath, 'https://www.google.com', '--extra-headers', '{notjson}'], {encoding: 'utf8'}); diff --git a/lighthouse-cli/test/fixtures/extra-cookies/invalid.txt b/lighthouse-cli/test/fixtures/extra-cookies/invalid.txt deleted file mode 100644 index cfd9a1e3a781..000000000000 --- a/lighthouse-cli/test/fixtures/extra-cookies/invalid.txt +++ /dev/null @@ -1 +0,0 @@ -NotJSON diff --git a/lighthouse-cli/test/fixtures/extra-cookies/valid.json b/lighthouse-cli/test/fixtures/extra-cookies/valid.json deleted file mode 100644 index 1e404b985004..000000000000 --- a/lighthouse-cli/test/fixtures/extra-cookies/valid.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "name":"test", - "value":"true", - "url":"http://localhost" - } -]