@@ -47,6 +47,21 @@ const TEST_PUSH = {
4747 attestation : null ,
4848} ;
4949
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+
5065/**
5166 * Clean up response data from the DB by removing an extraneous properties,
5267 * allowing comparison with expect.
@@ -623,9 +638,47 @@ describe('Database clients', async () => {
623638 await db . removeUserCanAuthorise ( repoName , TEST_USER . username ) ;
624639 } ) ;
625640
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+
626677 after ( async function ( ) {
627678 await db . deleteRepo ( TEST_REPO . name ) ;
679+ await db . deleteRepo ( TEST_REPO_DOT_GIT . name ) ;
628680 await db . deleteUser ( TEST_USER . username ) ;
629681 await db . deletePush ( TEST_PUSH . id ) ;
682+ await db . deletePush ( TEST_PUSH_DOT_GIT . id ) ;
630683 } ) ;
631684} ) ;
0 commit comments