Skip to content

Commit

Permalink
feat(certs-v5): Remove old --domains flag from certs:add (#1781)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Gauger authored Apr 12, 2021
1 parent ddd2bba commit 12115d0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 314 deletions.
21 changes: 2 additions & 19 deletions packages/certs-v5/commands/certs/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ function hasMatch (certDomains, domain) {
return _.find(certDomains, (certDomain) => (certDomain === domain || isWildcardMatch(certDomain, domain)))
}

function getFlagChoices (context, certDomains, existingDomains) {
let flagDomains = context.flags.domains.split(',').map((str) => str.trim()).filter((str) => str !== '')
let choices = _.difference(flagDomains, existingDomains)

let badChoices = _.remove(choices, (choice) => (!hasMatch(certDomains, choice)))
badChoices.forEach(function (choice) {
cli.warn(`Not adding ${choice} because it is not listed in the certificate`)
})

return choices
}

function getPromptChoices (context, certDomains, existingDomains, newDomains) {
let nonWildcardDomains = newDomains.filter((domain) => !isWildcard(domain))

Expand All @@ -90,11 +78,7 @@ async function getChoices(certDomains, newDomains, existingDomains, context) {
if (newDomains.length === 0) {
return []
} else {
if (context.flags.domains !== undefined) {
return getFlagChoices(context, certDomains, existingDomains)
} else {
return ((await getPromptChoices(context, certDomains, existingDomains, newDomains))).domains;
}
return ((await getPromptChoices(context, certDomains, existingDomains, newDomains))).domains;
}
}

Expand Down Expand Up @@ -282,8 +266,7 @@ module.exports = {
],
flags: [
{ name: 'bypass', description: 'bypass the trust chain completion step', hasValue: false },
{ name: 'type', description: "type to create, either 'sni' or 'endpoint'", hasValue: true, completion: CertTypeCompletion },
{ name: 'domains', description: 'domains to create after certificate upload', hasValue: true }
{ name: 'type', description: "type to create, either 'sni' or 'endpoint'", hasValue: true, completion: CertTypeCompletion }
],
description: 'add an SSL certificate to an app',
help: 'Note: certificates with PEM encoding are also valid',
Expand Down
295 changes: 0 additions & 295 deletions packages/certs-v5/test/commands/certs/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,262 +592,6 @@ foo.example.org CNAME foo.example.org.herokudns.com
})
})

it('# when passed domains does not prompt and creates an SNI endpoint with stable cnames if no SSL addon', function () {
nock('https://api.heroku.com')
.get('/apps/example/features')
.reply(200, [])

let mock = nock('https://api.heroku.com')
.post('/apps/example/sni-endpoints', {
certificate_chain: 'pem content', private_key: 'key content'
})
.reply(200, endpointStables)

let domainsMock = nock('https://api.heroku.com')
.get('/apps/example/domains')
.reply(200, [
{ 'kind': 'custom', 'hostname': 'baz.example.org', 'cname': 'baz.example.org.herokudns.com' }
])

let domainsCreateFoo = nock('https://api.heroku.com')
.post('/apps/example/domains', { hostname: 'foo.example.org' })
.reply(200,
{ 'kind': 'custom', 'cname': 'foo.example.com.herokudns.com', 'hostname': 'foo.example.org' }
)

let domainsCreateBar = nock('https://api.heroku.com')
.post('/apps/example/domains', { hostname: 'bar.example.org' })
.reply(200,
{ 'kind': 'custom', 'cname': 'bar.example.com.herokudns.com', 'hostname': 'bar.example.org' }
)

return certs.run({ app: 'example', args: ['pem_file', 'key_file'], flags: { bypass: true, domains: 'foo.example.org,bar.example.org' } }).then(function () {
mock.done()
domainsMock.done()
domainsCreateFoo.done()
domainsCreateBar.done()
expect(unwrap(cli.stderr)).to.equal('Adding SSL certificate to example... done\n\nAdding domains foo.example.org, bar.example.org to example... done\n')
/* eslint-disable no-trailing-spaces */
expect(cli.stdout).to.equal(
`Certificate details:
Common Name(s): foo.example.org
bar.example.org
biz.example.com
Expires At: 2013-08-01 21:34 UTC
Issuer: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
Starts At: 2012-08-01 21:34 UTC
Subject: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
SSL certificate is self signed.
=== Your certificate has been added successfully. Update your application's DNS settings as follows
Domain Record Type DNS Target
─────────────── ─────────── ─────────────────────────────
baz.example.org CNAME baz.example.org.herokudns.com
foo.example.org CNAME foo.example.com.herokudns.com
bar.example.org CNAME bar.example.com.herokudns.com
`)
/* eslint-enable no-trailing-spaces */
})
})

