Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces deprecation and validation warnings for several credential configuration methods and constructors (such as 'fromJSON', 'fromStream', and 'Impersonated'), along with mechanisms to suppress these warnings during internal operations like Application Default Credentials (ADC) loading. It also ensures GAPIC JWT values are synchronized on cached credentials and adds comprehensive unit tests. The review feedback suggests improving the tests by using 'sinon.stub' instead of 'sinon.spy' on 'console.warn' to prevent expected warning messages from cluttering the test execution logs.
| beforeEach(() => { | ||
| sandbox = sinon.createSandbox(); | ||
| auth = new GoogleAuth(); | ||
| warnSpy = sandbox.spy(console, 'warn'); | ||
| }); |
There was a problem hiding this comment.
Using sinon.spy on console.warn allows the warning messages to be printed to the console during test execution, which can clutter the test output and make CI/CD logs noisy. Consider using sandbox.stub instead to silence the expected warnings while still allowing assertions on them.
| beforeEach(() => { | |
| sandbox = sinon.createSandbox(); | |
| auth = new GoogleAuth(); | |
| warnSpy = sandbox.spy(console, 'warn'); | |
| }); | |
| beforeEach(() => { | |
| sandbox = sinon.createSandbox(); | |
| auth = new GoogleAuth(); | |
| warnSpy = sandbox.stub(console, 'warn'); | |
| }); |
| it('should log a warning when called directly', () => { | ||
| const warnSpy = sinon.spy(console, 'warn'); | ||
| try { |
There was a problem hiding this comment.
Using sinon.spy on console.warn allows the warning messages to be printed to the console during test execution, which can clutter the test output and make CI/CD logs noisy. Consider using sinon.stub instead to silence the expected warnings while still allowing assertions on them.
| it('should log a warning when called directly', () => { | |
| const warnSpy = sinon.spy(console, 'warn'); | |
| try { | |
| it('should log a warning when called directly', () => { | |
| const warnSpy = sinon.stub(console, 'warn'); | |
| try { |
| it('should log a warning when instantiated directly', () => { | ||
| const sourceClient = createSampleJWTClient(); | ||
| const warnSpy = sinon.spy(console, 'warn'); | ||
| try { |
There was a problem hiding this comment.
Using sinon.spy on console.warn allows the warning messages to be printed to the console during test execution, which can clutter the test output and make CI/CD logs noisy. Consider using sinon.stub instead to silence the expected warnings while still allowing assertions on them.
| it('should log a warning when instantiated directly', () => { | |
| const sourceClient = createSampleJWTClient(); | |
| const warnSpy = sinon.spy(console, 'warn'); | |
| try { | |
| it('should log a warning when instantiated directly', () => { | |
| const sourceClient = createSampleJWTClient(); | |
| const warnSpy = sinon.stub(console, 'warn'); | |
| try { |
Description
Add runtime deprecation and validation warnings for unvalidated credential loading methods.
Impact
Warns users about unvalidated credentials without emitting warnings during ADC flows.
Changes
console.warnmessages inGoogleAuth.constructor(keyFilename/keyFileandcredentials),GoogleAuth.fromJSON,GoogleAuth.fromStream,ExternalAccountClient.fromJSON, andImpersonated.constructor.keyFilenamedeprecation warning to recommend using theauthobject constructor.@internalwarning suppression helpers (suppressAdcWarningandsuppressFromJsonWarning) insrc/util.tsso Application Default Credentials (_getApplicationCredentialsFromFilePath) never emit warnings for any credential type, and internalfromJSONcalls (_cacheClientFromJSONandfromImpersonatedJSON) do not emit duplicatefromJSONwarnings while preservingthis.fromJSONin the call chain.setGapicJWTValuesuses nullish coalescing assignment (??=) and syncs GAPIC JWT properties on cachedJWTinstances ingetClient().Testing
test/test.externalclient.ts,test/test.impersonated.ts, andtest/test.googleauth.tscovering all 6 warning messages._getApplicationCredentialsFromFilePath), including concurrent non-ADC calls while an ADC stream is reading.setGapicJWTValuessyncs on cachedJWTcredentials whengetClient()is called aftergetProjectId().Alternatives
_fromJSONInternal/_fromStreamInternalAsyncmethods without ADC suppression (as ingoogle-auth-library-nodejs#2176) still emitted warnings during ADC forexternal_accountandimpersonated_service_accountcredentials and bypassedthis.fromJSONspies/overrides.