11import { expect , use } from 'chai'
22import chaiAsPromised from 'chai-as-promised'
3- import inquirer from 'inquirer'
43import sinon from 'sinon'
54import { stderr } from 'stdout-stderr'
65
@@ -244,57 +243,7 @@ describe('credential-manager', function () {
244243 stderr . stop ( )
245244 } )
246245
247- it ( 'should use the selected account when an account is not provided' , async function ( ) {
248- const listAccountsStub = sinon . stub ( MacOSHandler . prototype , 'listAccounts' ) . returns ( [ 'user@example.com' ] )
249- const getAuthStub = sinon . stub ( MacOSHandler . prototype , 'getAuth' ) . returns ( 'keychain-token' )
250- const netrcStub = sinon . stub ( NetrcHandler . prototype , 'getAuth' )
251-
252- const auth = await credentialManager . getAuth ( undefined , 'api.heroku.com' )
253-
254- expect ( listAccountsStub . calledOnce ) . to . be . true
255- expect ( listAccountsStub . firstCall . args [ 0 ] ) . to . equal ( 'heroku-cli' )
256- expect ( getAuthStub . calledOnce ) . to . be . true
257- expect ( netrcStub . notCalled ) . to . be . true
258- expect ( auth ) . to . deep . equal ( { account : 'user@example.com' , token : 'keychain-token' } )
259- } )
260-
261- it ( 'should use the selected account when an account is not provided and multiple accounts are found' , async function ( ) {
262- const listAccountsStub = sinon . stub ( MacOSHandler . prototype , 'listAccounts' ) . returns ( [ 'user1@example.com' , 'user2@example.com' ] )
263- const promptStub = ( sinon . stub ( inquirer , 'prompt' ) ) . resolves ( { account : 'user2@example.com' } )
264- const macosStub = sinon . stub ( MacOSHandler . prototype , 'getAuth' ) . returns ( 'keychain-token' )
265- const netrcStub = sinon . stub ( NetrcHandler . prototype , 'getAuth' )
266-
267- const auth = await credentialManager . getAuth ( undefined , 'api.heroku.com' )
268-
269- expect ( listAccountsStub . calledOnce ) . to . be . true
270- expect ( promptStub . calledOnce ) . to . be . true
271- expect ( macosStub . calledOnce ) . to . be . true
272- expect ( netrcStub . notCalled ) . to . be . true
273- expect ( auth ) . to . deep . equal ( { account : 'user2@example.com' , token : 'keychain-token' } )
274- } )
275-
276- it ( 'should fall back to netrc when an account is not provided and no accounts are found' , async function ( ) {
277- sinon . stub ( MacOSHandler . prototype , 'listAccounts' ) . returns ( [ ] )
278- const macosStub = sinon . stub ( MacOSHandler . prototype , 'getAuth' )
279- const netrcStub = sinon . stub ( NetrcHandler . prototype , 'getAuth' )
280- netrcStub . resolves ( { login : 'user@example.com' , password : 'netrc-token' } )
281-
282- stderr . start ( )
283-
284- const auth = await credentialManager . getAuth ( undefined , 'api.heroku.com' )
285-
286- expect ( macosStub . notCalled ) . to . be . true
287- expect ( netrcStub . calledOnce ) . to . be . true
288- expect ( auth ) . to . deep . equal ( { account : 'user@example.com' , token : 'netrc-token' } )
289- expect ( unwrap ( stderr . output ) ) . to . contain ( 'Warning: We can’t retrieve the Heroku token from heroku-cli.' )
290- expect ( unwrap ( stderr . output ) ) . to . contain ( 'We\'ll try to retrieve the token from the .netrc file instead.' )
291- expect ( unwrap ( stderr . output ) ) . to . contain ( 'To turn off this warning, set HEROKU_KEYCHAIN_WARNINGS to "off".' )
292-
293- stderr . stop ( )
294- } )
295-
296- it ( 'should fall back to netrc when an account is not provided and listAccounts fails' , async function ( ) {
297- sinon . stub ( MacOSHandler . prototype , 'listAccounts' ) . throws ( new Error ( 'Keychain error' ) )
246+ it ( 'should fall back to netrc when an account is not provided' , async function ( ) {
298247 const macosStub = sinon . stub ( MacOSHandler . prototype , 'getAuth' )
299248 const netrcStub = sinon . stub ( NetrcHandler . prototype , 'getAuth' )
300249 netrcStub . resolves ( { login : 'user@example.com' , password : 'netrc-token' } )
@@ -306,9 +255,6 @@ describe('credential-manager', function () {
306255 expect ( macosStub . notCalled ) . to . be . true
307256 expect ( netrcStub . calledOnce ) . to . be . true
308257 expect ( auth ) . to . deep . equal ( { account : 'user@example.com' , token : 'netrc-token' } )
309- expect ( unwrap ( stderr . output ) ) . to . contain ( 'Warning: We can’t retrieve the Heroku token from heroku-cli.' )
310- expect ( unwrap ( stderr . output ) ) . to . contain ( 'We\'ll try to retrieve the token from the .netrc file instead.' )
311- expect ( unwrap ( stderr . output ) ) . to . contain ( 'To turn off this warning, set HEROKU_KEYCHAIN_WARNINGS to "off".' )
312258
313259 stderr . stop ( )
314260 } )
0 commit comments