Skip to content

Commit 4610389

Browse files
committed
test: add workspace regression test for shared-config provenance leak
Publish two public workspaces in order: one without provenance-file, for which OIDC automatically enables provenance, followed by one with publishConfig["provenance-file"]. Assert each publish receives exactly its own options ({ provenance: true } then { provenance: false, provenanceFile }) and that the shared config stays at its default, so an automatically derived package-specific decision cannot leak into subsequent workspace publishes. Extends mock-oidc with a times option on the GitHub id-token mock so a single fixture setup can serve one token request per workspace. Refs: #9882 (comment) Signed-off-by: Yunseo Kim <[email protected]>
1 parent b55f4f7 commit 4610389

2 files changed

Lines changed: 102 additions & 1 deletion

File tree

‎test/fixtures/mock-oidc.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,12 @@ const mockOidc = async (t, {
117117
})
118118

119119
if (mockGithubOidcOptions) {
120-
const { idToken, audience, statusCode = 200 } = mockGithubOidcOptions
120+
const { idToken, audience, statusCode = 200, times = 1 } = mockGithubOidcOptions
121121
const url = new URL(ACTIONS_ID_TOKEN_REQUEST_URL)
122122
nock(url.origin)
123123
.get(url.pathname)
124124
.query({ audience })
125+
.times(times)
125126
.matchHeader('authorization', `Bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}`)
126127
.matchHeader('accept', 'application/json')
127128
.reply(statusCode, statusCode !== 500 ? { value: idToken } : { message: 'Internal Server Error' })

‎test/lib/commands/publish.js‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,106 @@ t.test('oidc token exchange - provenance', (t) => {
16851685
})
16861686
}
16871687

1688+
t.test('automatic provenance does not leak between workspace publishes', async t => {
1689+
const provenanceBundlePath = path.join(t.testdir(), 'provenance-bundle.json')
1690+
const autoPackage = 'workspace-auto-provenance'
1691+
const filePackage = 'workspace-file-provenance'
1692+
const publishCalls = []
1693+
const prefixDir = {
1694+
'package.json': JSON.stringify({
1695+
name: 'workspace-root',
1696+
version: '1.0.0',
1697+
workspaces: [autoPackage, filePackage],
1698+
}),
1699+
[autoPackage]: {
1700+
'package.json': JSON.stringify({
1701+
name: autoPackage,
1702+
version: '1.0.0',
1703+
}),
1704+
},
1705+
[filePackage]: {
1706+
'package.json': JSON.stringify({
1707+
name: filePackage,
1708+
version: '1.0.0',
1709+
publishConfig: {
1710+
'provenance-file': provenanceBundlePath,
1711+
},
1712+
}),
1713+
},
1714+
}
1715+
1716+
const { npm, registry } = await mockOidc(t, {
1717+
oidcOptions: { github: true },
1718+
packageName: autoPackage,
1719+
config: {
1720+
'//registry.npmjs.org/:_authToken': 'existing-fallback-token',
1721+
workspaces: true,
1722+
},
1723+
mockGithubOidcOptions: {
1724+
audience: 'npm:registry.npmjs.org',
1725+
idToken: githubPublicIdToken,
1726+
times: 2,
1727+
},
1728+
mockOidcTokenExchangeOptions: {
1729+
idToken: githubPublicIdToken,
1730+
body: {
1731+
token: 'exchange-token',
1732+
},
1733+
},
1734+
publishOptions: {
1735+
noPut: true,
1736+
},
1737+
load: {
1738+
prefixDir,
1739+
mocks: {
1740+
libnpmaccess: {
1741+
getVisibility: async () => ({ public: true }),
1742+
},
1743+
// mocked as a plain module so the publish options each workspace
1744+
// receives can be recorded verbatim
1745+
libnpmpublish: {
1746+
publish: async (manifest, _tarballData, opts) => {
1747+
publishCalls.push({
1748+
name: manifest.name,
1749+
provenance: opts.provenance,
1750+
provenanceFile: opts.provenanceFile,
1751+
})
1752+
},
1753+
},
1754+
},
1755+
},
1756+
})
1757+
1758+
registry.mockOidcTokenExchange({
1759+
packageName: filePackage,
1760+
idToken: githubPublicIdToken,
1761+
body: {
1762+
token: 'exchange-token',
1763+
},
1764+
})
1765+
registry.publish(filePackage, { noPut: true })
1766+
1767+
await npm.exec('publish', [])
1768+
1769+
t.strictSame(publishCalls, [
1770+
{
1771+
name: autoPackage,
1772+
provenance: true,
1773+
provenanceFile: null,
1774+
},
1775+
{
1776+
name: filePackage,
1777+
provenance: false,
1778+
provenanceFile: provenanceBundlePath,
1779+
},
1780+
])
1781+
t.equal(
1782+
npm.config.isDefault('provenance'),
1783+
true,
1784+
'automatic provenance does not mutate shared config'
1785+
)
1786+
})
1787+
16881788
const brokenJwts = [
16891789
'x.invalid-jwt.x',
16901790
'x.invalid-jwt.',

0 commit comments

Comments
 (0)