@@ -599,17 +599,47 @@ t.test('other error code', async t => {
599
599
} )
600
600
601
601
t . test ( 'publish existing package with provenance in gha' , async t => {
602
+ // Environment variables
602
603
const oidcURL = 'https://mock.oidc'
603
604
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
+
604
613
// Set-up GHA environment variables
605
614
mockGlobals ( t , {
606
615
'process.env' : {
607
616
CI : true ,
608
617
GITHUB_ACTIONS : true ,
609
618
ACTIONS_ID_TOKEN_REQUEST_URL : oidcURL ,
610
619
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 ,
611
627
} ,
612
628
} )
629
+
630
+ const expectedSubject = {
631
+ name : 'pkg:npm/%40npmcli/libnpmpublish-test@1.0.0' ,
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
+
613
643
const { publish } = t . mock ( '..' , { 'ci-info' : t . mock ( 'ci-info' ) } )
614
644
const registry = new MockRegistry ( {
615
645
tap : t ,
@@ -732,7 +762,24 @@ t.test('publish existing package with provenance in gha', async t => {
732
762
733
763
registry . getVisibility ( { spec, visibility : { public : true } } )
734
764
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
+ 'provenance subject matches expectations' )
776
+ t . hasStrict ( provenance . predicate . builder . id ,
777
+ 'https://github.com/actions/runner' ,
778
+ 'provenance subject matches expectations' )
779
+ t . hasStrict ( provenance . predicate . invocation . configSource ,
780
+ expectedConfigSource ,
781
+ 'configSource matches expectations' )
782
+ return true
736
783
} ) . reply ( 201 , { } )
737
784
738
785
const ret = await publish ( manifest , tarData , {
0 commit comments