Skip to content

Commit adcef60

Browse files
Merge pull request #47 from bufferoverflow/refactor/access-fail-on-unauthenticated
refactor: access should fail if unauthenticated depending on verdaccio
2 parents 306823d + 8310d05 commit adcef60

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/gitlab.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class VerdaccioGitLab implements IPluginAuth {
6262

6363
if (this.config.legacy_mode) {
6464
this.publishLevel = '$owner';
65-
this.logger.info('[gitlab] legacy mode active pre-gitlab v11.2 active, publish is only allowed to group owners');
65+
this.logger.info('[gitlab] legacy mode pre-gitlab v11.2 active, publish is only allowed to group owners');
6666
} else {
6767
this.publishLevel = '$maintainer';
6868
if (this.config.publish) {
@@ -110,7 +110,7 @@ export default class VerdaccioGitLab implements IPluginAuth {
110110
// - for publish, the logged in user id and all the groups they can reach as configured with access level `$auth.gitlab.publish`
111111
//
112112
// In legacy mode, the groups are:
113-
// - for access, themselves and all groups with access level $owner
113+
// - for access, depending on the package settings in verdaccio
114114
// - for publish, the logged in user id and all the groups they can reach as `$owner`
115115
const gitlabPublishQueryParams = this.config.legacy_mode ? { owned: true } : { min_access_level: publishLevelId };
116116
const pPublishGroups = GitlabAPI.Groups.all(gitlabPublishQueryParams).then(groups => {
@@ -150,12 +150,12 @@ export default class VerdaccioGitLab implements IPluginAuth {
150150
if ((_package.access || []).includes('$authenticated') && user.name !== undefined) {
151151
this.logger.debug(`[gitlab] allow user: ${user.name} access to package: ${_package.name}`);
152152
return cb(null, true);
153-
} else if (!(_package.access || []).includes('$authenticated')) {
153+
} else if ((_package.access || []).includes('$all')) {
154154
this.logger.debug(`[gitlab] allow unauthenticated access to package: ${_package.name}`);
155155
return cb(null, true);
156156
} else {
157-
this.logger.debug(`[gitlab] deny user: ${user.name || ''} access to package: ${_package.name}`);
158-
return cb(null, false);
157+
this.logger.debug(`[gitlab] deny user: ${user.name || '<empty>'} access to package: ${_package.name}`);
158+
return cb(httperror[401]('access denied, user not authenticated in gitlab and unauthenticated package access disabled'));
159159
}
160160
}
161161

test/unit/gitlab.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
108108
verdaccioGitlab.allow_access(user, _package, cb);
109109
});
110110

111+
test('should deny access to package based on unauthenticated', done => {
112+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, options);
113+
const user: RemoteUser = {
114+
real_groups: [],
115+
groups: [],
116+
name: undefined
117+
};
118+
const _package: VerdaccioGitlabPackageAccess = {
119+
name: '@myGroup/myPackage',
120+
access: ['$authenticated'],
121+
gitlab: true
122+
};
123+
124+
const cb: Callback = (err, data) => {
125+
expect(err).toBeTruthy();
126+
expect(data).toBeFalsy();
127+
done();
128+
};
129+
130+
verdaccioGitlab.allow_access(user, _package, cb);
131+
});
132+
111133
test('should allow publish of package based on user group', done => {
112134
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, options);
113135
const user: RemoteUser = {

0 commit comments

Comments
 (0)