Skip to content

Commit

Permalink
Merge pull request #80 from develar/deps
Browse files Browse the repository at this point in the history
reject promise using Error and include error message
  • Loading branch information
sethlu authored Nov 14, 2016
2 parents 5197101 + 45f06e7 commit cd4c796
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
test/work
.idea/
yarn.lock
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
language: node_js
node_js:
- "7"
- "6"
- "4.1"
- "4.0"
- "0.12"
- "0.11"
- "0.10"
- "iojs"

script: npm run-script code-standard
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@
},
"homepage": "https://github.com/electron-userland/electron-osx-sign",
"dependencies": {
"bluebird": "^3.3.5",
"bluebird": "^3.4.6",
"compare-version": "^0.1.2",
"debug": "^2.2.0",
"isbinaryfile": "^3.0.0",
"debug": "^2.3.2",
"isbinaryfile": "^3.0.1",
"minimist": "^1.2.0",
"plist": "^1.2.0",
"plist": "^2.0.1",
"tempfile": "^1.1.1"
},
"devDependencies": {
"electron-download": "^2.1.2",
"eslint": "^2.11.1",
"electron-download": "^3.0.1",
"eslint": "^3.10.0",
"eslint-config-eslint": "^3.0.0",
"extract-zip": "^1.5.0",
"mkdirp": "^0.5.1",
"rimraf": "^2.5.2",
"rimraf": "^2.5.4",
"run-series": "^1.1.4",
"run-waterfall": "^1.1.3",
"standard": "^7.0.1",
"tape": "^4.5.1"
"standard": "^8.5.0",
"tape": "^4.6.2"
},
"scripts": {
"code-standard": "standard",
Expand All @@ -47,5 +47,8 @@
"ignore": [
"test/work"
]
},
"engines": {
"node": ">=0.4.0"
}
}
44 changes: 12 additions & 32 deletions sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

'use strict'

const child = require('child_process')
const path = require('path')

const Promise = require('bluebird')
Expand Down Expand Up @@ -83,48 +82,29 @@ function validateSignOptsAsync (opts) {
*/
function verifySignApplicationAsync (opts) {
// Verify with codesign
var promise = new Promise(function (resolve, reject) {
debuglog('Verifying application bundle with codesign...')
child.execFile('codesign', [
'--verify',
'--deep',
'--strict',
'--verbose=2',
opts.app
], function (err, stdout, stderr) {
if (err) {
debugerror(err)
reject('Failed to verify application bundle. See details in debug log. (electron-osx-sign:error)')
return
}
debuglog('Result:\n' + stderr)
resolve(undefined)
})
})
debuglog('Verifying application bundle with codesign...')
var promise = execFileAsync('codesign', [
'--verify',
'--deep',
'--strict',
'--verbose=2',
opts.app
])

// Additionally test Gatekeeper acceptance for darwin platform
if (opts.platform === 'darwin' && opts['gatekeeper-assess'] !== false) {
promise = promise.then(function () {
return new Promise(function (resolve, reject) {
promise = promise
.then(function () {
debuglog('Verifying Gatekeeper acceptance for darwin platform...')
child.execFile('spctl', [
return execFileAsync('spctl', [
'--assess',
'--type', 'execute',
'--verbose',
'--ignore-cache',
'--no-cache',
opts.app
], function (err, stdout, stderr) {
if (err) {
debugerror(err)
reject('Failed to pass Gatekeeper. See details in debug log. (electron-osx-sign:error)')
return
}
debuglog('Result:\n' + stderr)
resolve(undefined)
})
])
})
})
}

return promise
Expand Down
38 changes: 37 additions & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,44 @@ debugerror.log = console.error.bind(console)
/** @function */
const isBinaryFileAsync = module.exports.isBinaryFileAsync = Promise.promisify(require('isbinaryfile'))

function removePassword (input) {
return input.replace(/(-P |pass:|\/p|-pass )([^ ]+)/, function (match, p1, p2) {
return `${p1}***`
})
}

/** @function */
module.exports.execFileAsync = Promise.promisify(child.execFile)
module.exports.execFileAsync = function (file, args, options) {
if (debuglog.enabled) {
debuglog(`Executing ${file} ${args == null ? '' : removePassword(args.join(' '))}`)
}

return new Promise((resolve, reject) => {
child.execFile(file, args, options, function (error, stdout, stderr) {
if (error == null) {
if (debuglog.enabled) {
if (stderr.length !== 0) {
debuglog(stderr)
}
if (stdout.length !== 0) {
debuglog(stdout)
}
}
resolve(stdout)
} else {
let message = removePassword(`Exit code: ${error.code}. ${error.message}`)
if (stdout.length !== 0) {
message += `\n${stdout}`
}
if (stderr.length !== 0) {
message += `\n${stderr}`
}

reject(new Error(message))
}
})
})
}

/** @function */
const lstatAsync = module.exports.lstatAsync = Promise.promisify(fs.lstat)
Expand Down

0 comments on commit cd4c796

Please sign in to comment.