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..3b5be104d0801 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,32 @@ 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', + ], + })) + + 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', ], })) @@ -1169,7 +1194,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 +1217,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 +1292,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 +1325,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 +1628,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 +1679,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) => {