@@ -599,17 +599,47 @@ t.test('other error code', async t => {
599599} )
600600
601601t . test ( 'publish existing package with provenance in gha' , async t => {
602+ // Environment variables
602603 const oidcURL = 'https://mock.oidc'
603604 const requestToken = 'decafbad'
605+ const workflowPath = '.github/workflows/publish.yml'
606+ const repository = 'github/foo'
607+ const serverUrl = 'https://github.com'
608+ const ref = 'refs/heads/main'
609+ const sha = 'deadbeef'
610+ const runID = '123456'
611+ const runAttempt = '1'
612+
604613 // Set-up GHA environment variables
605614 mockGlobals ( t , {
606615 'process.env' : {
607616 CI : true ,
608617 GITHUB_ACTIONS : true ,
609618 ACTIONS_ID_TOKEN_REQUEST_URL : oidcURL ,
610619 ACTIONS_ID_TOKEN_REQUEST_TOKEN : requestToken ,
620+ GITHUB_WORKFLOW_REF : `${ repository } /${ workflowPath } @${ ref } ` ,
621+ GITHUB_REPOSITORY : repository ,
622+ GITHUB_SERVER_URL : serverUrl ,
623+ GITHUB_REF : ref ,
624+ GITHUB_SHA : sha ,
625+ GITHUB_RUN_ID : runID ,
626+ GITHUB_RUN_ATTEMPT : runAttempt ,
611627 } ,
612628 } )
629+
630+ const expectedSubject = {
631+ name :
'pkg:npm/%40npmcli/[email protected] ' , 632+ digest : {
633+ sha512 : integrity . sha512 [ 0 ] . hexDigest ( ) ,
634+ } ,
635+ }
636+
637+ const expectedConfigSource = {
638+ uri : `git+${ serverUrl } /${ repository } @${ ref } ` ,
639+ digest : { sha1 : sha } ,
640+ entryPoint : workflowPath ,
641+ }
642+
613643 const { publish } = t . mock ( '..' , { 'ci-info' : t . mock ( 'ci-info' ) } )
614644 const registry = new MockRegistry ( {
615645 tap : t ,
@@ -732,7 +762,24 @@ t.test('publish existing package with provenance in gha', async t => {
732762
733763 registry . getVisibility ( { spec, visibility : { public : true } } )
734764 registry . nock . put ( `/${ spec . escapedName } ` , body => {
735- return t . match ( body , packument , 'posted packument matches expectations' )
765+ const bundleAttachment = body . _attachments [ '@npmcli/libnpmpublish-test-1.0.0.sigstore' ]
766+ const bundle = JSON . parse ( bundleAttachment . data )
767+ const provenance = JSON . parse ( Buffer . from ( bundle . dsseEnvelope . payload , 'base64' ) . toString ( ) )
768+
769+ t . hasStrict ( body , packument , 'posted packument matches expectations' )
770+ t . hasStrict ( provenance . subject [ 0 ] ,
771+ expectedSubject ,
772+ 'provenance subject matches expectations' )
773+ t . hasStrict ( provenance . predicate . buildType ,
774+ 'https://github.com/npm/cli/gha/v2' ,
775+ 'buildType matches expectations' )
776+ t . hasStrict ( provenance . predicate . builder . id ,
777+ 'https://github.com/actions/runner' ,
778+ 'builder id matches expectations' )
779+ t . hasStrict ( provenance . predicate . invocation . configSource ,
780+ expectedConfigSource ,
781+ 'configSource matches expectations' )
782+ return true
736783 } ) . reply ( 201 , { } )
737784
738785 const ret = await publish ( manifest , tarData , {
0 commit comments