it('# when passed domains does not prompt and there are failures', function () {
nock('https://api.heroku.com')
.get('/apps/example/features')
.reply(200, [])

let mock = nock('https://api.heroku.com')
.post('/apps/example/sni-endpoints', {
certificate_chain: 'pem content', private_key: 'key content'
})
.reply(200, endpointStables)

let domainsMock = nock('https://api.heroku.com')
.get('/apps/example/domains')
.reply(200, [])

let domainsCreateFoo = nock('https://api.heroku.com')
.post('/apps/example/domains', { hostname: 'foo.example.org' })
.reply(200,
{ 'kind': 'custom', 'cname': 'foo.example.org.herokudns.com', 'hostname': 'foo.example.org' }
)

let domainsCreateBar = nock('https://api.heroku.com')
.post('/apps/example/domains', { hostname: 'bar.example.org' })
.reply(422, { 'id': 'invalid_params', 'message': 'example.com is currently in use by another app.' }
)

let domainsCreateBiz = nock('https://api.heroku.com')
.post('/apps/example/domains', { hostname: 'biz.example.com' })
.reply(200,
{ 'kind': 'custom', 'cname': 'biz.example.com.herokudns.com', 'hostname': 'biz.example.com' }
)

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()
domainsMock.done()
domainsCreateFoo.done()
domainsCreateBar.done()
domainsCreateBiz.done()
expect(unwrap(cli.stderr)).to.equal('Adding SSL certificate to example... done\n\nAdding domains foo.example.org, bar.example.org, biz.example.com to example... ! An error was encountered when adding bar.example.org example.com is currently in use by another app.\n')
/* eslint-disable no-trailing-spaces */
/* eslint-disable no-multiple-empty-lines */
expect(cli.stdout).to.equal(
`Certificate details:
Common Name(s): foo.example.org
bar.example.org
biz.example.com
Expires At: 2013-08-01 21:34 UTC
Issuer: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
Starts At: 2012-08-01 21:34 UTC
Subject: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
SSL certificate is self signed.
=== Your certificate has been added successfully. Update your application's DNS settings as follows
Domain Record Type DNS Target
─────────────── ─────────── ─────────────────────────────
foo.example.org CNAME foo.example.org.herokudns.com
biz.example.com CNAME biz.example.com.herokudns.com
`)
/* eslint-disable no-multiple-empty-lines */
/* eslint-enable no-trailing-spaces */
})
})

it('# when passed existing domains does not prompt and creates an SNI endpoint with stable cnames if no SSL addon', function () {
nock('https://api.heroku.com')
.get('/apps/example/features')
.reply(200, [])

let mock = nock('https://api.heroku.com')
.post('/apps/example/sni-endpoints', {
certificate_chain: 'pem content', private_key: 'key content'
})
.reply(200, endpointStables)

let domainsMock = nock('https://api.heroku.com')
.get('/apps/example/domains')
.reply(200, [
{ 'kind': 'custom', 'hostname': 'baz.example.org', 'cname': 'baz.example.org.herokudns.com' },
{ 'kind': 'custom', 'hostname': 'foo.example.org', 'cname': 'foo.example.org.herokudns.com' }
])

return certs.run({ app: 'example', args: ['pem_file', 'key_file'], flags: { bypass: true, domains: 'foo.example.org' } }).then(function () {
mock.done()
domainsMock.done()
expect(unwrap(cli.stderr)).to.equal('Adding SSL certificate to example... done\n')
/* eslint-disable no-trailing-spaces */
expect(cli.stdout).to.equal(
`Certificate details:
Common Name(s): foo.example.org
bar.example.org
biz.example.com
Expires At: 2013-08-01 21:34 UTC
Issuer: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
Starts At: 2012-08-01 21:34 UTC
Subject: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
SSL certificate is self signed.
=== The following common names already have domain entries
foo.example.org
=== Your certificate has been added successfully. Update your application's DNS settings as follows
Domain Record Type DNS Target
─────────────── ─────────── ─────────────────────────────
baz.example.org CNAME baz.example.org.herokudns.com
foo.example.org CNAME foo.example.org.herokudns.com
`)
/* eslint-enable no-trailing-spaces */
})
})

