Skip to content

Commit

Permalink
fix: use empty string for client secret when client secret is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jun 27, 2019
1 parent 3971775 commit 9513551
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/authInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export class AuthInfo extends AsyncCreatable<AuthInfo.Options> {
let sfdxAuthUrl = 'force://';

if (decryptedFields.clientId) {
sfdxAuthUrl += `${decryptedFields.clientId}:${decryptedFields.clientSecret}:`;
sfdxAuthUrl += `${decryptedFields.clientId}:${decryptedFields.clientSecret || ''}:`;
}

sfdxAuthUrl += `${decryptedFields.refreshToken}@${instanceUrl}`;
Expand Down
32 changes: 32 additions & 0 deletions test/unit/authInfoTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,38 @@ describe('AuthInfo', () => {
}@mydevhub.localhost.internal.salesforce.com:6109`
);
});

it('should hanlde undefined client secret', async () => {
const username = 'authInfoTest_username_RefreshToken';
const refreshTokenConfig = {
refreshToken: testMetadata.refreshToken,
loginUrl: testMetadata.loginUrl
};

const authResponse = {
access_token: testMetadata.accessToken,
instance_url: testMetadata.instanceUrl,
id: '00DAuthInfoTest_orgId/005AuthInfoTest_userId'
};

// Stub the http request (OAuth2.refreshToken())
_postParmsStub.returns(Promise.resolve(authResponse));

// Create the refresh token AuthInfo instance
const authInfo = await AuthInfo.create({
username,
oauth2Options: refreshTokenConfig
});

// delete the client secret
delete authInfo.getFields().clientSecret;

expect(authInfo.getSfdxAuthUrl()).to.contain(
`force://SalesforceDevelopmentExperience::${
testMetadata.refreshToken
}@mydevhub.localhost.internal.salesforce.com:6109`
);
});
});

describe('audienceUrl', () => {
Expand Down

0 comments on commit 9513551

Please sign in to comment.