Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import * as open from 'open';
export const getAliasByUsername = async (username: string): Promise<string> => {
const alias = await Aliases.create(Aliases.getDefaultOptions());
const keys = alias.getKeysByValue(username);
return keys?.length ? keys[0] : undefined;
// use the most recently added alias for that username
return keys?.length ? keys[keys.length - 1] : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshanemc is alias list associated with a user guaranteed to remain in order aliases were created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. That's how it seems to behave.
  2. We're not doing any sorting of the object keys in core that I could see
    https://github.com/forcedotcom/sfdx-core/blob/107070d43cfc223c7b4fb9bfa6c1ec1c10166b97/src/config/configGroup.ts#L217

};

export const openUrl = async (url: string): Promise<ChildProcess> => {
Expand Down
4 changes: 2 additions & 2 deletions test/shared/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ describe('getAliasByUsername', () => {
expect(await getAliasByUsername('username1')).to.equal('alias1');
});

it('returns first alias for a username that has multiple aliases', async () => {
expect(await getAliasByUsername('username2')).to.equal('alias2');
it('returns most recent alias for a username that has multiple aliases', async () => {
expect(await getAliasByUsername('username2')).to.equal('alias2b');
});

it('returns undefined when no matching username is found', async () => {
Expand Down