@@ -18,12 +18,15 @@ describe('checkUserPushPermission', () => {
18
18
getUsersStub = sinon . stub ( ) ;
19
19
isUserPushAllowedStub = sinon . stub ( ) ;
20
20
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
+ ) ;
27
30
28
31
exec = checkUserPushPermission . exec ;
29
32
} ) ;
@@ -39,40 +42,43 @@ describe('checkUserPushPermission', () => {
39
42
40
43
beforeEach ( ( ) => {
41
44
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' ) ;
49
46
action . user = 'git-user' ;
47
+ action . userEmail = '[email protected] ' ;
50
48
stepSpy = sinon . spy ( Step . prototype , 'log' ) ;
51
49
} ) ;
52
50
53
51
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
+ ] ) ;
55
55
isUserPushAllowedStub . resolves ( true ) ;
56
56
57
57
const result = await exec ( req , action ) ;
58
58
59
59
expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
60
60
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
+ ) ;
63
67
} ) ;
64
68
65
69
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
+ ] ) ;
67
73
isUserPushAllowedStub . resolves ( false ) ;
68
74
69
75
const result = await exec ( req , action ) ;
70
76
71
77
expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
72
78
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
+ ) ;
76
82
} ) ;
77
83
78
84
it ( 'should reject push when no user found for git account' , async ( ) => {
@@ -82,21 +88,22 @@ describe('checkUserPushPermission', () => {
82
88
83
89
expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
84
90
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' ) ;
87
92
} ) ;
88
93
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 ( ) => {
90
95
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' } ,
93
98
] ) ;
94
99
95
100
const result = await exec ( req , action ) ;
96
101
97
102
expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
98
103
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
+ ) ;
100
107
} ) ;
101
108
} ) ;
102
109
} ) ;
0 commit comments