@@ -473,3 +473,126 @@ t.test('token create invalid cidr', async t => {
473473 message : 'CIDR whitelist contains invalid CIDR entry: apple/cider' ,
474474 } )
475475} )
476+
477+ t . test ( 'token create with comma-separated packages' , async t => {
478+ const { npm, outputs } = await loadMockNpm ( t , {
479+ config : {
480+ ...auth ,
481+ name : 'csv-packages-token' ,
482+ password : 'test-password' ,
483+ packages : '@npmcli/pkg1,@npmcli/pkg2,@npmcli/pkg3' ,
484+ 'packages-and-scopes-permission' : 'read-write' ,
485+ } ,
486+ } )
487+
488+ const registry = new MockRegistry ( {
489+ tap : t ,
490+ registry : npm . config . get ( 'registry' ) ,
491+ authorization : authToken ,
492+ } )
493+
494+ registry . createToken ( {
495+ name : 'csv-packages-token' ,
496+ password : 'test-password' ,
497+ packages : [ '@npmcli/pkg1' , '@npmcli/pkg2' , '@npmcli/pkg3' ] ,
498+ packages_and_scopes_permission : 'read-write' ,
499+ } , {
500+ access : 'publish' ,
501+ } )
502+
503+ await npm . exec ( 'token' , [ 'create' ] )
504+ t . match ( outputs , [ 'Created publish token n3wt0k3n' ] )
505+ } )
506+
507+ t . test ( 'token create with comma-separated scopes' , async t => {
508+ const { npm, outputs } = await loadMockNpm ( t , {
509+ config : {
510+ ...auth ,
511+ name : 'csv-scopes-token' ,
512+ password : 'test-password' ,
513+ scopes : '@npmcli,@scope2,@scope3' ,
514+ 'packages-and-scopes-permission' : 'read-only' ,
515+ } ,
516+ } )
517+
518+ const registry = new MockRegistry ( {
519+ tap : t ,
520+ registry : npm . config . get ( 'registry' ) ,
521+ authorization : authToken ,
522+ } )
523+
524+ registry . createToken ( {
525+ name : 'csv-scopes-token' ,
526+ password : 'test-password' ,
527+ scopes : [ '@npmcli' , '@scope2' , '@scope3' ] ,
528+ packages_and_scopes_permission : 'read-only' ,
529+ } , {
530+ access : 'read-only' ,
531+ } )
532+
533+ await npm . exec ( 'token' , [ 'create' ] )
534+ t . match ( outputs , [ 'Created read only token n3wt0k3n' ] )
535+ } )
536+
537+ t . test ( 'token create with comma-separated orgs' , async t => {
538+ const { npm, outputs } = await loadMockNpm ( t , {
539+ config : {
540+ ...auth ,
541+ name : 'csv-orgs-token' ,
542+ password : 'test-password' ,
543+ orgs : '@npmcli,@org2,@org3' ,
544+ 'orgs-permission' : 'read-write' ,
545+ } ,
546+ } )
547+
548+ const registry = new MockRegistry ( {
549+ tap : t ,
550+ registry : npm . config . get ( 'registry' ) ,
551+ authorization : authToken ,
552+ } )
553+
554+ registry . createToken ( {
555+ name : 'csv-orgs-token' ,
556+ password : 'test-password' ,
557+ orgs : [ '@npmcli' , '@org2' , '@org3' ] ,
558+ orgs_permission : 'read-write' ,
559+ } , {
560+ access : 'publish' ,
561+ } )
562+
563+ await npm . exec ( 'token' , [ 'create' ] )
564+ t . match ( outputs , [ 'Created publish token n3wt0k3n' ] )
565+ } )
566+
567+ t . test ( 'token create with comma-separated cidr' , async t => {
568+ const { npm, outputs } = await loadMockNpm ( t , {
569+ config : {
570+ ...auth ,
571+ name : 'csv-cidr-token' ,
572+ password : 'test-password' ,
573+ cidr : '10.0.0.0/8,192.168.1.0/24,172.16.0.0/12' ,
574+ } ,
575+ } )
576+
577+ const registry = new MockRegistry ( {
578+ tap : t ,
579+ registry : npm . config . get ( 'registry' ) ,
580+ authorization : authToken ,
581+ } )
582+
583+ const expires = new Date ( )
584+ registry . createToken ( {
585+ name : 'csv-cidr-token' ,
586+ password : 'test-password' ,
587+ cidr_whitelist : [ '10.0.0.0/8' , '192.168.1.0/24' , '172.16.0.0/12' ] ,
588+ } , {
589+ cidr_whitelist : [ '10.0.0.0/8' , '192.168.1.0/24' , '172.16.0.0/12' ] ,
590+ expires,
591+ } )
592+
593+ await npm . exec ( 'token' , [ 'create' ] )
594+ t . match ( outputs , [
595+ 'Created read only token n3wt0k3n' ,
596+ 'with IP whitelist: 10.0.0.0/8,192.168.1.0/24,172.16.0.0/12' ,
597+ ] )
598+ } )
0 commit comments