Skip to content

Commit

Permalink
fix(BrowserFetcher): ensure executable has proper permissions (#2342)
Browse files Browse the repository at this point in the history
This patch ensures Chromium executable has permissions to be executed
by non-owner users.

Fixes #2283.
  • Loading branch information
aslushnikov committed Apr 10, 2018
1 parent beea6f9 commit 5089d2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/BrowserFetcher.js
Expand Up @@ -38,6 +38,7 @@ const downloadURLs = {
const readdirAsync = helper.promisify(fs.readdir.bind(fs));
const mkdirAsync = helper.promisify(fs.mkdir.bind(fs));
const unlinkAsync = helper.promisify(fs.unlink.bind(fs));
const chmodAsync = helper.promisify(fs.chmod.bind(fs));

function existsAsync(filePath) {
let fulfill = null;
Expand Down Expand Up @@ -115,7 +116,10 @@ class BrowserFetcher {
if (await existsAsync(zipPath))
await unlinkAsync(zipPath);
}
return this.revisionInfo(revision);
const revisionInfo = this.revisionInfo(revision);
if (revisionInfo)
await chmodAsync(revisionInfo.executablePath, 0o755);
return revisionInfo;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/puppeteer.spec.js
Expand Up @@ -20,6 +20,7 @@ const path = require('path');
const {helper} = require('../lib/helper');
const mkdtempAsync = helper.promisify(fs.mkdtemp);
const readFileAsync = helper.promisify(fs.readFile);
const statAsync = helper.promisify(fs.stat);
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
const utils = require('./utils');

Expand Down Expand Up @@ -51,6 +52,8 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro
revisionInfo = await browserFetcher.download('123456');
expect(revisionInfo.local).toBe(true);
expect(await readFileAsync(revisionInfo.executablePath, 'utf8')).toBe('LINUX BINARY\n');
const expectedPermissions = os.platform() === 'win32' ? 0666 : 0755;
expect((await statAsync(revisionInfo.executablePath)).mode & 0777).toBe(expectedPermissions);
expect(await browserFetcher.localRevisions()).toEqual(['123456']);
await browserFetcher.remove('123456');
expect(await browserFetcher.localRevisions()).toEqual([]);
Expand Down

0 comments on commit 5089d2e

Please sign in to comment.