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