Skip to content

Commit

Permalink
fix: eagerly load keytar during profile creation (twilio#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
childish-sambino committed Nov 21, 2019
1 parent 6982963 commit e505e17
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/commands/profiles/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class ProfilesCreate extends BaseCommand {
async run() {
await super.run();

// Eagerly load up the credential store. No need to proceed if this fails.
await this.secureStorage.loadKeytar();

this.loadArguments();
await this.promptForProfileId();

Expand Down
9 changes: 9 additions & 0 deletions test/commands/profiles/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('commands', () => {
authToken: constants.FAKE_API_SECRET
});
ctx.testCmd.inquirer.prompt = fakePrompt;
ctx.testCmd.secureStorage.loadKeytar = sinon.fake.resolves(true);
});

createTest()
Expand Down Expand Up @@ -129,6 +130,14 @@ describe('commands', () => {
.catch(/Could not create an API Key/)
.it('fails to create an API key');

createTest()
.do(ctx => {
ctx.testCmd.secureStorage.loadKeytar = sinon.fake.rejects('ugh');
})
.do(ctx => ctx.testCmd.run())
.catch(/ugh/)
.it('fails early if keytar cannot be loaded');

createTest(['--region', 'dev'])
.nock('https://api.dev.twilio.com', api => {
api.get(`/2010-04-01/Accounts/${constants.FAKE_ACCOUNT_SID}.json`).reply(200, {
Expand Down

0 comments on commit e505e17

Please sign in to comment.