Skip to content

Commit

Permalink
Remove capability to load cookies from file
Browse files Browse the repository at this point in the history
  • Loading branch information
RynatSibahatau committed Jun 15, 2019
1 parent 2e1365b commit 1677a37
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 29 deletions.
10 changes: 4 additions & 6 deletions lighthouse-cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 3 additions & 6 deletions lighthouse-cli/test/cli/bin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down
9 changes: 0 additions & 9 deletions lighthouse-cli/test/cli/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
Expand Down
1 change: 0 additions & 1 deletion lighthouse-cli/test/fixtures/extra-cookies/invalid.txt

This file was deleted.

7 changes: 0 additions & 7 deletions lighthouse-cli/test/fixtures/extra-cookies/valid.json

This file was deleted.

0 comments on commit 1677a37

Please sign in to comment.