@@ -475,3 +475,115 @@ t.test('token create invalid cidr', async t => {
475475 message : 'CIDR whitelist contains invalid CIDR entry: apple/cider' ,
476476 } )
477477} )
478+
479+ t . test ( 'token create stage-only produces stage-only policy and no warning' , async t => {
480+ const { npm, outputs, logs } = await loadMockNpm ( t , {
481+ config : {
482+ ...auth ,
483+ name : 'stage-only-token' ,
484+ password : 'test-password' ,
485+ 'packages-and-scopes-permission' : 'read-write-stage-only' ,
486+ } ,
487+ } )
488+
489+ const registry = new MockRegistry ( {
490+ tap : t ,
491+ registry : npm . config . get ( 'registry' ) ,
492+ authorization : authToken ,
493+ } )
494+
495+ registry . createToken ( {
496+ name : 'stage-only-token' ,
497+ password : 'test-password' ,
498+ packages_and_scopes_permission : 'read-write-stage-only' ,
499+ } )
500+
501+ await npm . exec ( 'token' , [ 'create' ] )
502+ t . match ( outputs , [ 'Created token n3wt0k3n' ] )
503+ t . strictSame ( logs . warn , [ ] , 'no deprecation warning for stage-only tokens' )
504+ } )
505+
506+ t . test ( 'token create read-write warns about direct-publish' , async t => {
507+ const { npm, outputs, logs } = await loadMockNpm ( t , {
508+ config : {
509+ ...auth ,
510+ name : 'rw-token' ,
511+ password : 'test-password' ,
512+ 'packages-and-scopes-permission' : 'read-write' ,
513+ } ,
514+ } )
515+
516+ const registry = new MockRegistry ( {
517+ tap : t ,
518+ registry : npm . config . get ( 'registry' ) ,
519+ authorization : authToken ,
520+ } )
521+
522+ registry . createToken ( {
523+ name : 'rw-token' ,
524+ password : 'test-password' ,
525+ packages_and_scopes_permission : 'read-write' ,
526+ } )
527+
528+ await npm . exec ( 'token' , [ 'create' ] )
529+ t . match ( outputs , [ 'Created token n3wt0k3n' ] )
530+ t . match ( logs . warn , [ / p u b l i s h d i r e c t l y t o t h e r e g i s t r y / ] , 'warns about direct-publish token' )
531+ t . match ( logs . warn , [ / r e a d - w r i t e - s t a g e - o n l y / ] , 'warning points to stage-only tokens' )
532+ t . match ( logs . warn , [ / h t t p s : \/ \/ g h \. i o \/ b y p a s s - 2 f a - t o k e n s - n o - l o n g e r - p u b l i s h / ] , 'warning includes the docs link' )
533+ } )
534+
535+ t . test ( 'token create bypass-2fa alone does not warn' , async t => {
536+ const { npm, outputs, logs } = await loadMockNpm ( t , {
537+ config : {
538+ ...auth ,
539+ name : 'bypass-token' ,
540+ password : 'test-password' ,
541+ 'bypass-2fa' : true ,
542+ } ,
543+ } )
544+
545+ const registry = new MockRegistry ( {
546+ tap : t ,
547+ registry : npm . config . get ( 'registry' ) ,
548+ authorization : authToken ,
549+ } )
550+
551+ registry . createToken ( {
552+ name : 'bypass-token' ,
553+ password : 'test-password' ,
554+ bypass_2fa : true ,
555+ } )
556+
557+ await npm . exec ( 'token' , [ 'create' ] )
558+ t . match ( outputs , [ 'Created token n3wt0k3n' ] )
559+ t . strictSame ( logs . warn , [ ] , 'bypass-2fa alone grants no publish capability, so no warning' )
560+ } )
561+
562+ t . test ( 'token create read-write with bypass-2fa warns about direct-publish' , async t => {
563+ const { npm, outputs, logs } = await loadMockNpm ( t , {
564+ config : {
565+ ...auth ,
566+ name : 'rw-bypass-token' ,
567+ password : 'test-password' ,
568+ 'packages-and-scopes-permission' : 'read-write' ,
569+ 'bypass-2fa' : true ,
570+ } ,
571+ } )
572+
573+ const registry = new MockRegistry ( {
574+ tap : t ,
575+ registry : npm . config . get ( 'registry' ) ,
576+ authorization : authToken ,
577+ } )
578+
579+ registry . createToken ( {
580+ name : 'rw-bypass-token' ,
581+ password : 'test-password' ,
582+ packages_and_scopes_permission : 'read-write' ,
583+ bypass_2fa : true ,
584+ } )
585+
586+ await npm . exec ( 'token' , [ 'create' ] )
587+ t . match ( outputs , [ 'Created token n3wt0k3n' ] )
588+ t . match ( logs . warn , [ / p u b l i s h d i r e c t l y t o t h e r e g i s t r y / ] , 'warns for read-write automation publish token' )
589+ } )
0 commit comments