@@ -483,6 +483,114 @@ describe('test git-proxy-cli', function () {
483483 } ) ;
484484 } ) ;
485485
486+ // *** create user ***
487+
488+ describe ( 'test git-proxy-cli :: create-user' , function ( ) {
489+ it ( 'attempt to create user should fail when server is down' , async function ( ) {
490+ try {
491+ // start server -> login -> stop server
492+ await helper . startServer ( service ) ;
493+ await helper . runCli ( `npx -- @finos/git-proxy-cli login --username admin --password admin` ) ;
494+ } finally {
495+ await helper . closeServer ( service . httpServer ) ;
496+ }
497+
498+ const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email new@email.com --gitAccount newgit` ;
499+ const expectedExitCode = 2 ;
500+ const expectedMessages = null ;
501+ const expectedErrorMessages = [ 'Error: Create User:' ] ;
502+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
503+ } ) ;
504+
505+ it ( 'attempt to create user should fail when not authenticated' , async function ( ) {
506+ await helper . removeCookiesFile ( ) ;
507+
508+ const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email new@email.com --gitAccount newgit` ;
509+ const expectedExitCode = 1 ;
510+ const expectedMessages = null ;
511+ const expectedErrorMessages = [ 'Error: Create User: Authentication required' ] ;
512+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
513+ } ) ;
514+
515+ it ( 'attempt to create user should fail when not admin' , async function ( ) {
516+ try {
517+ await helper . startServer ( service ) ;
518+ await helper . runCli (
519+ `npx -- @finos/git-proxy-cli login --username testuser --password testpassword` ,
520+ ) ;
521+
522+ const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email new@email.com --gitAccount newgit` ;
523+ const expectedExitCode = 3 ;
524+ const expectedMessages = null ;
525+ const expectedErrorMessages = [ 'Error: Create User: Authentication required' ] ;
526+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
527+ } finally {
528+ await helper . closeServer ( service . httpServer ) ;
529+ }
530+ } ) ;
531+
532+ it ( 'attempt to create user should fail with missing required fields' , async function ( ) {
533+ try {
534+ await helper . startServer ( service ) ;
535+ await helper . runCli ( `npx -- @finos/git-proxy-cli login --username admin --password admin` ) ;
536+
537+ const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --email new@email.com --gitAccount newgit` ;
538+ const expectedExitCode = 4 ;
539+ const expectedMessages = null ;
540+ const expectedErrorMessages = [ 'Error: Create User: Missing required fields' ] ;
541+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
542+ } finally {
543+ await helper . closeServer ( service . httpServer ) ;
544+ }
545+ } ) ;
546+
547+ it ( 'should successfully create a new user' , async function ( ) {
548+ try {
549+ await helper . startServer ( service ) ;
550+ await helper . runCli ( `npx -- @finos/git-proxy-cli login --username admin --password admin` ) ;
551+
552+ const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email new@email.com --gitAccount newgit` ;
553+ const expectedExitCode = 0 ;
554+ const expectedMessages = [ "User 'newuser' created successfully" ] ;
555+ const expectedErrorMessages = null ;
556+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
557+
558+ // Verify we can login with the new user
559+ await helper . runCli (
560+ `npx -- @finos/git-proxy-cli login --username newuser --password newpass` ,
561+ 0 ,
562+ [ `Login "newuser" <new@email.com>: OK` ] ,
563+ null ,
564+ ) ;
565+ } finally {
566+ await helper . closeServer ( service . httpServer ) ;
567+ }
568+ } ) ;
569+
570+ it ( 'should successfully create a new admin user' , async function ( ) {
571+ try {
572+ await helper . startServer ( service ) ;
573+ await helper . runCli ( `npx -- @finos/git-proxy-cli login --username admin --password admin` ) ;
574+
575+ const cli = `npx -- @finos/git-proxy-cli create-user --username newadmin --password newpass --email newadmin@email.com --gitAccount newgit --admin` ;
576+ const expectedExitCode = 0 ;
577+ const expectedMessages = [ "User 'newadmin' created successfully" ] ;
578+ const expectedErrorMessages = null ;
579+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
580+
581+ // Verify we can login with the new admin user
582+ await helper . runCli (
583+ `npx -- @finos/git-proxy-cli login --username newadmin --password newpass` ,
584+ 0 ,
585+ [ `Login "newadmin" <newadmin@email.com> (admin): OK` ] ,
586+ null ,
587+ ) ;
588+ } finally {
589+ await helper . closeServer ( service . httpServer ) ;
590+ }
591+ } ) ;
592+ } ) ;
593+
486594 // *** tests require push in db ***
487595
488596 describe ( 'test git-proxy-cli :: git push administration' , function ( ) {
0 commit comments