it('# when passed existing domains does not prompt and creates an SNI endpoint with stable cnames if no SSL addon and wildcard match', function () {
nock('https://api.heroku.com')
.get('/apps/example/features')
.reply(200, [])

let mock = nock('https://api.heroku.com')
.post('/apps/example/sni-endpoints', {
certificate_chain: 'pem content', private_key: 'key content'
})
.reply(200, endpointWildcard)

let domainsMock = nock('https://api.heroku.com')
.get('/apps/example/domains')
.reply(200, [])

let domainsCreateFoo = nock('https://api.heroku.com')
.post('/apps/example/domains', { hostname: 'foo.example.org' })
.reply(200,
{ 'kind': 'custom', 'cname': 'foo.example.org.herokudns.com', 'hostname': 'foo.example.org' }
)

return certs.run({ app: 'example', args: ['pem_file', 'key_file'], flags: { bypass: true, domains: 'foo.example.org' } }).then(function () {
mock.done()
domainsMock.done()
domainsCreateFoo.done()
expect(unwrap(cli.stderr)).to.equal('Adding SSL certificate to example... done\n\nAdding domain foo.example.org to example... done\n')
/* eslint-disable no-trailing-spaces */
expect(cli.stdout).to.equal(
`Certificate details:
Common Name(s): *.example.org
Expires At: 2013-08-01 21:34 UTC
Issuer: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
Starts At: 2012-08-01 21:34 UTC
Subject: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
SSL certificate is self signed.
=== Your certificate has been added successfully. Update your application's DNS settings as follows
Domain Record Type DNS Target
─────────────── ─────────── ─────────────────────────────
foo.example.org CNAME foo.example.org.herokudns.com
`)
/* eslint-enable no-trailing-spaces */
})
})

it('# when passed bad domains does not prompt and creates an SNI endpoint with stable cnames if no SSL addon', function () {
nock('https://api.heroku.com')
.get('/apps/example/features')
.reply(200, [])

let mock = nock('https://api.heroku.com')
.post('/apps/example/sni-endpoints', {
certificate_chain: 'pem content', private_key: 'key content'
})
.reply(200, endpointStables)

let domainsMock = nock('https://api.heroku.com')
.get('/apps/example/domains')
.reply(200, [
{ 'kind': 'custom', 'hostname': 'baz.example.org', 'cname': 'baz.example.org.herokudns.com' }
])

return certs.run({ app: 'example', args: ['pem_file', 'key_file'], flags: { bypass: true, domains: 'garbage.example.org' } }).then(function () {
mock.done()
domainsMock.done()
expect(unwrap(cli.stderr)).to.equal('Adding SSL certificate to example... done Not adding garbage.example.org because it is not listed in the certificate\n')
/* eslint-disable no-trailing-spaces */
expect(cli.stdout).to.equal(
`Certificate details:
Common Name(s): foo.example.org
bar.example.org
biz.example.com
Expires At: 2013-08-01 21:34 UTC
Issuer: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
Starts At: 2012-08-01 21:34 UTC
Subject: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
SSL certificate is self signed.
=== Your certificate has been added successfully. Update your application's DNS settings as follows
Domain Record Type DNS Target
─────────────── ─────────── ─────────────────────────────
baz.example.org CNAME baz.example.org.herokudns.com
`)
/* eslint-enable no-trailing-spaces */
})
})

it('# does not prompt if all domains covered', function () {
nock('https://api.heroku.com')
.get('/apps/example/features')
Expand Down Expand Up @@ -1113,45 +857,6 @@ foo.example.org CNAME foo.example.org.herokudns.com
})
})

it('# when no domains exist and none are selected there should be no table', function () {
nock('https://api.heroku.com')
.get('/apps/example/features')
.reply(200, [])

let mock = nock('https://api.heroku.com')
.post('/apps/example/sni-endpoints', {
certificate_chain: 'pem content', private_key: 'key content'
})
.reply(200, endpointStables)

let domainsMock = nock('https://api.heroku.com')
.get('/apps/example/domains')
.reply(200, [])

return certs.run({ app: 'example', args: ['pem_file', 'key_file'], flags: { bypass: true, domains: '' } }).then(function () {
mock.done()
domainsMock.done()
expect(unwrap(cli.stderr)).to.equal('Adding SSL certificate to example... done\n')
/* eslint-disable no-trailing-spaces */
/* eslint-disable no-irregular-whitespace */
expect(cli.stdout).to.equal(
`Certificate details:
Common Name(s): foo.example.org
bar.example.org
biz.example.com
Expires At: 2013-08-01 21:34 UTC
Issuer: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
Starts At: 2012-08-01 21:34 UTC
Subject: /C=US/ST=California/L=San Francisco/O=Heroku by Salesforce/CN=secure.example.org
SSL certificate is self signed.
=== Your certificate has been added successfully. Add a custom domain to your app by running heroku domains:add <yourdomain.com>
`)
/* eslint-disable no-irregular-whitespace */
/* eslint-enable no-trailing-spaces */
})
})

describe('waiting for domains', function () {
let clock

Expand Down

0 comments on commit 12115d0

Please sign in to comment.