@@ -980,3 +980,177 @@ t.test('automatic provenance with incorrect permissions', async t => {
980980 }
981981 )
982982} )
983+
984+ t . test ( 'user-supplied provenance - success' , async t => {
985+ const { publish } = t . mock ( '..' , {
986+ '../lib/provenance' : t . mock ( '../lib/provenance' , {
987+ sigstore : { sigstore : { verify : ( ) => { } } } ,
988+ } ) ,
989+ } )
990+
991+ const registry = new MockRegistry ( {
992+ tap : t ,
993+ registry : opts . registry ,
994+ authorization : token ,
995+ } )
996+ const manifest = {
997+ name : '@npmcli/libnpmpublish-test' ,
998+ version : '1.0.0' ,
999+ description : 'test libnpmpublish package' ,
1000+ }
1001+ const spec = npa ( manifest . name )
1002+ const packument = {
1003+ _id : manifest . name ,
1004+ name : manifest . name ,
1005+ description : manifest . description ,
1006+ 'dist-tags' : {
1007+ latest : '1.0.0' ,
1008+ } ,
1009+ versions : {
1010+ '1.0.0' : {
1011+ _id : `${ manifest . name } @${ manifest . version } ` ,
1012+ _nodeVersion : process . versions . node ,
1013+ ...manifest ,
1014+ dist : {
1015+ shasum,
1016+ integrity : integrity . sha512 [ 0 ] . toString ( ) ,
1017+ /* eslint-disable-next-line max-len */
1018+ tarball : 'http://mock.reg/@npmcli/libnpmpublish-test/-/@npmcli/libnpmpublish-test-1.0.0.tgz' ,
1019+ } ,
1020+ } ,
1021+ } ,
1022+ access : 'public' ,
1023+ _attachments : {
1024+ '@npmcli/libnpmpublish-test-1.0.0.tgz' : {
1025+ content_type : 'application/octet-stream' ,
1026+ data : tarData . toString ( 'base64' ) ,
1027+ length : tarData . length ,
1028+ } ,
1029+ '@npmcli/libnpmpublish-test-1.0.0.sigstore' : {
1030+ content_type : 'application/vnd.dev.sigstore.bundle+json;version=0.1' ,
1031+ data : / .* / , // Can't match against static value as signature is always different
1032+ length : 7927 ,
1033+ } ,
1034+ } ,
1035+ }
1036+ registry . nock . put ( `/${ spec . escapedName } ` , body => {
1037+ return t . match ( body , packument , 'posted packument matches expectations' )
1038+ } ) . reply ( 201 , { } )
1039+ const ret = await publish ( manifest , tarData , {
1040+ ...opts ,
1041+ provenanceFile : './test/fixtures/valid-bundle.json' ,
1042+ } )
1043+ t . ok ( ret , 'publish succeeded' )
1044+ } )
1045+
1046+ t . test ( 'user-supplied provenance - failure' , async t => {
1047+ const { publish } = t . mock ( '..' )
1048+ const manifest = {
1049+ name : '@npmcli/libnpmpublish-test' ,
1050+ version : '1.0.0' ,
1051+ description : 'test libnpmpublish package' ,
1052+ }
1053+ await t . rejects (
1054+ publish ( manifest , Buffer . from ( '' ) , {
1055+ ...opts ,
1056+ provenanceFile : './test/fixtures/bad-bundle.json' ,
1057+ } ) ,
1058+ { message : / I n v a l i d p r o v e n a n c e p r o v i d e d / }
1059+ )
1060+ } )
1061+
1062+ t . test ( 'user-supplied provenance - bundle missing DSSE envelope' , async t => {
1063+ const { publish } = t . mock ( '..' )
1064+ const manifest = {
1065+ name : '@npmcli/libnpmpublish-test' ,
1066+ version : '1.0.0' ,
1067+ description : 'test libnpmpublish package' ,
1068+ }
1069+ await t . rejects (
1070+ publish ( manifest , Buffer . from ( '' ) , {
1071+ ...opts ,
1072+ provenanceFile : './test/fixtures/no-provenance-envelope-bundle.json' ,
1073+ } ) ,
1074+ { message : / N o d s s e E n v e l o p e w i t h p a y l o a d f o u n d / }
1075+ )
1076+ } )
1077+
1078+ t . test ( 'user-supplied provenance - bundle with invalid DSSE payload' , async t => {
1079+ const { publish } = t . mock ( '..' )
1080+ const manifest = {
1081+ name : '@npmcli/libnpmpublish-test' ,
1082+ version : '1.0.0' ,
1083+ description : 'test libnpmpublish package' ,
1084+ }
1085+ await t . rejects (
1086+ publish ( manifest , Buffer . from ( '' ) , {
1087+ ...opts ,
1088+ provenanceFile : './test/fixtures/bad-dsse-payload-bundle.json' ,
1089+ } ) ,
1090+ { message : / F a i l e d t o p a r s e p a y l o a d / }
1091+ )
1092+ } )
1093+
1094+ t . test ( 'user-supplied provenance - provenance with missing subject' , async t => {
1095+ const { publish } = t . mock ( '..' )
1096+ const manifest = {
1097+ name : '@npmcli/libnpmpublish-test' ,
1098+ version : '1.0.0' ,
1099+ description : 'test libnpmpublish package' ,
1100+ }
1101+ await t . rejects (
1102+ publish ( manifest , Buffer . from ( '' ) , {
1103+ ...opts ,
1104+ provenanceFile : './test/fixtures/no-provenance-subject-bundle.json' ,
1105+ } ) ,
1106+ { message : / N o s u b j e c t f o u n d / }
1107+ )
1108+ } )
1109+
1110+ t . test ( 'user-supplied provenance - provenance w/ multiple subjects' , async t => {
1111+ const { publish } = t . mock ( '..' )
1112+ const manifest = {
1113+ name : '@npmcli/libnpmpublish-test' ,
1114+ version : '1.0.0' ,
1115+ description : 'test libnpmpublish package' ,
1116+ }
1117+ await t . rejects (
1118+ publish ( manifest , Buffer . from ( '' ) , {
1119+ ...opts ,
1120+ provenanceFile : './test/fixtures/multi-subject-provenance-bundle.json' ,
1121+ } ) ,
1122+ { message : / F o u n d m o r e t h a n o n e s u b j e c t / }
1123+ )
1124+ } )
1125+
1126+ t . test ( 'user-supplied provenance - provenance w/ mismatched subject name' , async t => {
1127+ const { publish } = t . mock ( '..' )
1128+ const manifest = {
1129+ name : '@npmcli/libnpmpublish-fail-test' ,
1130+ version : '1.0.0' ,
1131+ description : 'test libnpmpublish package' ,
1132+ }
1133+ await t . rejects (
1134+ publish ( manifest , Buffer . from ( '' ) , {
1135+ ...opts ,
1136+ provenanceFile : './test/fixtures/valid-bundle.json' ,
1137+ } ) ,
1138+ { message : / P r o v e n a n c e s u b j e c t / }
1139+ )
1140+ } )
1141+
1142+ t . test ( 'user-supplied provenance - provenance w/ mismatched package digest' , async t => {
1143+ const { publish } = t . mock ( '..' )
1144+ const manifest = {
1145+ name : '@npmcli/libnpmpublish-test' ,
1146+ version : '1.0.0' ,
1147+ description : 'test libnpmpublish package' ,
1148+ }
1149+ await t . rejects (
1150+ publish ( manifest , Buffer . from ( '' ) , {
1151+ ...opts ,
1152+ provenanceFile : './test/fixtures/digest-mismatch-provenance-bundle.json' ,
1153+ } ) ,
1154+ { message : / P r o v e n a n c e s u b j e c t d i g e s t d o e s n o t m a t c h / }
1155+ )
1156+ } )
0 commit comments