@@ -47,6 +47,21 @@ const TEST_PUSH = {
47
47
attestation : null ,
48
48
} ;
49
49
50
+ const TEST_REPO_DOT_GIT = {
51
+ project : 'finos' ,
52
+ name : 'db.git-test-repo' ,
53
+ url : 'https://github.com/finos/db.git-test-repo.git' ,
54
+ } ;
55
+
56
+ // the same as TEST_PUSH but with .git somewhere valid within the name
57
+ // to ensure a global replace isn't done when trimming, just to the end
58
+ const TEST_PUSH_DOT_GIT = {
59
+ ...TEST_PUSH ,
60
+ repoName : 'db.git-test-repo.git' ,
61
+ url : 'https://github.com/finos/db.git-test-repo.git' ,
62
+ repo : 'finos/db.git-test-repo.git' ,
63
+ } ;
64
+
50
65
/**
51
66
* Clean up response data from the DB by removing an extraneous properties,
52
67
* allowing comparison with expect.
@@ -623,9 +638,47 @@ describe('Database clients', async () => {
623
638
await db . removeUserCanAuthorise ( repoName , TEST_USER . username ) ;
624
639
} ) ;
625
640
641
+ it ( 'should be able to check if a user can approve/reject push including .git within the repo name' , async function ( ) {
642
+ let allowed = undefined ;
643
+ const repoName = trimTrailingDotGit ( TEST_PUSH_DOT_GIT . repoName ) ;
644
+
645
+ await db . createRepo ( TEST_REPO_DOT_GIT ) ;
646
+ try {
647
+ // push does not exist yet, should return false
648
+ allowed = await db . canUserApproveRejectPush ( TEST_PUSH_DOT_GIT . id , TEST_USER . username ) ;
649
+ expect ( allowed ) . to . be . false ;
650
+ } catch ( e ) {
651
+ expect . fail ( e ) ;
652
+ }
653
+
654
+ try {
655
+ // create the push - user should already exist and not authorised to push
656
+ await db . writeAudit ( TEST_PUSH_DOT_GIT ) ;
657
+ allowed = await db . canUserApproveRejectPush ( TEST_PUSH_DOT_GIT . id , TEST_USER . username ) ;
658
+ expect ( allowed ) . to . be . false ;
659
+ } catch ( e ) {
660
+ expect . fail ( e ) ;
661
+ }
662
+
663
+ try {
664
+ // authorise user and recheck
665
+ await db . addUserCanAuthorise ( repoName , TEST_USER . username ) ;
666
+ allowed = await db . canUserApproveRejectPush ( TEST_PUSH_DOT_GIT . id , TEST_USER . username ) ;
667
+ expect ( allowed ) . to . be . true ;
668
+ } catch ( e ) {
669
+ expect . fail ( e ) ;
670
+ }
671
+
672
+ // clean up
673
+ await db . deletePush ( TEST_PUSH_DOT_GIT . id ) ;
674
+ await db . removeUserCanAuthorise ( repoName , TEST_USER . username ) ;
675
+ } ) ;
676
+
626
677
after ( async function ( ) {
627
678
await db . deleteRepo ( TEST_REPO . name ) ;
679
+ await db . deleteRepo ( TEST_REPO_DOT_GIT . name ) ;
628
680
await db . deleteUser ( TEST_USER . username ) ;
629
681
await db . deletePush ( TEST_PUSH . id ) ;
682
+ await db . deletePush ( TEST_PUSH_DOT_GIT . id ) ;
630
683
} ) ;
631
684
} ) ;
0 commit comments