Skip to content

Commit e31ffe8

Browse files
GauBenarcanis
andauthored
test(acceptance-tests): add tests for provenance (#6755)
## What's the problem this PR addresses? <!-- Describe the rationale of your PR. --> <!-- Link all issues that it closes. (Closes/Resolves #xxxx.) --> Follow-up #6750: add tests ## How did you fix it? <!-- A detailed description of your implementation. --> New npm publish acceptance tests that verifies the provenance statement validity ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [ ] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [ ] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [ ] I will check that all automated PR checks pass before the PR gets reviewed. --------- Co-authored-by: Maël Nison <[email protected]>
1 parent 2ce5d27 commit e31ffe8

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

.github/workflows/integration-workflow.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ jobs:
241241
runs-on: ${{matrix.platform[0]}}-${{matrix.platform[1]}}
242242
needs: build
243243

244+
# Permission required to produce a valid provenance statement during the tests
245+
# Only run inside the main repository; this may fail in master since it doesn't run in PRs from forks
246+
permissions:
247+
id-token: write
248+
244249
steps:
245250
- uses: actions/checkout@v4
246251

.pnp.cjs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/acceptance-tests/pkg-tests-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"pkg-tests-fixtures": "workspace:^",
2626
"semver": "^7.1.2",
2727
"serve-static": "^1.14.1",
28+
"sigstore": "^3.1.0",
2829
"super-resolve": "^1.0.0",
2930
"tar-fs": "^1.16.0",
3031
"tslib": "^2.4.0"

packages/acceptance-tests/pkg-tests-core/sources/utils/tests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import os from 'os';
1313
import pem from 'pem';
1414
import semver from 'semver';
1515
import serveStatic from 'serve-static';
16+
import * as sigstore from 'sigstore';
1617
import stream from 'stream';
1718
import * as t from 'typanion';
1819
import {promisify} from 'util';
@@ -569,6 +570,15 @@ export const startPackageServer = ({type}: {type: keyof typeof packageServerUrls
569570
if (typeof body.versions[version].gitHead !== `undefined` && name === `githead-forbidden`)
570571
return processError(response, 400, `Unexpected gitHead`);
571572

573+
if (name === `provenance-required`) {
574+
try {
575+
const bundle = JSON.parse(body._attachments[`${name}-${version}.sigstore`].data);
576+
sigstore.verify(bundle);
577+
} catch (error) {
578+
return processError(response, 400, (error as Error).message);
579+
}
580+
}
581+
572582
response.writeHead(200, {[`Content-Type`]: `application/json`});
573583
return response.end(rawData);
574584
});

packages/acceptance-tests/pkg-tests-specs/sources/commands/publish.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {npath, xfs} from '@yarnpkg/fslib';
22

3-
export {};
3+
const {
4+
tests: {testIf},
5+
} = require(`pkg-tests-core`);
46

57
const {
68
exec: {execFile},
@@ -86,4 +88,29 @@ describe(`publish`, () => {
8688
},
8789
});
8890
}));
91+
92+
testIf(
93+
() => !!process.env.ACTIONS_ID_TOKEN_REQUEST_URL,
94+
`should publish a package with a valid provenance statement`,
95+
makeTemporaryEnv({
96+
name: `provenance-required`,
97+
version: `1.0.0`,
98+
}, async ({run}) => {
99+
await run(`install`);
100+
101+
const githubEnv = Object.fromEntries(
102+
Object.entries(process.env).filter(([key]) => (
103+
key.startsWith(`ACTIONS_`) || key.startsWith(`GITHUB_`) || key.startsWith(`RUNNER_`)),
104+
),
105+
);
106+
107+
await run(`npm`, `publish`, {
108+
env: {
109+
...githubEnv,
110+
YARN_NPM_AUTH_TOKEN: validLogins.fooUser.npmAuthToken,
111+
YARN_NPM_PUBLISH_PROVENANCE: `true`,
112+
},
113+
});
114+
}),
115+
);
89116
});

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16872,6 +16872,7 @@ pem@dexus/pem:
1687216872
pkg-tests-fixtures: "workspace:^"
1687316873
semver: "npm:^7.1.2"
1687416874
serve-static: "npm:^1.14.1"
16875+
sigstore: "npm:^3.1.0"
1687516876
super-resolve: "npm:^1.0.0"
1687616877
tar-fs: "npm:^1.16.0"
1687716878
tslib: "npm:^2.4.0"

0 commit comments

Comments
 (0)