-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: provenance build type v2 (#6228)
Signed-off-by: Brian DeHamer <[email protected]> Co-authored-by: Philip Harrison <[email protected]>
- Loading branch information
Showing
2 changed files
with
58 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -599,17 +599,47 @@ t.test('other error code', async t => { | |
}) | ||
|
||
t.test('publish existing package with provenance in gha', async t => { | ||
// Environment variables | ||
const oidcURL = 'https://mock.oidc' | ||
const requestToken = 'decafbad' | ||
const workflowPath = '.github/workflows/publish.yml' | ||
const repository = 'github/foo' | ||
const serverUrl = 'https://github.com' | ||
const ref = 'refs/heads/main' | ||
const sha = 'deadbeef' | ||
const runID = '123456' | ||
const runAttempt = '1' | ||
|
||
// Set-up GHA environment variables | ||
mockGlobals(t, { | ||
'process.env': { | ||
CI: true, | ||
GITHUB_ACTIONS: true, | ||
ACTIONS_ID_TOKEN_REQUEST_URL: oidcURL, | ||
ACTIONS_ID_TOKEN_REQUEST_TOKEN: requestToken, | ||
GITHUB_WORKFLOW_REF: `${repository}/${workflowPath}@${ref}`, | ||
GITHUB_REPOSITORY: repository, | ||
GITHUB_SERVER_URL: serverUrl, | ||
GITHUB_REF: ref, | ||
GITHUB_SHA: sha, | ||
GITHUB_RUN_ID: runID, | ||
GITHUB_RUN_ATTEMPT: runAttempt, | ||
}, | ||
}) | ||
|
||
const expectedSubject = { | ||
name: 'pkg:npm/%40npmcli/[email protected]', | ||
digest: { | ||
sha512: integrity.sha512[0].hexDigest(), | ||
}, | ||
} | ||
|
||
const expectedConfigSource = { | ||
uri: `git+${serverUrl}/${repository}@${ref}`, | ||
digest: { sha1: sha }, | ||
entryPoint: workflowPath, | ||
} | ||
|
||
const { publish } = t.mock('..', { 'ci-info': t.mock('ci-info') }) | ||
const registry = new MockRegistry({ | ||
tap: t, | ||
|
@@ -732,7 +762,24 @@ t.test('publish existing package with provenance in gha', async t => { | |
|
||
registry.getVisibility({ spec, visibility: { public: true } }) | ||
registry.nock.put(`/${spec.escapedName}`, body => { | ||
return t.match(body, packument, 'posted packument matches expectations') | ||
const bundleAttachment = body._attachments['@npmcli/libnpmpublish-test-1.0.0.sigstore'] | ||
const bundle = JSON.parse(bundleAttachment.data) | ||
const provenance = JSON.parse(Buffer.from(bundle.dsseEnvelope.payload, 'base64').toString()) | ||
|
||
t.hasStrict(body, packument, 'posted packument matches expectations') | ||
t.hasStrict(provenance.subject[0], | ||
expectedSubject, | ||
'provenance subject matches expectations') | ||
t.hasStrict(provenance.predicate.buildType, | ||
'https://github.com/npm/cli/gha/v2', | ||
'buildType matches expectations') | ||
t.hasStrict(provenance.predicate.builder.id, | ||
'https://github.com/actions/runner', | ||
'builder id matches expectations') | ||
t.hasStrict(provenance.predicate.invocation.configSource, | ||
expectedConfigSource, | ||
'configSource matches expectations') | ||
return true | ||
}).reply(201, {}) | ||
|
||
const ret = await publish(manifest, tarData, { | ||
|