@@ -4,74 +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
11
13
12
14
- const TEST_OPTIONS = {
15
- // $FlowFixMe
16
- config : { } ,
17
- logger : logger
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
-
27
13
28
14
describe ( 'Gitlab Auth Plugin Unit Tests' , ( ) => {
29
15
test ( 'should create a plugin instance' , ( ) => {
30
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
16
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
31
17
32
18
expect ( verdaccioGitlab ) . toBeDefined ( ) ;
33
19
} ) ;
34
20
35
21
test ( 'should authenticate a user' , done => {
36
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
22
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
37
23
38
24
const cb : Callback = ( err , data ) => {
39
25
expect ( err ) . toBeFalsy ( ) ;
40
26
expect ( data . sort ( ) ) . toEqual ( [ 'myGroup' , 'myUser' ] . sort ( ) ) ;
41
27
done ( ) ;
42
28
} ;
43
29
44
- verdaccioGitlab . authenticate ( TEST_USER , TEST_PASS , cb ) ;
30
+ verdaccioGitlab . authenticate ( config . user , config . pass , cb ) ;
45
31
} ) ;
46
32
47
33
test ( 'should fail authentication with wrong pass' , done => {
48
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
49
- const wrongPass : string = TEST_PASS + '_wrong' ;
34
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
35
+ const wrongPass : string = config . pass + '_wrong' ;
50
36
51
37
const cb : Callback = ( err , data ) => {
52
38
expect ( err ) . toBeTruthy ( ) ;
53
39
expect ( data ) . toBeFalsy ( ) ;
54
40
done ( ) ;
55
41
} ;
56
42
57
- verdaccioGitlab . authenticate ( TEST_USER , wrongPass , cb ) ;
43
+ verdaccioGitlab . authenticate ( config . user , wrongPass , cb ) ;
58
44
} ) ;
59
45
60
46
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' ;
47
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
48
+ const wrongUser : string = config . user + '_wrong' ;
63
49
64
50
const cb : Callback = ( err , data ) => {
65
51
expect ( err ) . toBeTruthy ( ) ;
66
52
expect ( data ) . toBeFalsy ( ) ;
67
53
done ( ) ;
68
54
} ;
69
55
70
- verdaccioGitlab . authenticate ( wrongUser , TEST_PASS , cb ) ;
56
+ verdaccioGitlab . authenticate ( wrongUser , config . pass , cb ) ;
71
57
} ) ;
72
58
73
59
test ( 'should allow access to package based on user group' , done => {
74
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
60
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
75
61
const _package : VerdaccioGitlabPackageAccess = {
76
62
name : '@myGroup/myPackage' ,
77
63
access : [ '$authenticated' ] ,
@@ -84,13 +70,13 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
84
70
done ( ) ;
85
71
} ;
86
72
87
- verdaccioGitlab . allow_access ( TEST_REMOTE_USER , _package , cb ) ;
73
+ verdaccioGitlab . allow_access ( config . remoteUser , _package , cb ) ;
88
74
} ) ;
89
75
90
76
test ( 'should allow access to package based on user name' , done => {
91
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
77
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
92
78
const _package : VerdaccioGitlabPackageAccess = {
93
- name : TEST_USER ,
79
+ name : config . user ,
94
80
access : [ '$authenticated' ] ,
95
81
gitlab : true
96
82
} ;
@@ -101,11 +87,11 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
101
87
done ( ) ;
102
88
} ;
103
89
104
- verdaccioGitlab . allow_access ( TEST_REMOTE_USER , _package , cb ) ;
90
+ verdaccioGitlab . allow_access ( config . remoteUser , _package , cb ) ;
105
91
} ) ;
106
92
107
93
test ( 'should deny access to package based on unauthenticated' , done => {
108
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
94
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
109
95
const unauthenticatedUser : RemoteUser = {
110
96
real_groups : [ ] ,
111
97
groups : [ ] ,
@@ -127,7 +113,7 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
127
113
} ) ;
128
114
129
115
test ( 'should allow publish of package based on user group' , done => {
130
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
116
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
131
117
const _package : VerdaccioGitlabPackageAccess = {
132
118
name : '@myGroup/myPackage' ,
133
119
gitlab : true
@@ -139,13 +125,13 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
139
125
done ( ) ;
140
126
} ;
141
127
142
- verdaccioGitlab . allow_publish ( TEST_REMOTE_USER , _package , cb ) ;
128
+ verdaccioGitlab . allow_publish ( config . remoteUser , _package , cb ) ;
143
129
} ) ;
144
130
145
131
test ( 'should allow publish of package based on user name' , done => {
146
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
132
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
147
133
const _package : VerdaccioGitlabPackageAccess = {
148
- name : TEST_USER ,
134
+ name : config . user ,
149
135
gitlab : true
150
136
} ;
151
137
@@ -155,18 +141,18 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
155
141
done ( ) ;
156
142
} ;
157
143
158
- verdaccioGitlab . allow_publish ( TEST_REMOTE_USER , _package , cb ) ;
144
+ verdaccioGitlab . allow_publish ( config . remoteUser , _package , cb ) ;
159
145
} ) ;
160
146
161
147
test ( 'should deny publish of package based on unauthenticated' , done => {
162
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
148
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
163
149
const unauthenticatedUser : RemoteUser = {
164
150
real_groups : [ ] ,
165
151
groups : [ ] ,
166
152
name : undefined
167
153
} ;
168
154
const _package : VerdaccioGitlabPackageAccess = {
169
- name : TEST_USER ,
155
+ name : config . user ,
170
156
gitlab : true
171
157
} ;
172
158
@@ -180,7 +166,7 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
180
166
} ) ;
181
167
182
168
test ( 'should deny publish of package based on group' , done => {
183
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
169
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
184
170
const _package : VerdaccioGitlabPackageAccess = {
185
171
name : '@anotherGroup/myPackage' ,
186
172
gitlab : true
@@ -192,11 +178,11 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
192
178
done ( ) ;
193
179
} ;
194
180
195
- verdaccioGitlab . allow_publish ( TEST_REMOTE_USER , _package , cb ) ;
181
+ verdaccioGitlab . allow_publish ( config . remoteUser , _package , cb ) ;
196
182
} ) ;
197
183
198
184
test ( 'should deny publish of package based on user' , done => {
199
- const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( defaultConfig , TEST_OPTIONS ) ;
185
+ const verdaccioGitlab : VerdaccioGitlab = new VerdaccioGitlab ( config . verdaccioGitlabConfig , config . options ) ;
200
186
const _package : VerdaccioGitlabPackageAccess = {
201
187
name : 'anotherUser' ,
202
188
gitlab : true
@@ -208,6 +194,6 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
208
194
done ( ) ;
209
195
} ;
210
196
211
- verdaccioGitlab . allow_publish ( TEST_REMOTE_USER , _package , cb ) ;
197
+ verdaccioGitlab . allow_publish ( config . remoteUser , _package , cb ) ;
212
198
} ) ;
213
199
} ) ;
0 commit comments