Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pg-v5): credentials adding capabilities for numbered essential plans #2513

Merged
merged 12 commits into from
Oct 24, 2023
2 changes: 1 addition & 1 deletion packages/pg-v5/commands/credentials/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function run(context, heroku) {
const {app, args, flags} = context

let db = await fetcher.addon(app, args.database)
if (util.essentialPlan(db)) throw new Error('You can’t perform this operation on Essential-tier databases.')
if (util.essentialPlan(db)) throw new Error("You can't create a custom credential on Essential-tier databases.")

let data = {
name: flags.name,
Expand Down
2 changes: 1 addition & 1 deletion packages/pg-v5/commands/credentials/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function run(context, heroku) {

let db = await fetcher.addon(app, args.database)
if (util.essentialPlan(db)) {
brittanyrjones marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Essential-tier databases support only one default credential.')
throw new Error("You can't destroy the default credential on Essential-tier databases.")
}

let attachments = await heroku.get(`/addons/${db.name}/addon-attachments`)
Expand Down
4 changes: 2 additions & 2 deletions packages/pg-v5/commands/credentials/rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ async function run(context, heroku) {
throw new Error('cannot pass both --all and --name')
}

if (util.essentialPlan(db) && cred !== 'default') {
throw new Error('Essential-tier databases support only one default credential.')
if (util.essentialNumPlan(db) || (util.legacyEssentialPlan(db) && cred !== 'default')) {
throw new Error("You can't rotate credentials on Essential-tier databases.")
}

if (all && flags.force) {
Expand Down
4 changes: 2 additions & 2 deletions packages/pg-v5/commands/credentials/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ async function run(context, heroku) {

let db = await fetcher.addon(app, args.database)
let cred = flags.name || 'default'
if (util.essentialPlan(db) && cred !== 'default') {
throw new Error('Essential-tier databases support only one default credential.')
if (util.essentialNumPlan(db) || (util.legacyEssentialPlan(db) && cred !== 'default')) {
throw new Error("You can't view credentials on Essential-tier databases.")
}

let credInfo = await heroku.get(`/postgres/v0/databases/${db.name}/credentials/${encodeURIComponent(cred)}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,31 @@ Please define the new grants for the credential within Postgres: heroku pg:psql
.then(() => expect(cli.stderr).to.equal('Creating credential credname... done\n'))
})

it('throws an error when the db is numbered essential plan', () => {
const essentialAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:essential-0'},
}

const fetcher = () => {
return {
database: () => db,
addon: () => essentialAddon,
}
}

const cmd = proxyquire('../../../../commands/credentials/create', {
'../../lib/fetcher': fetcher,
})

const err = "You can't create a custom credential on Essential-tier databases."
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

it('throws an error when the db is essential plan', () => {
const hobbyAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:hobby-dev'},
plan: {name: 'heroku-postgresql:mini'},
}

const fetcher = () => {
Expand All @@ -72,7 +93,7 @@ Please define the new grants for the credential within Postgres: heroku pg:psql
'../../lib/fetcher': fetcher,
})

const err = 'You can’t perform this operation on Essential-tier databases.'
const err = "You can't create a custom credential on Essential-tier databases."
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,28 @@ Database objects owned by credname will be assigned to the default credential.
'../../lib/fetcher': fetcher,
})

const err = 'Essential-tier databases support only one default credential.'
const err = "You can't destroy the default credential on Essential-tier databases."
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

it('throws an error when the db is numbered essential plan', () => {
const essentialAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:essential-0'},
}

const fetcher = () => {
return {
database: () => db,
addon: () => essentialAddon,
}
}

const cmd = proxyquire('../../../../commands/credentials/destroy', {
'../../lib/fetcher': fetcher,
})

const err = "You can't destroy the default credential on Essential-tier databases."
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ describe('pg:credentials:rotate', () => {
return expect(cmd.run({app: 'myapp', args: {}, flags: {all: true, name: 'my_role', confirm: 'myapp'}})).to.be.rejectedWith(Error, err)
})

it('throws an error when the db is starter plan but the name is specified', () => {
it('throws an error when the db is essential plan but the name is specified', () => {
const hobbyAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:hobby-dev'},
plan: {name: 'heroku-postgresql:mini'},
}

const fetcher = () => {
Expand All @@ -122,7 +122,28 @@ describe('pg:credentials:rotate', () => {
'../../lib/fetcher': fetcher,
})

const err = 'Essential-tier databases support only one default credential.'
const err = "You can't rotate credentials on Essential-tier databases."
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

it('throws an error when the db is numbered essential plan', () => {
const essentialAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:essential-0'},
}

const fetcher = () => {
return {
database: () => db,
addon: () => essentialAddon,
}
}

const cmd = proxyquire('../../../../commands/credentials/rotate', {
'../../lib/fetcher': fetcher,
})

const err = "You can't rotate credentials on Essential-tier databases."
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

Expand Down
23 changes: 22 additions & 1 deletion packages/pg-v5/test/unit/commands/credentials/url.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,28 @@ Connection URL:
'../../lib/fetcher': fetcher,
})

const err = 'Essential-tier databases support only one default credential.'
const err = "You can't view credentials on Essential-tier databases."
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

it('throws an error when the db is numbered essential plan', () => {
const essentialAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:essential-0'},
}

const fetcher = () => {
return {
database: () => db,
addon: () => essentialAddon,
}
}

const cmd = proxyquire('../../../../commands/credentials/url', {
'../../lib/fetcher': fetcher,
})

const err = "You can't view credentials on Essential-tier databases."
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

Expand Down