Skip to content

Commit

Permalink
Rework cert stub data
Browse files Browse the repository at this point in the history
  • Loading branch information
eablack committed Mar 6, 2024
1 parent 9463dcb commit d93df69
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
49 changes: 25 additions & 24 deletions packages/cli/test/helpers/stubs/sni-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import heredoc from 'tsheredoc'

export type Endpoint = {
name: string
cname: string | null
Expand Down Expand Up @@ -110,29 +108,32 @@ export const endpointWithDomains: Endpoint = {
},
}

export function certificateDetails() {
return `
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.
`
}

export function certificateDetailsWithDomains() {
return `
Common Name(s): example.org
Domain(s): subdomain.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.
`
}
export const certificateDetails = `
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.
`

export const certificateDetailsWithDomains = `
Common Name(s): example.org
Domain(s): subdomain.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.
`
export const untrustedCertificateDetails = `
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=Untrusted/CN=untrusted.example.org
SSL certificate is not trusted.
`
export const endpoint: Endpoint = {
name: 'tokyo-1050',
cname: 'tokyo-1050.herokussl.com',
Expand Down
18 changes: 7 additions & 11 deletions packages/cli/test/unit/commands/certs/info.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
endpointTrusted,
certificateDetails,
certificateDetailsWithDomains,
untrustedCertificateDetails,
} from '../../../helpers/stubs/sni-endpoints'
const sharedSni = require('./shared_sni.unit.test.ts')

Expand All @@ -32,7 +33,7 @@ describe('heroku certs:info', function () {
`))
expectOutput(stdout.output, heredoc(`
Certificate details:
${certificateDetails()}
${certificateDetails}
`))
})

Expand Down Expand Up @@ -60,7 +61,7 @@ describe('heroku certs:info', function () {
])
expectOutput(stdout.output, heredoc(`
Certificate details:
${certificateDetailsWithDomains()}
${certificateDetailsWithDomains}
`))
})

Expand All @@ -80,12 +81,7 @@ describe('heroku certs:info', function () {
`))
expectOutput(heredoc(stdout.output), heredoc(`
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=Untrusted/CN=untrusted.example.org
SSL certificate is not trusted.
${untrustedCertificateDetails}
`))
})

Expand Down Expand Up @@ -135,10 +131,10 @@ describe('heroku shared', function () {
`)
}

const stdout = function (certificateDetails: string) {
const stdout = function (certDetails: string) {
return heredoc(`
Certificate details:
${certificateDetails}
Certificate details:
${certDetails}
`)
}

Expand Down
5 changes: 2 additions & 3 deletions packages/cli/test/unit/commands/certs/shared_sni.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {stdout, stderr} from 'stdout-stderr'
import runCommand, {GenericCmd} from '../../../helpers/runCommand'

import * as nock from 'nock'
import {expect} from 'chai'
import {
Expand Down Expand Up @@ -39,7 +38,7 @@ export const shouldHandleArgs = function (commandText: string, command: GenericC
'tokyo-1050',
])
expectOutput(stderr.output, stderrOutput(endpoint))
expectOutput(stdout.output, stdoutOutput(certificateDetails(), endpoint))
expectOutput(stdout.output, stdoutOutput(certificateDetails, endpoint))
})

it('# errors out for --endpoint when there are multiple ', async function () {
Expand Down Expand Up @@ -68,7 +67,7 @@ export const shouldHandleArgs = function (commandText: string, command: GenericC
'tokyo-1050.herokussl.com',
])
expectOutput(stderr.output, stderrOutput(endpoint))
expectOutput(stdout.output, stdoutOutput(certificateDetails(), endpoint))
expectOutput(stdout.output, stdoutOutput(certificateDetails, endpoint))
})

it('# --endpoint errors out if there is no match', async function () {
Expand Down

0 comments on commit d93df69

Please sign in to comment.