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: do not try and authenticate when error reporting is disabled #676

Merged
merged 6 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/google-apis/auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export class RequestHandler extends Service {
this._config = config;
this._logger = logger;

if (tryAuthenticate) {
if (!this._config.getShouldReportErrorsToAPI()) {
losalex marked this conversation as resolved.
Show resolved Hide resolved
this._logger.info('Not configured to send errors to the API; skipping Google Cloud API Authentication.');
} else if (tryAuthenticate) {
this.authClient.getAccessToken().then(
() => {},
err => {
Expand Down
21 changes: 19 additions & 2 deletions test/unit/google-apis/auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,25 @@ describe('RequestHandler', () => {
);
});

it('should not request OAuth2 token if error reporting is disabled', function (done) {
verifyReportedMessage(
{reportMode: 'never'},
null, // no access token error
{
info: 'Not configured to send errors to the API; skipping Google Cloud API Authentication.',
},
done
);
});

it('should not issue a warning if disabled and can communicate with the API', done => {
process.env.NODE_ENV = 'production';
verifyReportedMessage(
{reportMode: 'never'},
null, // no access token error
{}, // no expected logs
{
info: 'Not configured to send errors to the API; skipping Google Cloud API Authentication.',
},
done
);
});
Expand All @@ -125,7 +138,9 @@ describe('RequestHandler', () => {
verifyReportedMessage(
{reportMode: 'never'},
null, // no access token error
{}, // no expected logs
{
info: 'Not configured to send errors to the API; skipping Google Cloud API Authentication.',
},
done
);
});
Expand Down Expand Up @@ -166,6 +181,7 @@ describe('RequestHandler', () => {
{reportMode: 'production'},
null, // no access token error
{
info: 'Not configured to send errors to the API; skipping Google Cloud API Authentication.',
warn:
'The error reporting client is configured to report ' +
'errors if and only if the NODE_ENV environment variable is set to ' +
Expand All @@ -183,6 +199,7 @@ describe('RequestHandler', () => {
{},
null, // no access token error
{
info: 'Not configured to send errors to the API; skipping Google Cloud API Authentication.',
warn:
'The error reporting client is configured to report ' +
'errors if and only if the NODE_ENV environment variable is set to ' +
Expand Down