diff --git a/.gitignore b/.gitignore index f9527c9c6..fcd813bc8 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ twilio.env ### Backup package.json files created during release ### *.bak +.idea/ diff --git a/src/commands/profiles/create.js b/src/commands/profiles/create.js index 940709cff..7d35b4323 100644 --- a/src/commands/profiles/create.js +++ b/src/commands/profiles/create.js @@ -169,8 +169,13 @@ class ProfilesCreate extends BaseCommand { } } + getApiKeyFriendlyName() { + const friendlyName = `twilio-cli for ${os.userInfo().username} on ${os.hostname()}`; + return friendlyName.substring(0, 64); + } + async saveCredentials() { - const apiKeyFriendlyName = `twilio-cli for ${os.userInfo().username} on ${os.hostname()}`; + const apiKeyFriendlyName = this.getApiKeyFriendlyName(); let apiKey = null; const twilioClient = this.getTwilioClient(); diff --git a/test/commands/profiles/create.test.js b/test/commands/profiles/create.test.js index 549de8e06..94af3a9e6 100644 --- a/test/commands/profiles/create.test.js +++ b/test/commands/profiles/create.test.js @@ -4,6 +4,7 @@ const { expect, test, constants } = require('@twilio/cli-test'); const { Config, ConfigData } = require('@twilio/cli-core').services.config; const ProfilesCreate = require('../../../src/commands/profiles/create'); const helpMessages = require('../../../src/services/messaging/help-messages'); +const os = require('os'); describe('commands', () => { describe('profiles', () => { @@ -58,6 +59,19 @@ describe('commands', () => { ); }); + createTest() + .do(ctx => { + sinon.stub(os, 'hostname').returns('some_super_long_fake_hostname'); + sinon.stub(os, 'userInfo').returns({ + username: 'some_super_long_fake_username' + }); + ctx.returned = ctx.testCmd.getApiKeyFriendlyName(); + }) + .it('truncates apiKeyFriendlyName to 64 characters', ctx => { + expect(ctx.returned.length).to.equal(64); + expect(ctx.returned).to.equal('twilio-cli for some_super_long_fake_username on some_super_long_'); + }); + createTest(['not-an-account-sid']) .do(ctx => { const fakePrompt = ctx.testCmd.inquirer.prompt;