From 51860f6b7818ab448ac01720510fc897137db9fc Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Fri, 28 Aug 2026 02:58:48 +0500 Subject: [PATCH 1/2] fix: log oidc failures at warn level --- lib/utils/oidc.js | 12 ++++++------ test/lib/commands/publish.js | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/utils/oidc.js b/lib/utils/oidc.js index 00f32c642621c..8bdebee1d9c30 100644 --- a/lib/utils/oidc.js +++ b/lib/utils/oidc.js @@ -93,12 +93,12 @@ async function oidc ({ packageName, registry, opts, config }) { const json = await response.json() if (!response.ok) { - log.verbose('oidc', `Failed to fetch id_token from GitHub: received an invalid response`) + log.warn('oidc', `Failed to fetch id_token from GitHub: received an invalid response`) return undefined } if (!json.value) { - log.verbose('oidc', `Failed to fetch id_token from GitHub: missing value`) + log.warn('oidc', `Failed to fetch id_token from GitHub: missing value`) return undefined } @@ -123,12 +123,12 @@ async function oidc ({ packageName, registry, opts, config }) { method: 'POST', }) } catch (error) { - log.verbose('oidc', `Failed token exchange request with body message: ${error?.body?.message || 'Unknown error'}`) + log.warn('oidc', `Failed token exchange request with body message: ${error?.body?.message || 'Unknown error'}`) return undefined } if (!response?.token) { - log.verbose('oidc', 'Failed because token exchange was missing the token in the response body') + log.warn('oidc', 'Failed because token exchange was missing the token in the response body') return undefined } @@ -164,10 +164,10 @@ async function oidc ({ packageName, registry, opts, config }) { } } } catch (error) { - log.verbose('oidc', `Failed to set provenance with message: ${error?.message || 'Unknown error'}`) + log.warn('oidc', `Failed to set provenance with message: ${error?.message || 'Unknown error'}`) } } catch (error) { - log.verbose('oidc', `Failure with message: ${error?.message || 'Unknown error'}`) + log.warn('oidc', `Failure with message: ${error?.message || 'Unknown error'}`) } return undefined } diff --git a/test/lib/commands/publish.js b/test/lib/commands/publish.js index ec2c2fd9c8b66..ebc41e6bec50b 100644 --- a/test/lib/commands/publish.js +++ b/test/lib/commands/publish.js @@ -1106,7 +1106,7 @@ t.test('oidc token exchange - no provenance', t => { token: 'existing-fallback-token', }, logsContain: [ - 'verbose oidc Failed to fetch id_token from GitHub: received an invalid response', + 'warn oidc Failed to fetch id_token from GitHub: received an invalid response', ], })) @@ -1123,7 +1123,7 @@ t.test('oidc token exchange - no provenance', t => { token: 'existing-fallback-token', }, logsContain: [ - 'verbose oidc Failed to fetch id_token from GitHub: missing value', + 'warn oidc Failed to fetch id_token from GitHub: missing value', ], })) @@ -1147,7 +1147,7 @@ t.test('oidc token exchange - no provenance', t => { token: 'existing-fallback-token', }, logsContain: [ - 'verbose oidc Failed token exchange request with body message: oidc token exchange failed', + 'warn oidc Failed token exchange request with body message: oidc token exchange failed', ], })) @@ -1169,7 +1169,7 @@ t.test('oidc token exchange - no provenance', t => { token: 'existing-fallback-token', }, logsContain: [ - 'verbose oidc Failed token exchange request with body message: Unknown error', + 'warn oidc Failed token exchange request with body message: Unknown error', ], })) @@ -1192,7 +1192,7 @@ t.test('oidc token exchange - no provenance', t => { token: 'existing-fallback-token', }, logsContain: [ - 'verbose oidc Failed because token exchange was missing the token in the response body', + 'warn oidc Failed because token exchange was missing the token in the response body', ], })) @@ -1267,7 +1267,7 @@ t.test('oidc token exchange - no provenance', t => { token: 'existing-fallback-token', }, logsContain: [ - 'verbose oidc Failure with message: Invalid URL', + 'warn oidc Failure with message: Invalid URL', ], })) @@ -1300,7 +1300,7 @@ t.test('oidc token exchange - no provenance', t => { await npm.exec('publish', []) t.match(joinedOutput(), '+ @npmcli/test-package@1.0.0') - t.ok(logs.includes('verbose oidc Failure with message: Unknown error')) + t.ok(logs.includes('warn oidc Failure with message: Unknown error')) }) t.test('default registry success gitlab', oidcPublishTest({ @@ -1603,7 +1603,7 @@ t.test('oidc token exchange - provenance', (t) => { token: 'existing-fallback-token', }, logsContain: [ - 'verbose oidc Failed token exchange request with body message: oidc token exchange failed', + 'warn oidc Failed token exchange request with body message: oidc token exchange failed', ], provenance: false, })) @@ -1654,10 +1654,10 @@ t.test('oidc token exchange - provenance', (t) => { const provenanceFailures = [[ new Error('Valid error'), - 'verbose oidc Failed to set provenance with message: Valid error', + 'warn oidc Failed to set provenance with message: Valid error', ], [ 'Valid error', - 'verbose oidc Failed to set provenance with message: Unknown error', + 'warn oidc Failed to set provenance with message: Unknown error', ]] provenanceFailures.forEach(([error, logMessage], index) => { From b4784e5121031d5e9d19b13ae1905bb7d312073e Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Fri, 28 Aug 2026 03:08:35 +0500 Subject: [PATCH 2/2] fix: cover oidc warn at default loglevel --- test/lib/commands/publish.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/lib/commands/publish.js b/test/lib/commands/publish.js index ebc41e6bec50b..3b5be104d0801 100644 --- a/test/lib/commands/publish.js +++ b/test/lib/commands/publish.js @@ -1151,6 +1151,31 @@ t.test('oidc token exchange - no provenance', t => { ], })) + t.test('token exchange 500 with fallback at default loglevel', oidcPublishTest({ + oidcOptions: { github: true }, + config: { + loglevel: 'notice', + '//registry.npmjs.org/:_authToken': 'existing-fallback-token', + }, + mockGithubOidcOptions: { + audience: 'npm:registry.npmjs.org', + idToken: githubPrivateIdToken, + }, + mockOidcTokenExchangeOptions: { + statusCode: 500, + idToken: githubPrivateIdToken, + body: { + message: 'oidc token exchange failed', + }, + }, + publishOptions: { + token: 'existing-fallback-token', + }, + logsContain: [ + 'warn oidc Failed token exchange request with body message: oidc token exchange failed', + ], + })) + t.test('token exchange 500 with no body message with fallback', oidcPublishTest({ oidcOptions: { github: true }, config: {