Skip to content

Commit 51dc3ac

Browse files
feat(pg-v5): credentials adding capabilities for numbered essential plans (#2513)
* adding essential num plan tests * wrong dir * edit module * extra line * combining messaging * adding cred check * testing url and rotate * editing based on credentials being available for num essentials too * remove line * error message changes * fix expectation --------- Co-authored-by: Justin Downing <jdowning@heroku.com>
1 parent 2a71b1e commit 51dc3ac

File tree

8 files changed

+97
-13
lines changed

8 files changed

+97
-13
lines changed

packages/pg-v5/commands/credentials/create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async function run(context, heroku) {
1010
const {app, args, flags} = context
1111

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

1515
let data = {
1616
name: flags.name,

packages/pg-v5/commands/credentials/destroy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function run(context, heroku) {
1616

1717
let db = await fetcher.addon(app, args.database)
1818
if (util.essentialPlan(db)) {
19-
throw new Error('Essential-tier databases support only one default credential.')
19+
throw new Error("You can't destroy the default credential on Essential-tier databases.")
2020
}
2121

2222
let attachments = await heroku.get(`/addons/${db.name}/addon-attachments`)

packages/pg-v5/commands/credentials/rotate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ async function run(context, heroku) {
1616
throw new Error('cannot pass both --all and --name')
1717
}
1818

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

2323
if (all && flags.force) {

packages/pg-v5/commands/credentials/url.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async function run(context, heroku) {
1212

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

1919
let credInfo = await heroku.get(`/postgres/v0/databases/${db.name}/credentials/${encodeURIComponent(cred)}`,

packages/pg-v5/test/unit/commands/credentials/create.unit.test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,31 @@ Please define the new grants for the credential within Postgres: heroku pg:psql
5555
.then(() => expect(cli.stderr).to.equal('Creating credential credname... done\n'))
5656
})
5757

58+
it('throws an error when the db is numbered essential plan', () => {
59+
const essentialAddon = {
60+
name: 'postgres-1',
61+
plan: {name: 'heroku-postgresql:essential-0'},
62+
}
63+
64+
const fetcher = () => {
65+
return {
66+
database: () => db,
67+
addon: () => essentialAddon,
68+
}
69+
}
70+
71+
const cmd = proxyquire('../../../../commands/credentials/create', {
72+
'../../lib/fetcher': fetcher,
73+
})
74+
75+
const err = "You can't create a custom credential on Essential-tier databases."
76+
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
77+
})
78+
5879
it('throws an error when the db is essential plan', () => {
5980
const hobbyAddon = {
6081
name: 'postgres-1',
61-
plan: {name: 'heroku-postgresql:hobby-dev'},
82+
plan: {name: 'heroku-postgresql:mini'},
6283
}
6384

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

75-
const err = 'You can’t perform this operation on Essential-tier databases.'
96+
const err = "You can't create a custom credential on Essential-tier databases."
7697
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
7798
})
7899
})

packages/pg-v5/test/unit/commands/credentials/destroy.unit.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,28 @@ Database objects owned by credname will be assigned to the default credential.
7979
'../../lib/fetcher': fetcher,
8080
})
8181

82-
const err = 'Essential-tier databases support only one default credential.'
82+
const err = "You can't destroy the default credential on Essential-tier databases."
83+
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
84+
})
85+
86+
it('throws an error when the db is numbered essential plan', () => {
87+
const essentialAddon = {
88+
name: 'postgres-1',
89+
plan: {name: 'heroku-postgresql:essential-0'},
90+
}
91+
92+
const fetcher = () => {
93+
return {
94+
database: () => db,
95+
addon: () => essentialAddon,
96+
}
97+
}
98+
99+
const cmd = proxyquire('../../../../commands/credentials/destroy', {
100+
'../../lib/fetcher': fetcher,
101+
})
102+
103+
const err = "You can't destroy the default credential on Essential-tier databases."
83104
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
84105
})
85106

packages/pg-v5/test/unit/commands/credentials/rotate.unit.test.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ describe('pg:credentials:rotate', () => {
105105
return expect(cmd.run({app: 'myapp', args: {}, flags: {all: true, name: 'my_role', confirm: 'myapp'}})).to.be.rejectedWith(Error, err)
106106
})
107107

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

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

125-
const err = 'Essential-tier databases support only one default credential.'
125+
const err = "You can't rotate credentials on Essential-tier databases."
126+
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
127+
})
128+
129+
it('throws an error when the db is numbered essential plan', () => {
130+
const essentialAddon = {
131+
name: 'postgres-1',
132+
plan: {name: 'heroku-postgresql:essential-0'},
133+
}
134+
135+
const fetcher = () => {
136+
return {
137+
database: () => db,
138+
addon: () => essentialAddon,
139+
}
140+
}
141+
142+
const cmd = proxyquire('../../../../commands/credentials/rotate', {
143+
'../../lib/fetcher': fetcher,
144+
})
145+
146+
const err = "You can't rotate credentials on Essential-tier databases."
126147
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
127148
})
128149

packages/pg-v5/test/unit/commands/credentials/url.unit.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,28 @@ Connection URL:
9595
'../../lib/fetcher': fetcher,
9696
})
9797

98-
const err = 'Essential-tier databases support only one default credential.'
98+
const err = "You can't view credentials on Essential-tier databases."
99+
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
100+
})
101+
102+
it('throws an error when the db is numbered essential plan', () => {
103+
const essentialAddon = {
104+
name: 'postgres-1',
105+
plan: {name: 'heroku-postgresql:essential-0'},
106+
}
107+
108+
const fetcher = () => {
109+
return {
110+
database: () => db,
111+
addon: () => essentialAddon,
112+
}
113+
}
114+
115+
const cmd = proxyquire('../../../../commands/credentials/url', {
116+
'../../lib/fetcher': fetcher,
117+
})
118+
119+
const err = "You can't view credentials on Essential-tier databases."
99120
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
100121
})
101122

0 commit comments

Comments
 (0)