Skip to content

test(acceptance-tests): add tests for provenance #6755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 9, 2025
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ jobs:
runs-on: ${{matrix.platform[0]}}-${{matrix.platform[1]}}
needs: build

# Permission required to produce a valid provenance statement during the tests
# Only run inside the main repository; this may fail in master since it doesn't run in PRs from forks
permissions:
id-token: write

steps:
- uses: actions/checkout@v4

Expand Down
1 change: 1 addition & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/acceptance-tests/pkg-tests-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"pkg-tests-fixtures": "workspace:^",
"semver": "^7.1.2",
"serve-static": "^1.14.1",
"sigstore": "^3.1.0",
"super-resolve": "^1.0.0",
"tar-fs": "^1.16.0",
"tslib": "^2.4.0"
Expand Down
10 changes: 10 additions & 0 deletions packages/acceptance-tests/pkg-tests-core/sources/utils/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import os from 'os';
import pem from 'pem';
import semver from 'semver';
import serveStatic from 'serve-static';
import * as sigstore from 'sigstore';
import stream from 'stream';
import * as t from 'typanion';
import {promisify} from 'util';
Expand Down Expand Up @@ -559,6 +560,15 @@ export const startPackageServer = ({type}: {type: keyof typeof packageServerUrls
if (typeof body.versions[version].gitHead !== `undefined` && name === `githead-forbidden`)
return processError(response, 400, `Unexpected gitHead`);

if (name === `provenance-required`) {
try {
const bundle = JSON.parse(body._attachments[`${name}-${version}.sigstore`].data);
sigstore.verify(bundle);
} catch (error) {
return processError(response, 400, (error as Error).message);
}
}

response.writeHead(200, {[`Content-Type`]: `application/json`});
return response.end(rawData);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {npath, xfs} from '@yarnpkg/fslib';

export {};
const {
tests: {testIf},
} = require(`pkg-tests-core`);

const {
exec: {execFile},
Expand Down Expand Up @@ -86,4 +88,29 @@ describe(`publish`, () => {
},
});
}));

testIf(
() => !!process.env.ACTIONS_ID_TOKEN_REQUEST_URL,
`should publish a package with a valid provenance statement`,
makeTemporaryEnv({
name: `provenance-required`,
version: `1.0.0`,
}, async ({run}) => {
await run(`install`);

const githubEnv = Object.fromEntries(
Object.entries(process.env).filter(([key]) => (
key.startsWith(`ACTIONS_`) || key.startsWith(`GITHUB_`) || key.startsWith(`RUNNER_`)),
),
);

await run(`npm`, `publish`, {
env: {
...githubEnv,
YARN_NPM_AUTH_TOKEN: validLogins.fooUser.npmAuthToken,
YARN_NPM_PUBLISH_PROVENANCE: `true`,
},
});
}),
);
});
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16859,6 +16859,7 @@ pem@dexus/pem:
pkg-tests-fixtures: "workspace:^"
semver: "npm:^7.1.2"
serve-static: "npm:^1.14.1"
sigstore: "npm:^3.1.0"
super-resolve: "npm:^1.0.0"
tar-fs: "npm:^1.16.0"
tslib: "npm:^2.4.0"
Expand Down
Loading