Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore expired orgs #5729

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class WorkspaceContextUtil {
this._orgId = '';
if (error instanceof Error) {
console.log(
'There was an problem getting the orgId of the default org: ',
'There was a problem getting the orgId of the default org: ',
error
);
TelemetryService.getInstance().sendException(
Expand Down
33 changes: 14 additions & 19 deletions packages/salesforcedx-vscode-core/src/orgPicker/orgList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { AuthFields, AuthInfo, OrgAuthorization } from '@salesforce/core-bundle';
import {
AuthFields,
AuthInfo,
OrgAuthorization
} from '@salesforce/core-bundle';
import {
CancelResponse,
ConfigUtil,
Expand Down Expand Up @@ -61,7 +65,6 @@ export class OrgList implements vscode.Disposable {
const targetDevHub = await OrgAuthInfo.getDevHubUsername();

const authList = [];
const today = new Date();
for (const orgAuth of orgAuthorizations) {
// When this is called right after logging out of an org, there can
// still be a cached Org Auth in the list with a "No auth information found"
Expand All @@ -88,34 +91,26 @@ export class OrgList implements vscode.Disposable {
// scratch orgs parented by other (non-default) devHub orgs
continue;
}
const isExpired =
authFields && authFields.expirationDate
? today >= new Date(authFields.expirationDate)
: false;

if (orgAuth.isExpired === true) {
// If the scratch org is expired we don't want to see it in the org picker
continue;
}
const aliases = await ConfigUtil.getAllAliasesFor(orgAuth.username);
CristiCanizales marked this conversation as resolved.
Show resolved Hide resolved
let authListItem =
aliases && aliases.length > 0
const authListItem =
aliases?.length > 0
CristiCanizales marked this conversation as resolved.
Show resolved Hide resolved
? `${aliases.join(',')} - ${orgAuth.username}`
: orgAuth.username;

if (isExpired) {
authListItem += ` - ${nls.localize(
'org_expired'
)} ${String.fromCodePoint(0x274c)}`; // cross-mark
}

authList.push(authListItem);
}
return authList;
}

public async updateOrgList(): Promise<string[]> {
const orgAuthorizations = await this.getOrgAuthorizations();
if (orgAuthorizations && orgAuthorizations.length === 0) {
return [];
}
const authUsernameList = await this.filterAuthInfo(orgAuthorizations);
const authUsernameList = await this.filterAuthInfo(
mingxuanzhangsfdx marked this conversation as resolved.
Show resolved Hide resolved
await this.getOrgAuthorizations()
);
return authUsernameList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { AuthInfo, OrgAuthorization, StateAggregator } from '@salesforce/core-bundle';
import {
AuthInfo,
OrgAuthorization,
StateAggregator
} from '@salesforce/core-bundle';
import { ConfigUtil } from '@salesforce/salesforcedx-utils-vscode';
import { expect } from 'chai';
import { createSandbox, SinonStub } from 'sinon';
Expand Down Expand Up @@ -245,7 +249,7 @@ describe('orgList Tests', () => {
expect(authList[0]).to.equal('alias1 - [email protected]');
});

it('should flag the org as expired if expiration date has passed', async () => {
it('should filter the list to ignore expired orgs', async () => {
CristiCanizales marked this conversation as resolved.
Show resolved Hide resolved
const oneDayMillis = 60 * 60 * 24 * 1000;
const today = new Date();
const yesterday = new Date(today.getTime() - oneDayMillis);
Expand Down Expand Up @@ -290,19 +294,11 @@ describe('orgList Tests', () => {

const authList = await orgList.filterAuthInfo(authInfoObjects);

expect(authList[0]).to.equal(
'[email protected] - ' +
nls.localize('org_expired') +
' ' +
String.fromCodePoint(0x274c)
expect(authList).to.not.contain('[email protected]');
expect(authList).to.not.contain(
'[email protected]'
);
expect(authList[1]).to.equal(
'[email protected] - ' +
nls.localize('org_expired') +
' ' +
String.fromCodePoint(0x274c)
);
expect(authList[2]).to.equal('[email protected]');
expect(authList[0]).to.equal('[email protected]');
});
});
describe('Set Default Org', () => {
Expand Down
Loading