Skip to content

Commit b0533c1

Browse files
committed
Merge pull request #3 from kevinsawicki/password-path
Add more passwordPath tests
2 parents 0b5ae7e + c20259a commit b0533c1

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

test/fixtures/bad-password.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bad

test/signcode-test.js

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ var temp = require('temp').track()
66

77
var describe = global.describe
88
var it = global.it
9+
var timeout = process.env.CI ? 60000 : 30000
910

1011
describe('signcode', function () {
11-
this.timeout(30000)
12+
this.timeout(timeout)
1213

1314
describe('.sign(options)', function () {
1415
it('signs the executable with a cert/key pem pair', function (done) {
@@ -133,7 +134,46 @@ describe('signcode', function () {
133134
}
134135

135136
signcode.sign(options, function (error) {
136-
assert(error.message.length > 0)
137+
assert(error instanceof Error)
138+
assert.notEqual(error.message.indexOf('Failed to read private key file'), -1)
139+
done()
140+
})
141+
})
142+
143+
it('calls back with an error when a file with an incorrect password is specified', function (done) {
144+
var tempPath = temp.path({suffix: '.exe'})
145+
fs.writeFileSync(tempPath, fs.readFileSync(path.join(__dirname, 'fixtures', 'electron.exe')))
146+
147+
var options = {
148+
cert: path.join(__dirname, 'fixtures', 'cert-with-pw.pem'),
149+
hash: ['sha1', 'sha256'],
150+
key: path.join(__dirname, 'fixtures', 'key-with-pw.pem'),
151+
passwordPath: path.join(__dirname, 'fixtures', 'bad-password.txt'),
152+
path: tempPath
153+
}
154+
155+
signcode.sign(options, function (error) {
156+
assert(error instanceof Error)
157+
assert.notEqual(error.message.indexOf('Failed to read private key file'), -1)
158+
done()
159+
})
160+
})
161+
162+
it('calls back with an error when a non-existent password file is specified', function (done) {
163+
var tempPath = temp.path({suffix: '.exe'})
164+
fs.writeFileSync(tempPath, fs.readFileSync(path.join(__dirname, 'fixtures', 'electron.exe')))
165+
166+
var options = {
167+
cert: path.join(__dirname, 'fixtures', 'cert-with-pw.pem'),
168+
hash: ['sha1', 'sha256'],
169+
key: path.join(__dirname, 'fixtures', 'key-with-pw.pem'),
170+
passwordPath: path.join(__dirname, 'fixtures', 'not-password.txt'),
171+
path: tempPath
172+
}
173+
174+
signcode.sign(options, function (error) {
175+
assert(error instanceof Error)
176+
assert.notEqual(error.message.indexOf('Failed to open password file'), -1)
137177
done()
138178
})
139179
})
@@ -149,8 +189,8 @@ describe('signcode', function () {
149189
}
150190

151191
signcode.sign(options, function (error) {
152-
assert(error.message.length > 0)
153-
assert.notEqual(-1, error.message.indexOf('Failed to read certificate file'))
192+
assert(error instanceof Error)
193+
assert.notEqual(error.message.indexOf('Failed to read certificate file'), -1)
154194
done()
155195
})
156196
})
@@ -166,8 +206,8 @@ describe('signcode', function () {
166206
}
167207

168208
signcode.sign(options, function (error) {
169-
assert(error.message.length > 0)
170-
assert.notEqual(-1, error.message.indexOf('Failed to read private key file'))
209+
assert(error instanceof Error)
210+
assert.notEqual(error.message.indexOf('Failed to read private key file'), -1)
171211
done()
172212
})
173213
})
@@ -195,6 +235,7 @@ describe('signcode', function () {
195235
path: path.join(__dirname, 'fixtures', 'electron.exe')
196236
}
197237
signcode.verify(verifyOptions, function (error) {
238+
assert(error instanceof Error)
198239
assert.equal(error.message, 'No signature found')
199240
done()
200241
})
@@ -206,6 +247,7 @@ describe('signcode', function () {
206247
path: path.join(__dirname, 'fixtures', 'electron-signed.exe')
207248
}
208249
signcode.verify(verifyOptions, function (error) {
250+
assert(error instanceof Error)
209251
assert.equal(error.message, 'Leaf hash match failed')
210252
done()
211253
})

0 commit comments

Comments
 (0)