@@ -18,12 +18,15 @@ describe('checkUserPushPermission', () => {
1818 getUsersStub = sinon . stub ( ) ;
1919 isUserPushAllowedStub = sinon . stub ( ) ;
2020
21- const checkUserPushPermission = proxyquire ( '../../src/proxy/processors/push-action/checkUserPushPermission' , {
22- '../../../db' : {
23- getUsers : getUsersStub ,
24- isUserPushAllowed : isUserPushAllowedStub
25- }
26- } ) ;
21+ const checkUserPushPermission = proxyquire (
22+ '../../src/proxy/processors/push-action/checkUserPushPermission' ,
23+ {
24+ '../../../db' : {
25+ getUsers : getUsersStub ,
26+ isUserPushAllowed : isUserPushAllowedStub ,
27+ } ,
28+ } ,
29+ ) ;
2730
2831 exec = checkUserPushPermission . exec ;
2932 } ) ;
@@ -39,40 +42,43 @@ describe('checkUserPushPermission', () => {
3942
4043 beforeEach ( ( ) => {
4144 req = { } ;
42- action = new Action (
43- '1234567890' ,
44- 'push' ,
45- 'POST' ,
46- 1234567890 ,
47- 'test/repo.git'
48- ) ;
45+ action = new Action ( '1234567890' , 'push' , 'POST' , 1234567890 , 'test/repo.git' ) ;
4946 action . user = 'git-user' ;
47+ action . userEmail = '[email protected] ' ; 5048 stepSpy = sinon . spy ( Step . prototype , 'log' ) ;
5149 } ) ;
5250
5351 it ( 'should allow push when user has permission' , async ( ) => {
54- getUsersStub . resolves ( [ { username : 'db-user' , gitAccount : 'git-user' } ] ) ;
52+ getUsersStub . resolves ( [
53+ { username :
'db-user' , email :
'[email protected] ' , gitAccount :
'git-user' } , 54+ ] ) ;
5555 isUserPushAllowedStub . resolves ( true ) ;
5656
5757 const result = await exec ( req , action ) ;
5858
5959 expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
6060 expect ( result . steps [ 0 ] . error ) . to . be . false ;
61- expect ( stepSpy . calledWith ( 'User db-user is allowed to push on repo test/repo.git' ) ) . to . be . true ;
62- expect ( logStub . calledWith ( 'User db-user permission on Repo repo : true' ) ) . to . be . true ;
61+ expect ( stepSpy . lastCall . args [ 0 ] ) . to . equal (
62+ 'User db-user <[email protected] > is allowed to push on repo test/repo.git' , 63+ ) ;
64+ expect ( logStub . lastCall . args [ 0 ] ) . to . equal (
65+ 'User db-user <[email protected] > permission on Repo repo : true' , 66+ ) ;
6367 } ) ;
6468
6569 it ( 'should reject push when user has no permission' , async ( ) => {
66- getUsersStub . resolves ( [ { username : 'db-user' , gitAccount : 'git-user' } ] ) ;
70+ getUsersStub . resolves ( [
71+ { username :
'db-user' , email :
'[email protected] ' , gitAccount :
'git-user' } , 72+ ] ) ;
6773 isUserPushAllowedStub . resolves ( false ) ;
6874
6975 const result = await exec ( req , action ) ;
7076
7177 expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
7278 expect ( result . steps [ 0 ] . error ) . to . be . true ;
73- expect ( stepSpy . calledWith ( 'User db-user is not allowed to push on repo test/repo.git, ending' ) ) . to . be . true ;
74- expect ( result . steps [ 0 ] . errorMessage ) . to . include ( 'Rejecting push as user git-user' ) ;
75- expect ( logStub . calledWith ( 'User not allowed to Push' ) ) . to . be . true ;
79+ expect ( result . steps [ 0 ] . errorMessage ) . to . equal (
80+ 'Your push has been blocked ([email protected] is not allowed to push on repo test/repo. git)' , 81+ ) ;
7682 } ) ;
7783
7884 it ( 'should reject push when no user found for git account' , async ( ) => {
@@ -82,21 +88,22 @@ describe('checkUserPushPermission', () => {
8288
8389 expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
8490 expect ( result . steps [ 0 ] . error ) . to . be . true ;
85- expect ( stepSpy . calledWith ( 'User git-user is not allowed to push on repo test/repo.git, ending' ) ) . to . be . true ;
86- expect ( result . steps [ 0 ] . errorMessage ) . to . include ( 'Rejecting push as user git-user' ) ;
91+ expect ( result . steps [ 0 ] . errorMessage ) . to . include ( 'Your push has been blocked' ) ;
8792 } ) ;
8893
89- it ( 'should handle multiple users for git account by rejecting push' , async ( ) => {
94+ it ( 'should handle multiple users for git account by rejecting the push' , async ( ) => {
9095 getUsersStub . resolves ( [
91- { username : 'user1' , gitAccount : 'git-user' } ,
92- { username : 'user2' , gitAccount : 'git-user' }
96+ { username :
'user1' , email : '[email protected] ' , gitAccount :
'git-user' } , 97+ { username :
'user2' , email : '[email protected] ' , gitAccount :
'git-user' } , 9398 ] ) ;
9499
95100 const result = await exec ( req , action ) ;
96101
97102 expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
98103 expect ( result . steps [ 0 ] . error ) . to . be . true ;
99- expect ( logStub . calledWith ( 'Users for this git account: [{"username":"user1","gitAccount":"git-user"},{"username":"user2","gitAccount":"git-user"}]' ) ) . to . be . true ;
104+ expect ( result . steps [ 0 ] . errorMessage ) . to . equal (
105+ 'Your push has been blocked (there are multiple users with email [email protected] )' , 106+ ) ;
100107 } ) ;
101108 } ) ;
102109} ) ;
0 commit comments