-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'prerelease/9.0.0-alpha' into jw/pg-v5/upgrade-pg-backup…
…s-delete
- Loading branch information
Showing
5 changed files
with
131 additions
and
111 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
71 changes: 0 additions & 71 deletions
71
packages/certs-v5/test/unit/commands/certs/remove.unit.test.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import color from '@heroku-cli/color' | ||
import {Command, flags} from '@heroku-cli/command' | ||
import {ux} from '@oclif/core' | ||
import getEndpoint from '../../lib/certs/flags' | ||
import confirmApp from '../../lib/apps/confirm-app' | ||
import heredoc from 'tsheredoc' | ||
|
||
export default class Remove extends Command { | ||
static topic = 'certs'; | ||
static description = 'remove an SSL certificate from an app'; | ||
static flags = { | ||
confirm: flags.string({hidden: true}), | ||
name: flags.string({description: 'name to remove'}), | ||
endpoint: flags.string({description: 'endpoint to remove'}), | ||
app: flags.app({required: true}), | ||
remote: flags.remote(), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
const {flags} = await this.parse(Remove) | ||
const {app, confirm} = flags | ||
const sniEndpoint = await getEndpoint(flags, this.heroku) | ||
await confirmApp( | ||
app, | ||
confirm, | ||
heredoc` | ||
WARNING: Destructive Action - you cannot rollback this change | ||
This command will remove the endpoint ${sniEndpoint.name} from ${color.magenta(app)}. | ||
`, | ||
) | ||
ux.action.start(`Removing SSL certificate ${sniEndpoint.name} from ${color.magenta(app)}`) | ||
await this.heroku.request( | ||
`/apps/${app}/sni-endpoints/${sniEndpoint.name}`, | ||
{method: 'DELETE'}, | ||
) | ||
ux.action.stop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import {stdout, stderr} from 'stdout-stderr' | ||
import Cmd from '../../../../src/commands/certs/remove' | ||
import runCommand from '../../../helpers/runCommand' | ||
import heredoc from 'tsheredoc' | ||
import * as nock from 'nock' | ||
import {endpoint} from '../../../helpers/stubs/sni-endpoints' | ||
import sharedSni = require('./shared_sni.unit.test') | ||
import {SniEndpoint} from '../../../../src/lib/types/sni_endpoint' | ||
import {expect} from 'chai' | ||
import stripAnsi = require('strip-ansi') | ||
|
||
describe('heroku certs:remove', function () { | ||
afterEach(function () { | ||
nock.cleanAll() | ||
}) | ||
|
||
it('# deletes the endpoint', async () => { | ||
const api = nock('https://api.heroku.com') | ||
.get('/apps/example/sni-endpoints') | ||
.reply(200, [endpoint]) | ||
.delete('/apps/example/sni-endpoints/' + endpoint.name) | ||
.reply(200, [endpoint]) | ||
|
||
await runCommand(Cmd, [ | ||
'--app', | ||
'example', | ||
'--confirm', | ||
'example', | ||
]) | ||
|
||
api.done() | ||
|
||
expect(stderr.output).to.equal(heredoc` | ||
Removing SSL certificate tokyo-1050 from example... | ||
Removing SSL certificate tokyo-1050 from example... done | ||
`) | ||
}) | ||
|
||
it('# requires confirmation if wrong endpoint on app', async () => { | ||
const api = nock('https://api.heroku.com') | ||
.get('/apps/example/sni-endpoints') | ||
.reply(200, [endpoint]) | ||
|
||
try { | ||
await runCommand(Cmd, [ | ||
'--app', | ||
'example', | ||
'--confirm', | ||
'notexample', | ||
]) | ||
} catch (error) { | ||
const {message} = error as Error | ||
expect(stripAnsi(message)).to.equal('Confirmation notexample did not match example. Aborted.') | ||
} | ||
|
||
api.done() | ||
expect(stdout.output).to.equal('') | ||
}) | ||
}) | ||
|
||
describe('heroku shared', function () { | ||
const callback = function (err: Error | null, path: string, endpoint: Partial<SniEndpoint>) { | ||
if (err) | ||
throw err | ||
|
||
return nock('https://api.heroku.com') | ||
.delete(path) | ||
.reply(200, endpoint) | ||
} | ||
|
||
const stderr = function (endpoint: Partial<SniEndpoint>) { | ||
return heredoc(` | ||
Removing SSL certificate ${endpoint.name} from example... | ||
Removing SSL certificate ${endpoint.name} from example... done | ||
`) | ||
} | ||
|
||
sharedSni.shouldHandleArgs('certs:remove', Cmd, callback, {stderr}, {confirm: 'example'}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters