@@ -94,8 +94,7 @@ export default class VerdaccioGitLab implements IPluginAuth {
94
94
token : password
95
95
} ) ;
96
96
97
- const pUsers = GitlabAPI . Users . current ( ) ;
98
- return pUsers . then ( response => {
97
+ GitlabAPI . Users . current ( ) . then ( response => {
99
98
if ( user !== response . username ) {
100
99
return cb ( httperror [ 401 ] ( 'wrong gitlab username' ) ) ;
101
100
}
@@ -111,31 +110,25 @@ export default class VerdaccioGitLab implements IPluginAuth {
111
110
//
112
111
// In legacy mode, the groups are:
113
112
// - for access, depending on the package settings in verdaccio
114
- // - for publish, the logged in user id and all the groups they can reach as `$owner`
113
+ // - for publish, the logged in user id and all the groups they can reach as fixed `$auth.gitlab.publish` = `$owner`
115
114
const gitlabPublishQueryParams = this . config . legacy_mode ? { owned : true } : { min_access_level : publishLevelId } ;
116
- const pPublishGroups = GitlabAPI . Groups . all ( gitlabPublishQueryParams ) . then ( groups => {
117
- this . logger . trace ( '[gitlab] querying gitlab user groups with params:' , gitlabPublishQueryParams ) ;
118
- this . _addGroupsToArray ( groups , userGroups . publish ) ;
119
- } ) . catch ( error => {
120
- this . logger . error ( `[gitlab] user: ${ user } error querying publish groups: ${ error } ` ) ;
121
- return cb ( httperror [ 500 ] ( 'error querying gitlab' ) ) ;
122
- } ) ;
115
+ this . logger . trace ( '[gitlab] querying gitlab user groups with params:' , gitlabPublishQueryParams ) ;
123
116
124
- const pGroups = Promise . all ( [ pPublishGroups ] ) ;
125
- return pGroups . then ( ( ) => {
117
+ GitlabAPI . Groups . all ( gitlabPublishQueryParams ) . then ( groups => {
118
+ this . _addGroupsToArray ( groups , userGroups . publish ) ;
126
119
this . _setCachedUserGroups ( user , password , userGroups ) ;
120
+
127
121
this . logger . info ( `[gitlab] user: ${ user } successfully authenticated` ) ;
128
122
this . logger . debug ( `[gitlab] user: ${ user } , with groups:` , userGroups ) ;
123
+
129
124
return cb ( null , userGroups . publish ) ;
130
125
} ) . catch ( error => {
131
- this . logger . error ( `[gitlab] error authenticating : ${ error } ` ) ;
132
- return cb ( httperror [ 500 ] ( 'error authenticating' ) ) ;
126
+ this . logger . error ( `[gitlab] user: ${ user } error querying gitlab publish groups : ${ error } ` ) ;
127
+ return cb ( httperror [ 401 ] ( 'error authenticating user ' ) ) ;
133
128
} ) ;
134
129
} ) . catch ( error => {
135
- this . logger . info ( `[gitlab] user: ${ user } error authenticating: ${ error . message || { } } ` ) ;
136
- if ( error ) {
137
- return cb ( httperror [ 401 ] ( 'personal access token invalid' ) ) ;
138
- }
130
+ this . logger . error ( `[gitlab] user: ${ user } error querying gitlab user data: ${ error . message || { } } ` ) ;
131
+ return cb ( httperror [ 401 ] ( 'error authenticating user' ) ) ;
139
132
} ) ;
140
133
}
141
134
@@ -145,29 +138,31 @@ export default class VerdaccioGitLab implements IPluginAuth {
145
138
}
146
139
147
140
allow_access ( user : RemoteUser , _package : VerdaccioGitlabPackageAccess , cb : Callback ) {
148
- if ( ! _package . gitlab ) return cb ( ) ;
141
+ if ( ! _package . gitlab ) return cb ( null , false ) ;
149
142
150
143
if ( ( _package . access || [ ] ) . includes ( '$authenticated' ) && user . name !== undefined ) {
151
144
this . logger . debug ( `[gitlab] allow user: ${ user . name } access to package: ${ _package . name } ` ) ;
152
- return cb ( null , true ) ;
145
+ return cb ( null , false ) ;
153
146
} else if ( ( _package . access || [ ] ) . includes ( '$all' ) ) {
154
147
this . logger . debug ( `[gitlab] allow unauthenticated access to package: ${ _package . name } ` ) ;
155
- return cb ( null , true ) ;
148
+ return cb ( null , false ) ;
156
149
} else {
157
150
this . logger . debug ( `[gitlab] deny user: ${ user . name || '<empty>' } access to package: ${ _package . name } ` ) ;
158
151
return cb ( httperror [ 401 ] ( 'access denied, user not authenticated in gitlab and unauthenticated package access disabled' ) ) ;
159
152
}
160
153
}
161
154
162
155
allow_publish ( user : RemoteUser , _package : VerdaccioGitlabPackageAccess , cb : Callback ) {
163
- if ( ! _package . gitlab ) return cb ( ) ;
156
+ if ( ! _package . gitlab ) return cb ( null , false ) ;
157
+
164
158
let packageScopePermit = false ;
165
159
let packagePermit = false ;
166
160
// Only allow to publish packages when:
167
161
// - the package has exactly the same name as one of the user groups, or
168
162
// - the package scope is the same as one of the user groups
169
163
for ( let real_group of user . real_groups ) { // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
170
164
this . logger . trace ( `[gitlab] publish: checking group: ${ real_group } for user: ${ user . name || '' } and package: ${ _package . name } ` ) ;
165
+
171
166
if ( real_group === _package . name ) {
172
167
packagePermit = true ;
173
168
break ;
0 commit comments