@@ -9,68 +9,69 @@ import logger from './partials/logger.js';
9
9
10
10
// Do not remove, this mocks the gitlab library
11
11
import Gitlab from 'gitlab' ; // eslint-disable-line no-unused-vars
12
- const options = {
12
+
13
+
14
+ const TEST_OPTIONS = {
13
15
// $FlowFixMe
14
16
config : { } ,
15
17
logger : logger
16
18
} ;
19
+ const TEST_USER : string = 'myUser' ;
20
+ const TEST_PASS : string = 'myPass' ;
21
+ const TEST_REMOTE_USER : RemoteUser = {
22
+ real_groups : [ 'myGroup' , TEST_USER ] ,
23
+ groups : [ 'myGroup' , TEST_USER ] ,
24
+ name : TEST_USER
25
+ } ;
26
+
17
27
18
28
describe ( 'Gitlab Auth Plugin Unit Tests' , ( ) => {
19
29
test ( 'should create a plugin instance' , ( ) => {
20
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
30
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
21
31
22
32
expect ( verdaccioGitlab ) . toBeDefined ( ) ;
23
33
} ) ;
24
34
25
35
test ( 'should authenticate a user' , done => {
26
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
27
- const user : string = 'myUser' ;
28
- const pass : string = 'myPass' ;
36
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
29
37
30
38
const cb : Callback = ( err , data ) => {
31
39
expect ( err ) . toBeFalsy ( ) ;
32
40
expect ( data . sort ( ) ) . toEqual ( [ 'myGroup' , 'myUser' ] . sort ( ) ) ;
33
41
done ( ) ;
34
42
} ;
35
43
36
- verdaccioGitlab . authenticate ( user , pass , cb ) ;
44
+ verdaccioGitlab . authenticate ( TEST_USER , TEST_PASS , cb ) ;
37
45
} ) ;
38
46
39
47
test ( 'should fail authentication with wrong pass' , done => {
40
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
41
- const user : string = 'myUser' ;
42
- const pass : string = 'anotherPass' ;
48
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
49
+ const wrongPass : string = TEST_PASS + '_wrong' ;
43
50
44
51
const cb : Callback = ( err , data ) => {
45
52
expect ( err ) . toBeTruthy ( ) ;
46
53
expect ( data ) . toBeFalsy ( ) ;
47
54
done ( ) ;
48
55
} ;
49
56
50
- verdaccioGitlab . authenticate ( user , pass , cb ) ;
57
+ verdaccioGitlab . authenticate ( TEST_USER , wrongPass , cb ) ;
51
58
} ) ;
52
59
53
- test ( 'should fail authentication with not existing user' , done => {
54
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
55
- const user : string = 'anotherUser' ;
56
- const pass : string = 'myPass' ;
60
+ test ( 'should fail authentication with non-existing user' , done => {
61
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
62
+ const wrongUser : string = TEST_USER + '_wrong' ;
57
63
58
64
const cb : Callback = ( err , data ) => {
59
65
expect ( err ) . toBeTruthy ( ) ;
60
66
expect ( data ) . toBeFalsy ( ) ;
61
67
done ( ) ;
62
68
} ;
63
69
64
- verdaccioGitlab . authenticate ( user , pass , cb ) ;
70
+ verdaccioGitlab . authenticate ( wrongUser , TEST_PASS , cb ) ;
65
71
} ) ;
66
72
67
73
test ( 'should allow access to package based on user group' , done => {
68
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
69
- const user : RemoteUser = {
70
- real_groups : [ 'myGroup' , 'myUser' ] ,
71
- groups : [ 'myGroup' , 'myUser' ] ,
72
- name : 'myUser'
73
- } ;
74
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
74
75
const _package : VerdaccioGitlabPackageAccess = {
75
76
name : '@myGroup/myPackage' ,
76
77
access : [ '$authenticated' ] ,
@@ -83,18 +84,13 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
83
84
done ( ) ;
84
85
} ;
85
86
86
- verdaccioGitlab . allow_access ( user , _package , cb ) ;
87
+ verdaccioGitlab . allow_access ( TEST_REMOTE_USER , _package , cb ) ;
87
88
} ) ;
88
89
89
90
test ( 'should allow access to package based on user name' , done => {
90
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
91
- const user : RemoteUser = {
92
- real_groups : [ 'myGroup' , 'myUser' ] ,
93
- groups : [ 'myGroup' , 'myUser' ] ,
94
- name : 'myUser'
95
- } ;
91
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
96
92
const _package : VerdaccioGitlabPackageAccess = {
97
- name : 'myUser' ,
93
+ name : TEST_USER ,
98
94
access : [ '$authenticated' ] ,
99
95
gitlab : true
100
96
} ;
@@ -105,12 +101,12 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
105
101
done ( ) ;
106
102
} ;
107
103
108
- verdaccioGitlab . allow_access ( user , _package , cb ) ;
104
+ verdaccioGitlab . allow_access ( TEST_REMOTE_USER , _package , cb ) ;
109
105
} ) ;
110
106
111
107
test ( 'should deny access to package based on unauthenticated' , done => {
112
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
113
- const user : RemoteUser = {
108
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
109
+ const unauthenticatedUser : RemoteUser = {
114
110
real_groups : [ ] ,
115
111
groups : [ ] ,
116
112
name : undefined
@@ -127,16 +123,11 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
127
123
done ( ) ;
128
124
} ;
129
125
130
- verdaccioGitlab . allow_access ( user , _package , cb ) ;
126
+ verdaccioGitlab . allow_access ( unauthenticatedUser , _package , cb ) ;
131
127
} ) ;
132
128
133
129
test ( 'should allow publish of package based on user group' , done => {
134
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
135
- const user : RemoteUser = {
136
- real_groups : [ 'myGroup' , 'myUser' ] ,
137
- groups : [ 'myGroup' , 'myUser' ] ,
138
- name : 'myUser'
139
- } ;
130
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
140
131
const _package : VerdaccioGitlabPackageAccess = {
141
132
name : '@myGroup/myPackage' ,
142
133
gitlab : true
@@ -148,18 +139,13 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
148
139
done ( ) ;
149
140
} ;
150
141
151
- verdaccioGitlab . allow_publish ( user , _package , cb ) ;
142
+ verdaccioGitlab . allow_publish ( TEST_REMOTE_USER , _package , cb ) ;
152
143
} ) ;
153
144
154
145
test ( 'should allow publish of package based on user name' , done => {
155
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
156
- const user : RemoteUser = {
157
- real_groups : [ 'myGroup' , 'myUser' ] ,
158
- groups : [ 'myGroup' , 'myUser' ] ,
159
- name : 'myUser'
160
- } ;
146
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
161
147
const _package : VerdaccioGitlabPackageAccess = {
162
- name : 'myUser' ,
148
+ name : TEST_USER ,
163
149
gitlab : true
164
150
} ;
165
151
@@ -169,18 +155,18 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
169
155
done ( ) ;
170
156
} ;
171
157
172
- verdaccioGitlab . allow_publish ( user , _package , cb ) ;
158
+ verdaccioGitlab . allow_publish ( TEST_REMOTE_USER , _package , cb ) ;
173
159
} ) ;
174
160
175
161
test ( 'should deny publish of package based on unauthenticated' , done => {
176
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
177
- const user : RemoteUser = {
162
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
163
+ const unauthenticatedUser : RemoteUser = {
178
164
real_groups : [ ] ,
179
165
groups : [ ] ,
180
166
name : undefined
181
167
} ;
182
168
const _package : VerdaccioGitlabPackageAccess = {
183
- name : 'myUser' ,
169
+ name : TEST_USER ,
184
170
gitlab : true
185
171
} ;
186
172
@@ -190,16 +176,11 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
190
176
done ( ) ;
191
177
} ;
192
178
193
- verdaccioGitlab . allow_publish ( user , _package , cb ) ;
179
+ verdaccioGitlab . allow_publish ( unauthenticatedUser , _package , cb ) ;
194
180
} ) ;
195
181
196
182
test ( 'should deny publish of package based on group' , done => {
197
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
198
- const user : RemoteUser = {
199
- real_groups : [ 'myGroup' , 'myUser' ] ,
200
- groups : [ 'myGroup' , 'myUser' ] ,
201
- name : 'myUser'
202
- } ;
183
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
203
184
const _package : VerdaccioGitlabPackageAccess = {
204
185
name : '@anotherGroup/myPackage' ,
205
186
gitlab : true
@@ -211,16 +192,11 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
211
192
done ( ) ;
212
193
} ;
213
194
214
- verdaccioGitlab . allow_publish ( user , _package , cb ) ;
195
+ verdaccioGitlab . allow_publish ( TEST_REMOTE_USER , _package , cb ) ;
215
196
} ) ;
216
197
217
198
test ( 'should deny publish of package based on user' , done => {
218
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , options ) ;
219
- const user : RemoteUser = {
220
- real_groups : [ 'myGroup' , 'myUser' ] ,
221
- groups : [ 'myGroup' , 'myUser' ] ,
222
- name : 'myUser'
223
- } ;
199
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
224
200
const _package : VerdaccioGitlabPackageAccess = {
225
201
name : 'anotherUser' ,
226
202
gitlab : true
@@ -232,6 +208,6 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
232
208
done ( ) ;
233
209
} ;
234
210
235
- verdaccioGitlab . allow_publish ( user , _package , cb ) ;
211
+ verdaccioGitlab . allow_publish ( TEST_REMOTE_USER , _package , cb ) ;
236
212
} ) ;
237
213
} ) ;
0 commit comments