@@ -851,3 +851,71 @@ t.test('setting username/password/email individually', async t => {
851
851
auth : Buffer . from ( 'admin:admin' ) . toString ( 'base64' ) ,
852
852
} )
853
853
} )
854
+
855
+ t . test ( 'nerfdart auths set at the top level into the registry' , async t => {
856
+ const registry = 'https://registry.npmjs.org/'
857
+ const _auth = Buffer . from ( 'admin:admin' ) . toString ( 'base64' )
858
+ const username = 'admin'
859
+ const _password = Buffer . from ( 'admin' ) . toString ( 'base64' )
860
+
861
+ const _authToken = 'deadbeefblahblah'
862
+
863
+ // TODO(isaacs): We should NOT be requiring that email be nerfdarted.
864
+ // It's not particularly secret, and is only included in the "credentials"
865
+ // concept as an accident of history, because the old couchdb reg used it.
866
+ // It should be treated just like any other plain old config field.
867
+
868
+ // name: [ini, expect]
869
+ const cases = {
870
+ // TODO: should not require email
871
+ // '_auth only, no email': [ `_auth=${_auth}`, {
872
+ // '//registry.npmjs.org/:username': username,
873
+ // '//registry.npmjs.org/:_password': _password,
874
+ // }],
875
+ '_auth with email' : [ `_auth=${ _auth } \nemail=${ email } ` , {
876
+ '//registry.npmjs.org/:username' : username ,
877
+ '//registry.npmjs.org/:_password' : _password ,
878
+ // TODO: change to just 'email': email
879
+ '//registry.npmjs.org/:email' : email ,
880
+ } ] ,
881
+ '_authToken alone' : [ `_authToken=${ _authToken } ` , {
882
+ '//registry.npmjs.org/:_authToken' : _authToken ,
883
+ } ] ,
884
+ '_authToken and email' : [ `_authToken=${ _authToken } \nemail=${ email } ` , {
885
+ '//registry.npmjs.org/:_authToken' : _authToken ,
886
+ // TODO: should include (un-nerf-darted) email
887
+ // email,
888
+ } ] ,
889
+ // TODO: should not require email
890
+ // 'username and _password': [ `username=${username}\n_password=${_password}`, {
891
+ // '//registry.npmjs.org/:username': username,
892
+ // '//registry.npmjs.org/:_password': _password,
893
+ // }],
894
+ 'username, password, email' : [ `username=${ username } \n_password=${ _password } \nemail=${ email } ` , {
895
+ '//registry.npmjs.org/:username' : username ,
896
+ '//registry.npmjs.org/:_password' : _password ,
897
+ '//registry.npmjs.org/:email' :
'[email protected] ' ,
898
+ } ] ,
899
+ // handled invalid cases
900
+ 'username, no _password' : [ `username=${ username } ` , { } ] ,
901
+ '_password, no username' : [ `_password=${ _password } ` , { } ] ,
902
+ }
903
+
904
+ for ( const [ name , [ ini , expect ] ] of Object . entries ( cases ) ) {
905
+ //console.log({name, ini, expect})
906
+ t . test ( name , async t => {
907
+ const path = t . testdir ( { '.npmrc' : ini } )
908
+ const opts = {
909
+ shorthands : { } ,
910
+ argv : [ 'node' , __filename , `--userconfig=${ path } /.npmrc` , `--globalconfig=${ path } /npmrc` ] ,
911
+ definitions : {
912
+ registry : { default : registry } ,
913
+ } ,
914
+ npmPath : process . cwd ( ) ,
915
+ }
916
+ const c = new Config ( opts )
917
+ await c . load ( )
918
+ t . same ( c . list [ 3 ] , expect )
919
+ } )
920
+ }
921
+ } )
0 commit comments