Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/commands/container/login.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command, flags} from '@heroku-cli/command'
import {Command, flags, vars} from '@heroku-cli/command'
import {ux} from '@oclif/core/ux'

import {debug} from '../../lib/container/debug.js'
Expand Down Expand Up @@ -45,8 +45,7 @@ export default class Login extends Command {
async run() {
const {flags} = await this.parse(Login)
const {verbose} = flags
const herokuHost = process.env.HEROKU_HOST || 'heroku.com'
const registry = `registry.${herokuHost}`
const registry = `registry.${vars.host}`
const password = this.heroku.auth

if (verbose) {
Expand Down
5 changes: 2 additions & 3 deletions src/commands/container/logout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command, flags} from '@heroku-cli/command'
import {Command, flags, vars} from '@heroku-cli/command'
import {ux} from '@oclif/core/ux'

import {debug} from '../../lib/container/debug.js'
Expand All @@ -24,8 +24,7 @@ export default class Logout extends Command {
async run() {
const {flags} = await this.parse(Logout)
const {verbose} = flags
const herokuHost = process.env.HEROKU_HOST || 'heroku.com'
const registry = `registry.${herokuHost}`
const registry = `registry.${vars.host}`

if (verbose) {
debug.enabled = true
Expand Down
5 changes: 2 additions & 3 deletions src/commands/container/pull.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command, flags} from '@heroku-cli/command'
import {Command, flags, vars} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import {color, hux} from '@heroku/heroku-cli-util'

Expand Down Expand Up @@ -34,8 +34,7 @@ export default class Pull extends Command {
const {body: appBody} = await this.heroku.get<Heroku.App>(`/apps/${app}`)
ensureContainerStack(appBody, 'pull')

const herokuHost = process.env.HEROKU_HOST || 'heroku.com'
const registry = `registry.${herokuHost}`
const registry = `registry.${vars.host}`

if (verbose) {
debug.enabled = true
Expand Down
5 changes: 2 additions & 3 deletions src/commands/container/push.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command, flags} from '@heroku-cli/command'
import {Command, flags, vars} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import {color, hux} from '@heroku/heroku-cli-util'
import {ux} from '@oclif/core/ux'
Expand Down Expand Up @@ -48,8 +48,7 @@ export default class Push extends Command {
const {body: appBody} = await this.heroku.get<Heroku.App>(`/apps/${app}`)
ensureContainerStack(appBody, 'push')

const herokuHost = process.env.HEROKU_HOST || 'heroku.com'
const registry = `registry.${herokuHost}`
const registry = `registry.${vars.host}`
const dockerfiles = this.dockerHelper.getDockerfiles(process.cwd(), recursive)
const possibleJobs = this.dockerHelper.getJobs(`${registry}/${app}`, dockerfiles)
const jobs = await this.selectJobs(possibleJobs, processTypes as string[], recursive)
Expand Down
5 changes: 2 additions & 3 deletions src/commands/container/release.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command, flags} from '@heroku-cli/command'
import {Command, flags, vars} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import * as color from '@heroku/heroku-cli-util/color'
import {ux} from '@oclif/core/ux'
Expand Down Expand Up @@ -43,7 +43,6 @@ export default class ContainerRelease extends Command {
const {body: appBody} = await this.heroku.get<Heroku.App>(`/apps/${app}`)
ensureContainerStack(appBody, 'release')

const herokuHost: string = process.env.HEROKU_HOST || 'heroku.com'
const updateData: any[] = []
for (const process of argv) {
const image = `${app}/${process}`
Expand All @@ -55,7 +54,7 @@ export default class ContainerRelease extends Command {
Accept: 'application/vnd.docker.distribution.manifest.v2+json',
Authorization: `Basic ${Buffer.from(`:${this.heroku.auth}`).toString('base64')}`,
},
hostname: `registry.${herokuHost}`,
hostname: `registry.${vars.host}`,
},
)
let imageID
Expand Down
5 changes: 2 additions & 3 deletions src/commands/container/run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command, flags} from '@heroku-cli/command'
import {Command, flags, vars} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import {color, hux} from '@heroku/heroku-cli-util'
import {ux} from '@oclif/core/ux'
Expand Down Expand Up @@ -43,8 +43,7 @@ export default class Run extends Command {
const processType = argv.shift() as string
const command: string = argv.join(' ')

const herokuHost = process.env.HEROKU_HOST || 'heroku.com'
const registry = `registry.${herokuHost}`
const registry = `registry.${vars.host}`
const dockerfiles = this.dockerHelper.getDockerfiles(process.cwd(), false)
const possibleJobs = this.dockerHelper.getJobs(`${registry}/${app}`, dockerfiles)

Expand Down
29 changes: 29 additions & 0 deletions test/unit/commands/container/login.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,35 @@ describe('container:login', function () {
sandbox.assert.calledOnce(login)
})

context('when HEROKU_HOST is set to an invalid domain', function () {
let originalHost: string | undefined

beforeEach(function () {
originalHost = process.env.HEROKU_HOST
process.env.HEROKU_HOST = 'attacker.com'
})

afterEach(function () {
if (originalHost === undefined) {
delete process.env.HEROKU_HOST
} else {
process.env.HEROKU_HOST = originalHost
}
})

it('rejects invalid HEROKU_HOST and uses default registry', async function () {
const version = sandbox.stub(DockerHelper.prototype, 'version').resolves([19, 12])
const login = sandbox.stub(DockerHelper.prototype, 'cmd')
.withArgs('docker', ['login', '--username=_', '--password-stdin', 'registry.heroku.com'], {input: 'heroku_token'})

const {stderr} = await runCommand(Cmd)

expect(stderr).to.contain("Invalid HEROKU_HOST 'attacker.com'")
sandbox.assert.calledOnce(version)
sandbox.assert.calledOnce(login)
})
})

it('logs to the docker registry with an old version', async function () {
const version = sandbox.stub(DockerHelper.prototype, 'version').returns(new Promise(function (resolve) {
resolve([17, 0])
Expand Down
27 changes: 27 additions & 0 deletions test/unit/commands/container/logout.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@ describe('container logout', function () {
return sandbox.restore()
})

context('when HEROKU_HOST is set to an invalid domain', function () {
let originalHost: string | undefined

beforeEach(function () {
originalHost = process.env.HEROKU_HOST
process.env.HEROKU_HOST = 'attacker.com'
})

afterEach(function () {
if (originalHost === undefined) {
delete process.env.HEROKU_HOST
} else {
process.env.HEROKU_HOST = originalHost
}
})

it('rejects invalid HEROKU_HOST and uses default registry', async function () {
const logout = sandbox.stub(DockerHelper.prototype, 'cmd')
.withArgs('docker', ['logout', 'registry.heroku.com'])

const {stderr} = await runCommand(Cmd)

expect(stderr).to.contain("Invalid HEROKU_HOST 'attacker.com'")
sandbox.assert.calledOnce(logout)
})
})

it('logs out of the docker registry', async function () {
const logout = sandbox.stub(DockerHelper.prototype, 'cmd')
.withArgs('docker', ['logout', 'registry.heroku.com'])
Expand Down
49 changes: 49 additions & 0 deletions test/unit/commands/container/release.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,55 @@ describe('container release', function () {
expect(oclif.exit).to.equal(1)
})

context('when HEROKU_HOST is set to an invalid domain', function () {
let originalHost: string | undefined
let registry: nock.Scope

beforeEach(function () {
originalHost = process.env.HEROKU_HOST
process.env.HEROKU_HOST = 'attacker.com'
api
.get('/apps/testapp')
.reply(200, {name: 'testapp', stack: {name: 'container'}})
registry = nock('https://registry.heroku.com:443')
})

afterEach(function () {
if (originalHost === undefined) {
delete process.env.HEROKU_HOST
} else {
process.env.HEROKU_HOST = originalHost
}

registry.done()
})

it('rejects invalid host and sends request to registry.heroku.com', async function () {
api
.patch('/apps/testapp/formation', {
updates: [
{docker_image: 'image_id', type: 'web'},
],
})
.reply(200, {})
.get('/apps/testapp/releases')
.reply(200, [])
.get('/apps/testapp/releases')
.reply(200, [{id: 'release_id'}])
registry
.get('/v2/testapp/web/manifests/latest')
.reply(200, {config: {digest: 'image_id'}, schemaVersion: 2})

const {stderr} = await runCommand(Cmd, [
'--app',
'testapp',
'web',
])

expect(stderr).to.contain("Invalid HEROKU_HOST 'attacker.com'")
})
})

context('when the app is a container app', function () {
let registry: nock.Scope
beforeEach(function () {
Expand Down
Loading