Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions lib/utils/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
45 changes: 35 additions & 10 deletions test/lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
}))

Expand All @@ -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',
],
}))

Expand All @@ -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',
],
}))

Expand All @@ -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',
],
}))

Expand All @@ -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',
],
}))

Expand Down Expand Up @@ -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',
],
}))

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
}))
Expand Down Expand Up @@ -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) => {
Expand Down
Loading