@@ -620,20 +620,121 @@ describe('test git-proxy-cli', function () {
620
620
it ( 'attempt to reject should fail when git push ID not found' , async function ( ) {
621
621
try {
622
622
await helper . startServer ( service ) ;
623
- await helper . runCli (
624
- `npx -- @finos/git-proxy-cli login --username admin --password admin` ,
625
- ) ;
623
+ await helper . runCli ( `npx -- @finos/git-proxy-cli login --username admin --password admin` ) ;
626
624
627
625
const id = GHOST_PUSH_ID ;
628
626
const cli = `npx -- @finos/git-proxy-cli reject --id ${ id } ` ;
629
627
const expectedExitCode = 4 ;
630
628
const expectedMessages = null ;
631
629
const expectedErrorMessages = [ `Error: Reject: ID: '${ id } ': Not Found` ] ;
630
+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
631
+ } finally {
632
+ await helper . closeServer ( service . httpServer ) ;
633
+ }
634
+ } ) ;
635
+ } ) ;
636
+
637
+ // *** create user ***
638
+
639
+ describe ( 'test git-proxy-cli :: create-user' , function ( ) {
640
+ it ( 'attempt to create user should fail when server is down' , async function ( ) {
641
+ try {
642
+ // start server -> login -> stop server
643
+ await helper . startServer ( service ) ;
644
+ await helper . runCli ( `npx -- @finos/git-proxy-cli login --username admin --password admin` ) ;
645
+ } finally {
646
+ await helper . closeServer ( service . httpServer ) ;
647
+ }
648
+
649
+ const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email [email protected] --gitAccount newgit` ;
650
+ const expectedExitCode = 2 ;
651
+ const expectedMessages = null ;
652
+ const expectedErrorMessages = [ 'Error: Create User:' ] ;
653
+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
654
+ } ) ;
655
+
656
+ it ( 'attempt to create user should fail when not authenticated' , async function ( ) {
657
+ await helper . removeCookiesFile ( ) ;
658
+
659
+ const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email [email protected] --gitAccount newgit` ;
660
+ const expectedExitCode = 1 ;
661
+ const expectedMessages = null ;
662
+ const expectedErrorMessages = [ 'Error: Create User: Authentication required' ] ;
663
+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
664
+ } ) ;
665
+
666
+ it ( 'attempt to create user should fail when not admin' , async function ( ) {
667
+ try {
668
+ await helper . startServer ( service ) ;
632
669
await helper . runCli (
633
- cli ,
634
- expectedExitCode ,
635
- expectedMessages ,
636
- expectedErrorMessages ,
670
+ `npx -- @finos/git-proxy-cli login --username testuser --password testpassword` ,
671
+ ) ;
672
+
673
+ const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email [email protected] --gitAccount newgit` ;
674
+ const expectedExitCode = 3 ;
675
+ const expectedMessages = null ;
676
+ const expectedErrorMessages = [ 'Error: Create User: Authentication required' ] ;
677
+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
678
+ } finally {
679
+ await helper . closeServer ( service . httpServer ) ;
680
+ }
681
+ } ) ;
682
+
683
+ it ( 'attempt to create user should fail with missing required fields' , async function ( ) {
684
+ try {
685
+ await helper . startServer ( service ) ;
686
+ await helper . runCli ( `npx -- @finos/git-proxy-cli login --username admin --password admin` ) ;
687
+
688
+ const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --email [email protected] --gitAccount newgit` ;
689
+ const expectedExitCode = 4 ;
690
+ const expectedMessages = null ;
691
+ const expectedErrorMessages = [ 'Error: Create User: Missing required fields' ] ;
692
+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
693
+ } finally {
694
+ await helper . closeServer ( service . httpServer ) ;
695
+ }
696
+ } ) ;
697
+
698
+ it ( 'should successfully create a new user' , async function ( ) {
699
+ try {
700
+ await helper . startServer ( service ) ;
701
+ await helper . runCli ( `npx -- @finos/git-proxy-cli login --username admin --password admin` ) ;
702
+
703
+ const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email [email protected] --gitAccount newgit` ;
704
+ const expectedExitCode = 0 ;
705
+ const expectedMessages = [ "User 'newuser' created successfully" ] ;
706
+ const expectedErrorMessages = null ;
707
+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
708
+
709
+ // Verify we can login with the new user
710
+ await helper . runCli (
711
+ `npx -- @finos/git-proxy-cli login --username newuser --password newpass` ,
712
+ 0 ,
713
+ [ `Login "newuser" <[email protected] >: OK` ] ,
714
+ null ,
715
+ ) ;
716
+ } finally {
717
+ await helper . closeServer ( service . httpServer ) ;
718
+ }
719
+ } ) ;
720
+
721
+ it ( 'should successfully create a new admin user' , async function ( ) {
722
+ try {
723
+ await helper . startServer ( service ) ;
724
+ await helper . runCli ( `npx -- @finos/git-proxy-cli login --username admin --password admin` ) ;
725
+
726
+ const cli = `npx -- @finos/git-proxy-cli create-user --username newadmin --password newpass --email [email protected] --gitAccount newgit --admin` ;
727
+ const expectedExitCode = 0 ;
728
+ const expectedMessages = [ "User 'newadmin' created successfully" ] ;
729
+ const expectedErrorMessages = null ;
730
+ await helper . runCli ( cli , expectedExitCode , expectedMessages , expectedErrorMessages ) ;
731
+
732
+ // Verify we can login with the new admin user
733
+ await helper . runCli (
734
+ `npx -- @finos/git-proxy-cli login --username newadmin --password newpass` ,
735
+ 0 ,
736
+ [ `Login "newadmin" <[email protected] > (admin): OK` ] ,
737
+ null ,
637
738
) ;
638
739
} finally {
639
740
await helper . closeServer ( service . httpServer ) ;
0 commit comments