Socket
Socket
Sign inDemoInstall

heroku-certs

Package Overview
Dependencies
Maintainers
2
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heroku-certs - npm Package Compare versions

Comparing version 1.1.28 to 1.1.29

lib/get_cert_and_key.js

33

commands/certs/add.js

@@ -10,6 +10,4 @@ 'use strict'

let error = require('../../lib/error.js')
let readFile = require('../../lib/read_file.js')
let findMatch = require('../../lib/find_match.js')
let endpoints = require('../../lib/endpoints.js')
let sslDoctor = require('../../lib/ssl_doctor.js')
let displayWarnings = require('../../lib/display_warnings.js')

@@ -19,2 +17,3 @@ let certificateDetails = require('../../lib/certificate_details.js')

let isWildcardMatch = require('../../lib/is_wildcard_match.js')
let getCertAndKey = require('../../lib/get_cert_and_key.js')

@@ -58,21 +57,2 @@ function Domains (domains) {

function * getFiles (context) {
let files = yield {
crt: readFile(context.args.CRT, 'utf-8'),
key: readFile(context.args.KEY, 'utf-8')
}
let crt, key
if (context.flags.bypass) {
crt = files.crt
key = files.key
} else {
let res = JSON.parse(yield sslDoctor('resolve-chain-and-key', [files.crt, files.key]))
crt = res.pem
key = res.key
}
return {crt, key}
}
function hasMatch (certDomains, domain) {

@@ -284,3 +264,3 @@ return _.find(certDomains, (certDomain) => (certDomain === domain || isWildcardMatch(certDomain, domain)))

let files = yield getFiles(context)
let files = yield getCertAndKey(context)

@@ -315,2 +295,3 @@ let cert = yield cli.action(`Adding SSL certificate to ${cli.color.app(context.app)}`, {}, heroku.request({

command: 'add',
variableArgs: true,
args: [

@@ -326,5 +307,11 @@ {name: 'CRT', optional: false},

description: 'add an SSL certificate to an app',
help: `Example:
help: `Note: certificates with PEM encoding are also valid
Example:
$ heroku certs:add example.com.crt example.com.key
Cerfificate Intermediary Example:
$ heroku certs:add intermediary.crt example.com.crt example.com.key
`,

@@ -331,0 +318,0 @@ needsApp: true,

@@ -7,7 +7,6 @@ 'use strict'

let flags = require('../../lib/flags.js')
let readFile = require('../../lib/read_file.js')
let sslDoctor = require('../../lib/ssl_doctor.js')
let displayWarnings = require('../../lib/display_warnings.js')
let formatEndpoint = require('../../lib/format_endpoint.js')
let certificateDetails = require('../../lib/certificate_details.js')
let getCertAndKey = require('../../lib/get_cert_and_key.js')

@@ -17,17 +16,4 @@ function * run (context, heroku) {

let files = yield {
crt: readFile(context.args.CRT, 'utf-8'),
key: readFile(context.args.KEY, 'utf-8')
}
let files = yield getCertAndKey(context)
let crt, key
if (context.flags.bypass) {
crt = files.crt
key = files.key
} else {
let res = JSON.parse(yield sslDoctor('resolve-chain-and-key', [files.crt, files.key]))
crt = res.pem
key = res.key
}
let formattedEndpoint = formatEndpoint(endpoint)

@@ -41,3 +27,3 @@

headers: {'Accept': `application/vnd.heroku+json; version=3.${endpoint._meta.variant}`},
body: {certificate_chain: crt, private_key: key}
body: {certificate_chain: files.crt, private_key: files.key}
}))

@@ -52,2 +38,3 @@

command: 'update',
variableArgs: true,
args: [

@@ -64,5 +51,11 @@ {name: 'CRT', optional: false},

description: 'update an SSL certificate on an app',
help: `Example:
help: `Note: certificates with PEM encoding are also valid
Example:
$ heroku certs:update example.com.crt example.com.key
Cerfificate Intermediary Example:
$ heroku certs:update intermediary.crt example.com.crt example.com.key
`,

@@ -69,0 +62,0 @@ needsApp: true,

{
"name": "heroku-certs",
"description": "heroku ssl plugin",
"version": "1.1.28",
"version": "1.1.29",
"author": "Ransom Briggs rbriggs@heroku.com",

@@ -6,0 +6,0 @@ "bugs": {

@@ -78,3 +78,3 @@ 'use strict'

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, type: 'endpoint'}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, type: 'endpoint'}}).then(function () {
mockSsl.done()

@@ -131,3 +131,3 @@ expect(cli.stderr).to.equal('Adding SSL certificate to example... done\n')

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {}}).then(function () {
sslDoctor.done()

@@ -149,2 +149,71 @@ mockSsl.done()

it('# posts intermediaries to ssl doctor', function () {
nock('https://api.heroku.com')
.get('/apps/example')
.reply(200, { 'space': null })
mockDomains(inquirer)
mockFile(fs, 'pem_file', 'pem content')
mockFile(fs, 'int_file', 'int content')
mockFile(fs, 'key_file', 'key content')
let sslDoctor = nock('https://ssl-doctor.heroku.com', {
reqheaders: {
'content-type': 'application/octet-stream',
'content-length': '35'
}
})
.post('/resolve-chain-and-key', 'pem content\nint content\nkey content')
.reply(200, {pem: 'pem content\nint content', key: 'key content'})
let mockSsl = nock('https://api.heroku.com')
.get('/apps/example/addons/ssl%3Aendpoint')
.reply(404, {
'id': 'not_found',
'resource': 'addon'
})
let mockSni = nock('https://api.heroku.com')
.post('/apps/example/sni-endpoints', {
certificate_chain: 'pem content\nint content', private_key: 'key content'
})
.reply(200, endpoint)
return certs.run({app: 'example', args: ['pem_file', 'int_file', 'key_file'], flags: {}}).then(function () {
sslDoctor.done()
mockSsl.done()
mockSni.done()
expect(cli.stderr).to.equal('Resolving trust chain... done\nAdding SSL certificate to example... done\n')
/* eslint-disable no-irregular-whitespace */
expect(cli.stdout).to.equal(
`example now served by tokyo-1050.herokussl.com
Certificate details:
${certificateDetails}
=== Your certificate has been added successfully.  Add a custom domain to your app by running heroku domains:add <yourdomain.com>
`)
})
/* eslint-enable no-irregular-whitespace */
})
it('# errors out when args < 2', function () {
nock('https://api.heroku.com')
.get('/apps/example')
.reply(200, { 'space': null })
let mockSsl = nock('https://api.heroku.com')
.get('/apps/example/addons/ssl%3Aendpoint')
.reply(404, {
'id': 'not_found',
'resource': 'addon'
})
return assertExit(1, certs.run({app: 'example', args: ['pem_file'], flags: {}})).then(function () {
mockSsl.done()
expect(cli.stderr).to.equal(' ▸ Usage: heroku certs:add CRT KEY\n')
expect(cli.stdout).to.equal('')
})
})
it('# propegates ssl doctor errors', function () {

@@ -176,3 +245,3 @@ nock('https://api.heroku.com')

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {}})
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {}})
.then(function () {

@@ -213,3 +282,3 @@ expect.fail('Expected exception')

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mockSni.done()

@@ -230,2 +299,21 @@ mockSsl.done()

it('# bypass errors out with intermediaries', function () {
nock('https://api.heroku.com')
.get('/apps/example')
.reply(200, { 'space': null })
let mockSsl = nock('https://api.heroku.com')
.get('/apps/example/addons/ssl%3Aendpoint')
.reply(404, {
'id': 'not_found',
'resource': 'addon'
})
return assertExit(1, certs.run({app: 'example', args: ['pem_file', 'int_file', 'key_file'], flags: {bypass: true}})).then(function () {
mockSsl.done()
expect(cli.stderr).to.equal(' ▸ Usage: heroku certs:add CRT KEY\n')
expect(cli.stdout).to.equal('')
})
})
it('# displays warnings', function () {

@@ -254,3 +342,3 @@ nock('https://api.heroku.com')

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mockSni.done()

@@ -285,3 +373,3 @@ mockSsl.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mock.done()

@@ -326,3 +414,3 @@ expect(cli.stderr).to.equal('Adding SSL certificate to example... done\n')

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mock.done()

@@ -391,3 +479,3 @@ expect(cli.stderr).to.equal('Adding SSL certificate to example... done\n')

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mock.done()

@@ -450,3 +538,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, domains: 'foo.example.org,bar.example.org'}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, domains: 'foo.example.org,bar.example.org'}}).then(function () {
mock.done()

@@ -508,3 +596,3 @@ domainsMock.done()

return assertExit(2, certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, domains: 'foo.example.org,bar.example.org,biz.example.com'}})).then(function () {
return assertExit(2, certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, domains: 'foo.example.org,bar.example.org,biz.example.com'}})).then(function () {
mock.done()

@@ -555,3 +643,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, domains: 'foo.example.org'}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, domains: 'foo.example.org'}}).then(function () {
mock.done()

@@ -602,3 +690,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, domains: 'foo.example.org'}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, domains: 'foo.example.org'}}).then(function () {
mock.done()

@@ -640,3 +728,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, domains: 'garbage.example.org'}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, domains: 'garbage.example.org'}}).then(function () {
mock.done()

@@ -682,3 +770,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mock.done()

@@ -729,3 +817,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mock.done()

@@ -770,3 +858,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mock.done()

@@ -814,3 +902,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mock.done()

@@ -851,3 +939,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mock.done()

@@ -891,3 +979,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mock.done()

@@ -928,3 +1016,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, domains: ''}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, domains: ''}}).then(function () {
mock.done()

@@ -1000,3 +1088,3 @@ domainsMock.done()

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}).then(function () {
mock.done()

@@ -1052,3 +1140,3 @@ domainsMock.done()

return assert.isRejected(certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}}), /Timed out while waiting for stable domains to be created/).then(function () {
return assert.isRejected(certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}}), /Timed out while waiting for stable domains to be created/).then(function () {
mock.done()

@@ -1084,3 +1172,3 @@ domainsMock.done()

return assertExit(1, certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true}})).then(function () {
return assertExit(1, certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true}})).then(function () {
mockAddons.done()

@@ -1093,3 +1181,3 @@ expect(cli.stderr).to.equal(" ▸ Must pass --type with either 'endpoint' or 'sni'\n")

it('# errors out if type is not known', function () {
return assertExit(1, certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, type: 'foo'}})).then(function () {
return assertExit(1, certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, type: 'foo'}})).then(function () {
expect(cli.stderr).to.equal(" ▸ Must pass --type with either 'endpoint' or 'sni'\n")

@@ -1118,3 +1206,3 @@ expect(cli.stdout).to.equal('')

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, type: 'sni'}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, type: 'sni'}}).then(function () {
mockSni.done()

@@ -1150,3 +1238,3 @@ expect(cli.stderr).to.equal('Adding SSL certificate to example... done\n')

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, type: 'endpoint'}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, type: 'endpoint'}}).then(function () {
mockSni.done()

@@ -1153,0 +1241,0 @@ expect(cli.stderr).to.equal('Adding SSL certificate to example... done\n')

@@ -11,2 +11,3 @@ 'use strict'

let error = require('../../../lib/error.js')
let assertExit = require('../../assert_exit.js')
let shared = require('./shared.js')

@@ -16,2 +17,3 @@ let sharedSsl = require('./shared_ssl.js')

let endpoint = require('../../stubs/sni-endpoints.js').endpoint
let endpointStable = require('../../stubs/sni-endpoints.js').endpoint_stable

@@ -53,3 +55,3 @@ let endpointWarning = require('../../stubs/sni-endpoints.js').endpoint_warning

var thrown = false
return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {confirm: 'notexample', bypass: true}}).catch(function (err) {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {confirm: 'notexample', bypass: true}}).catch(function (err) {
thrown = true

@@ -81,3 +83,3 @@ expect(err).to.equal('Confirmation notexample did not match example. Aborted.')

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {name: 'tokyo-1050', confirm: 'example'}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {name: 'tokyo-1050', confirm: 'example'}}).then(function () {
sslDoctor.done()

@@ -93,2 +95,45 @@ mock.done()

it('# posts intermediaries to ssl doctor', function () {
mockFile(fs, 'pem_file', 'pem content')
mockFile(fs, 'int_file', 'int content')
mockFile(fs, 'key_file', 'key content')
let sslDoctor = nock('https://ssl-doctor.heroku.com', {
reqheaders: {
'content-type': 'application/octet-stream',
'content-length': '35'
}
})
.post('/resolve-chain-and-key', 'pem content\nint content\nkey content')
.reply(200, {pem: 'pem content\nint content', key: 'key content'})
let mock = nock('https://api.heroku.com')
.patch('/apps/example/sni-endpoints/tokyo-1050', {
certificate_chain: 'pem content\nint content', private_key: 'key content'
})
.reply(200, endpoint)
return certs.run({app: 'example', args: ['pem_file', 'int_file', 'key_file'], flags: {confirm: 'example'}}).then(function () {
sslDoctor.done()
mock.done()
expect(cli.stderr).to.equal('Resolving trust chain... done\nUpdating SSL certificate tokyo-1050 for example... done\n')
expect(cli.stdout).to.equal(
`Updated certificate details:
${certificateDetails}
`)
})
/* eslint-enable no-irregular-whitespace */
})
it('# errors out when args < 2', function () {
nock('https://api.heroku.com')
.get('/apps/example')
.reply(200, { 'space': null })
return assertExit(1, certs.run({app: 'example', args: ['pem_file'], flags: {}})).then(function () {
expect(cli.stderr).to.equal(' ▸ Usage: heroku certs:add CRT KEY\n')
expect(cli.stdout).to.equal('')
})
})
it('# propegates ssl doctor errors', function () {

@@ -107,3 +152,3 @@ mockFile(fs, 'pem_file', 'pem content')

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {confirm: 'example'}})
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {confirm: 'example'}})
.then(function () {

@@ -130,3 +175,3 @@ expect.fail('Expected exception')

return certs.run({app: 'example', args: {name: 'tokyo-1050', CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, confirm: 'example'}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, confirm: 'example'}}).then(function () {
mock.done()

@@ -141,2 +186,13 @@ expect(cli.stderr).to.equal('Updating SSL certificate tokyo-1050 for example... done\n')

it('# bypass errors out with intermediaries', function () {
nock('https://api.heroku.com')
.get('/apps/example')
.reply(200, { 'space': null })
return assertExit(1, certs.run({app: 'example', args: ['pem_file', 'int_file', 'key_file'], flags: {bypass: true}})).then(function () {
expect(cli.stderr).to.equal(' ▸ Usage: heroku certs:add CRT KEY\n')
expect(cli.stdout).to.equal('')
})
})
it('# displays warnings', function () {

@@ -152,3 +208,3 @@ mockFile(fs, 'pem_file', 'pem content')

return certs.run({app: 'example', args: {name: 'tokyo-1050', CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, confirm: 'example'}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {bypass: true, confirm: 'example'}}).then(function () {
mock.done()

@@ -187,11 +243,11 @@ expect(unwrap(cli.stderr)).to.equal('Updating SSL certificate tokyo-1050 for example... done WARNING: ssl_cert provides no domain(s) that are configured for this Heroku app\n')

shared.shouldHandleArgs('certs:update', 'updates an endpoint', certs, callback, {
stderr, stdout, args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, confirm: 'example'}
stderr, stdout, args: ['pem_file', 'key_file'], flags: {bypass: true, confirm: 'example'}
})
sharedSsl.shouldHandleArgs('certs:update', 'updates an endpoint', certs, callback, {
stderr, stdout, args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, confirm: 'example'}
stderr, stdout, args: ['pem_file', 'key_file'], flags: {bypass: true, confirm: 'example'}
})
sharedSni.shouldHandleArgs('certs:update', 'updates an endpoint', certs, callback, {
stderr, stdout, args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {bypass: true, confirm: 'example'}
stderr, stdout, args: ['pem_file', 'key_file'], flags: {bypass: true, confirm: 'example'}
})

@@ -239,3 +295,3 @@ })

return certs.run({app: 'example', args: {CRT: 'pem_file', KEY: 'key_file'}, flags: {name: 'tokyo-1050', confirm: 'example', bypass: true}}).then(function () {
return certs.run({app: 'example', args: ['pem_file', 'key_file'], flags: {name: 'tokyo-1050', confirm: 'example', bypass: true}}).then(function () {
mockSni.done()

@@ -242,0 +298,0 @@ mockPut.done()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc