0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

fix: groups are not array were not handled

any group that is returned from a authenticate() and is not an array will throw an error.
This commit is contained in:
Juan Picado @jotadeveloper 2018-06-05 22:46:02 +02:00
parent 73324a2971
commit a62688f844
No known key found for this signature in database
GPG key ID: 18AC54485952D158

View file

@ -1,5 +1,6 @@
// @flow
import _ from 'lodash';
import {loadPlugin} from '../lib/plugin-loader';
import {ErrorCode} from './utils';
import {aesDecrypt, aesEncrypt, signPayload, verifyPayload} from './crypto-utils';
@ -74,8 +75,8 @@ class Auth {
}
authenticate(user: string, password: string, cb: Callback) {
const plugins = this.plugins.slice(0)
;(function next() {
const plugins = this.plugins.slice(0);
(function next() {
const plugin = plugins.shift();
if (typeof(plugin.authenticate) !== 'function') {
@ -99,6 +100,11 @@ class Auth {
if (typeof groups === 'string') {
throw new TypeError('invalid type for function');
}
const isGroupValid: boolean = _.isArray(groups);
if (!isGroupValid) {
throw new TypeError('user groups is different than an array');
}
return cb(err, authenticatedUser(user, groups));
}
next();
@ -350,14 +356,16 @@ function buildAnonymousUser() {
/**
* Authenticate an user.
* @return {Object} { name: xx, groups: [], real_groups: [] }
* @return {Object} { name: xx, pluginGroups: [], real_groups: [] }
*/
function authenticatedUser(name: string, groups: Array<any>) {
let _groups = (groups || []).concat(['$all', '$authenticated', '@all', '@authenticated', 'all']);
function authenticatedUser(name: string, pluginGroups: Array<any>) {
const isGroupValid: boolean = _.isArray(pluginGroups);
const groups = (isGroupValid ? pluginGroups : []).concat(['$all', '$authenticated', '@all', '@authenticated', 'all']);
return {
name: name,
groups: _groups,
real_groups: groups,
name,
groups,
real_groups: pluginGroups,
};
}