Skip to content

Commit

Permalink
test(oauth): UT ensures new token is bubbled up
Browse files Browse the repository at this point in the history
Updated UT to ensure `AuthInfo.refreshFn` always bubbles up the new,
refreshed access token instead of the old one.
  • Loading branch information
cristiand391 committed Jan 16, 2025
1 parent 0919f28 commit fa7817a
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions test/unit/org/authInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,14 +1096,25 @@ describe('AuthInfo', () => {

describe('refreshFn', () => {
it('should call init() and save()', async () => {
const refreshedToken = '123456789abc';

const context = {
getUsername: () => '',
getFields: (decrypt = false) => ({
loginUrl: testOrg.loginUrl,
clientId: testOrg.clientId,
privateKey: 'authInfoTest/jwt/server.key',
accessToken: decrypt ? testOrg.accessToken : testOrg.encryptedAccessToken,
}),
getFields: $$.SANDBOX.stub()
.onFirstCall()
.callsFake((decrypt = false) => ({
loginUrl: testOrg.loginUrl,
clientId: testOrg.clientId,
privateKey: 'authInfoTest/jwt/server.key',
accessToken: decrypt ? testOrg.accessToken : testOrg.encryptedAccessToken,
}))
.onSecondCall()
.callsFake((decrypt = false) => ({
loginUrl: testOrg.loginUrl,
clientId: testOrg.clientId,
privateKey: 'authInfoTest/jwt/server.key',
accessToken: decrypt ? refreshedToken : testOrg.encryptedAccessToken,
})),
initAuthOptions: $$.SANDBOX.stub(),
save: $$.SANDBOX.stub(),
logger: $$.TEST_LOGGER,
Expand All @@ -1119,15 +1130,18 @@ describe('AuthInfo', () => {
expect(context.initAuthOptions.called, 'Should have called AuthInfo.initAuthOptions() during refreshFn()').to.be
.true;
const expectedInitArgs = {
loginUrl: context.getFields().loginUrl,
clientId: context.getFields().clientId,
privateKey: context.getFields().privateKey,
loginUrl: testOrg.loginUrl,
clientId: testOrg.clientId,
privateKey: testOrg.privateKey,
accessToken: testOrg.accessToken,
};
expect(context.initAuthOptions.firstCall.args[0]).to.deep.equal(expectedInitArgs);
expect(context.save.called, 'Should have called AuthInfo.save() during refreshFn()').to.be.true;
expect(testCallback.called, 'Should have called the callback passed to refreshFn()').to.be.true;
expect(testCallback.firstCall.args[1]).to.equal(testOrg.accessToken);
expect(
testCallback.firstCall.args[1],
'Should have passed the new access token to the refreshFn callback'
).to.equal(refreshedToken);
});

it('should path.resolve jwtkeyfilepath', async () => {
Expand Down

4 comments on commit fa7817a

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: fa7817a Previous: 8aed637 Ratio
Child logger creation 479518 ops/sec (±0.47%) 495484 ops/sec (±0.41%) 1.03
Logging a string on root logger 1153870 ops/sec (±5.47%) 1161434 ops/sec (±6.51%) 1.01
Logging an object on root logger 26613 ops/sec (±198.22%) 22983 ops/sec (±201.11%) 0.86
Logging an object with a message on root logger 261702 ops/sec (±89.84%) 599012 ops/sec (±5.63%) 2.29
Logging an object with a redacted prop on root logger 625576 ops/sec (±8.29%) 647085 ops/sec (±7.17%) 1.03
Logging a nested 3-level object on root logger 9609 ops/sec (±209.19%) 29269 ops/sec (±185.00%) 3.05

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: fa7817a Previous: 8aed637 Ratio
Logging an object with a message on root logger 261702 ops/sec (±89.84%) 599012 ops/sec (±5.63%) 2.29
Logging a nested 3-level object on root logger 9609 ops/sec (±209.19%) 29269 ops/sec (±185.00%) 3.05

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Logger Benchmarks - windows-latest

Benchmark suite Current: fa7817a Previous: 8aed637 Ratio
Child logger creation 325326 ops/sec (±1.40%) 314230 ops/sec (±2.96%) 0.97
Logging a string on root logger 845873 ops/sec (±8.13%) 759583 ops/sec (±14.82%) 0.90
Logging an object on root logger 660053 ops/sec (±8.85%) 706134 ops/sec (±9.10%) 1.07
Logging an object with a message on root logger 2045 ops/sec (±276.16%) 20301 ops/sec (±185.46%) 9.93
Logging an object with a redacted prop on root logger 185455 ops/sec (±124.54%) 507957 ops/sec (±8.41%) 2.74
Logging a nested 3-level object on root logger 467926 ops/sec (±6.23%) 23157 ops/sec (±185.46%) 0.049488594350388736

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - windows-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: fa7817a Previous: 8aed637 Ratio
Logging an object with a message on root logger 2045 ops/sec (±276.16%) 20301 ops/sec (±185.46%) 9.93
Logging an object with a redacted prop on root logger 185455 ops/sec (±124.54%) 507957 ops/sec (±8.41%) 2.74

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.