Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit 4915e97

Browse files
authored
chore(deps): upgrade sinon to 21 (#2050)
* chore(deps): upgrade sinon to 21 * specify which timers to fake * use @feywind's util for timers * add crucial file
1 parent bd7e4e3 commit 4915e97

12 files changed

Lines changed: 86 additions & 24 deletions

.github/scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"devDependencies": {
1717
"@octokit/rest": "^19.0.0",
1818
"mocha": "^10.0.0",
19-
"sinon": "^18.0.0"
19+
"sinon": "^21.0.0"
2020
}
2121
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"nock": "^14.0.1",
5757
"null-loader": "^4.0.0",
5858
"puppeteer": "^24.0.0",
59-
"sinon": "^18.0.1",
59+
"sinon": "^21.0.0",
6060
"ts-loader": "^8.0.0",
6161
"typescript": "^5.1.6",
6262
"webpack": "^5.21.2",

test/test.awsclient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
getExpectedExternalAccountMetricsHeaderValue,
3030
} from './externalclienthelper';
3131
import {AwsSecurityCredentials} from '../src/auth/awsrequestsigner';
32-
32+
import {TestUtils} from './utils';
3333
nock.disableNetConnect();
3434

3535
const ONE_HOUR_IN_SECS = 3600;
@@ -175,7 +175,7 @@ describe('AwsClient', () => {
175175
);
176176

177177
beforeEach(() => {
178-
clock = sinon.useFakeTimers(referenceDate);
178+
clock = TestUtils.useFakeTimers(sinon, referenceDate);
179179
});
180180

181181
afterEach(() => {

test/test.awsrequestsigner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {describe, it, afterEach, beforeEach} from 'mocha';
1717
import * as sinon from 'sinon';
1818
import {AwsRequestSigner} from '../src/auth/awsrequestsigner';
1919
import {GaxiosOptions} from 'gaxios';
20-
20+
import {TestUtils} from './utils';
2121
/** Defines the interface to facilitate testing of AWS request signing. */
2222
interface AwsRequestSignerTest {
2323
// Test description.
@@ -41,7 +41,7 @@ describe('AwsRequestSigner', () => {
4141
const token = awsSecurityCredentials.Token;
4242

4343
beforeEach(() => {
44-
clock = sinon.useFakeTimers(0);
44+
clock = TestUtils.useFakeTimers(sinon);
4545
});
4646

4747
afterEach(() => {

test/test.baseexternalclient.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
getExpectedExternalAccountMetricsHeaderValue,
4141
} from './externalclienthelper';
4242
import {DEFAULT_UNIVERSE} from '../src/auth/authclient';
43-
43+
import {TestUtils} from './utils';
4444
nock.disableNetConnect();
4545

4646
interface SampleResponse {
@@ -965,7 +965,7 @@ describe('BaseExternalAccountClient', () => {
965965
});
966966

967967
it('should force refresh when cached credential is expired', async () => {
968-
clock = sinon.useFakeTimers(0);
968+
clock = TestUtils.useFakeTimers(sinon);
969969
const emittedEvents: Credentials[] = [];
970970
const stsSuccessfulResponse2 = Object.assign({}, stsSuccessfulResponse);
971971
stsSuccessfulResponse2.access_token = 'ACCESS_TOKEN2';
@@ -1063,7 +1063,8 @@ describe('BaseExternalAccountClient', () => {
10631063
});
10641064

10651065
it('should respect provided eagerRefreshThresholdMillis', async () => {
1066-
clock = sinon.useFakeTimers(0);
1066+
clock = TestUtils.useFakeTimers(sinon);
1067+
10671068
const customThresh = 10 * 1000;
10681069
const stsSuccessfulResponse2 = Object.assign({}, stsSuccessfulResponse);
10691070
stsSuccessfulResponse2.access_token = 'ACCESS_TOKEN2';
@@ -1381,7 +1382,7 @@ describe('BaseExternalAccountClient', () => {
13811382
});
13821383

13831384
it('should force refresh when cached credential is expired', async () => {
1384-
clock = sinon.useFakeTimers(0);
1385+
clock = TestUtils.useFakeTimers(sinon);
13851386
const emittedEvents: Credentials[] = [];
13861387
const stsSuccessfulResponse2 = Object.assign({}, stsSuccessfulResponse);
13871388
stsSuccessfulResponse2.access_token = 'ACCESS_TOKEN2';
@@ -1505,7 +1506,7 @@ describe('BaseExternalAccountClient', () => {
15051506
});
15061507

15071508
it('should respect provided eagerRefreshThresholdMillis', async () => {
1508-
clock = sinon.useFakeTimers(0);
1509+
clock = TestUtils.useFakeTimers(sinon);
15091510
const customThresh = 10 * 1000;
15101511
const stsSuccessfulResponse2 = Object.assign({}, stsSuccessfulResponse);
15111512
stsSuccessfulResponse2.access_token = 'ACCESS_TOKEN2';
@@ -2540,7 +2541,7 @@ describe('BaseExternalAccountClient', () => {
25402541

25412542
describe('setCredentials()', () => {
25422543
it('should allow injection of GCP access tokens directly', async () => {
2543-
clock = sinon.useFakeTimers(0);
2544+
clock = TestUtils.useFakeTimers(sinon);
25442545
const credentials = {
25452546
access_token: 'INJECTED_ACCESS_TOKEN',
25462547
// Simulate token expires in 10mins.
@@ -2581,7 +2582,7 @@ describe('BaseExternalAccountClient', () => {
25812582
});
25822583

25832584
it('should not expire injected creds with no expiry_date', async () => {
2584-
clock = sinon.useFakeTimers(0);
2585+
clock = TestUtils.useFakeTimers(sinon);
25852586
const credentials = {
25862587
access_token: 'INJECTED_ACCESS_TOKEN',
25872588
};

test/test.downscopedclient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
getErrorFromOAuthErrorResponse,
3333
} from '../src/auth/oauth2common';
3434
import {GetAccessTokenResponse} from '../src/auth/authclient';
35-
35+
import {TestUtils} from './utils';
3636
nock.disableNetConnect();
3737

3838
/** A dummy class used as source credential for testing. */
@@ -376,7 +376,7 @@ describe('DownscopedClient', () => {
376376
describe('getAccessToken()', () => {
377377
it('should return current unexpired cached DownscopedClient access token', async () => {
378378
const now = new Date().getTime();
379-
clock = sinon.useFakeTimers(now);
379+
clock = TestUtils.useFakeTimers(sinon, now);
380380
const credentials = {
381381
access_token: 'DOWNSCOPED_CLIENT_ACCESS_TOKEN',
382382
expiry_date: now + ONE_HOUR_IN_SECS * 1000,
@@ -415,7 +415,7 @@ describe('DownscopedClient', () => {
415415

416416
it('should refresh a new DownscopedClient access when cached one gets expired', async () => {
417417
const now = new Date().getTime();
418-
clock = sinon.useFakeTimers(now);
418+
clock = TestUtils.useFakeTimers(sinon, now);
419419
const emittedEvents: Credentials[] = [];
420420
const credentials = {
421421
access_token: 'DOWNSCOPED_CLIENT_ACCESS_TOKEN',

test/test.executableresponse.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
ExecutableResponseJson,
2626
} from '../src/auth/executable-response';
2727
import * as sinon from 'sinon';
28+
import {TestUtils} from './utils';
2829

2930
const SAML_SUBJECT_TOKEN_TYPE = 'urn:ietf:params:oauth:token-type:saml2';
3031
const OIDC_SUBJECT_TOKEN_TYPE1 = 'urn:ietf:params:oauth:token-type:id_token';
@@ -35,7 +36,7 @@ describe('ExecutableResponse', () => {
3536
const referenceTime = 1653429377000;
3637

3738
beforeEach(() => {
38-
clock = sinon.useFakeTimers({now: referenceTime});
39+
clock = TestUtils.useFakeTimers(sinon, referenceTime);
3940
});
4041

4142
afterEach(() => {

test/test.externalaccountauthorizeduserclient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
OAuthErrorResponse,
3131
} from '../src/auth/oauth2common';
3232
import {DEFAULT_UNIVERSE} from '../src/auth/authclient';
33+
import {TestUtils} from './utils';
3334

3435
nock.disableNetConnect();
3536

@@ -110,7 +111,7 @@ describe('ExternalAccountAuthorizedUserClient', () => {
110111
expires_in: 3600,
111112
};
112113
beforeEach(() => {
113-
clock = sinon.useFakeTimers(referenceDate);
114+
clock = TestUtils.useFakeTimers(sinon, referenceDate);
114115
});
115116

116117
afterEach(() => {

test/test.pluggableauthclient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
} from '../src/auth/executable-response';
3838
import {PluggableAuthHandler} from '../src/auth/pluggable-auth-handler';
3939
import {StsSuccessfulResponse} from '../src/auth/stscredentials';
40+
import {TestUtils} from './utils';
4041

4142
const OIDC_SUBJECT_TOKEN_TYPE1 = 'urn:ietf:params:oauth:token-type:id_token';
4243
const SAML_SUBJECT_TOKEN_TYPE = 'urn:ietf:params:oauth:token-type:saml2';
@@ -113,7 +114,7 @@ describe('PluggableAuthClient', () => {
113114
GOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES: '1',
114115
});
115116
sandbox.stub(process, 'env').value(envVars);
116-
clock = sinon.useFakeTimers({now: referenceTime});
117+
clock = TestUtils.useFakeTimers(sinon, referenceTime);
117118

118119
responseJson = {
119120
success: true,

test/test.pluggableauthhandler.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
} from '../src/auth/pluggable-auth-handler';
3131
import * as assert from 'assert';
3232
import {ExecutableError} from '../src/auth/pluggable-auth-client';
33+
import {TestUtils} from './utils';
3334

3435
const OIDC_SUBJECT_TOKEN_TYPE1 = 'urn:ietf:params:oauth:token-type:id_token';
3536
const SAML_SUBJECT_TOKEN_TYPE = 'urn:ietf:params:oauth:token-type:saml2';
@@ -121,8 +122,7 @@ describe('PluggableAuthHandler', () => {
121122
beforeEach(() => {
122123
// Stub environment variables
123124
sandbox.stub(process, 'env').value(process.env);
124-
clock = sandbox.useFakeTimers({now: referenceTime});
125-
125+
clock = TestUtils.useFakeTimers(sinon, referenceTime);
126126
defaultResponseJson = {
127127
success: true,
128128
version: 1,
@@ -371,8 +371,7 @@ describe('PluggableAuthHandler', () => {
371371
let defaultResponseJson: ExecutableResponseJson;
372372

373373
beforeEach(() => {
374-
clock = sandbox.useFakeTimers({now: referenceTime});
375-
374+
clock = TestUtils.useFakeTimers(sinon, referenceTime);
376375
defaultResponseJson = {
377376
success: true,
378377
version: 1,

0 commit comments

Comments
 (0)