bchanudet / verdaccio-mysql Goto Github PK
View Code? Open in Web Editor NEWVerdaccio MySQL plugin authentication
License: MIT License
Verdaccio MySQL plugin authentication
License: MIT License
This is two problems, firstly the exception is unhandled which means the server crashes and secondly the example queries provided either fail or cause failure in the associated JS.
The trigger the error, have a an empty db based on the example sql at https://github.com/bchanudet/verdaccio-mysql/blob/master/example/mysql-database.sql
issue an npm command:
npm adduser --registry http://npm.example.com/
The process does not add any user_groups so it seems that the SQL which is run to return them means usergroups is set to NULL.
SELECT u.`username`, GROUP_CONCAT(g.`name`) AS usergroups FROM `users` u LEFT JOIN `user_group` ug ON ug.`username` = u.`username` LEFT JOIN `groups` g ON ug.`group` = g.`name` WHERE u.`username` = ? AND u.`password` = PASSWORD(?)
Do we need to add user_groups before we can add a user?
Verdaccio 5.0.3 logs
http --- 404, user: null(192.168.88.254 via undefined), req: 'POST /-/v1/login', bytes: 20/150
express:router dispatching PUT /-/user/org.couchdb.user:tshaw +8s
express:router query : /-/user/org.couchdb.user:tshaw +0ms
express:router expressInit : /-/user/org.couchdb.user:tshaw +1ms
express:router corsMiddleware : /-/user/org.couchdb.user:tshaw +0ms
express:router <anonymous> : /-/user/org.couchdb.user:tshaw +0ms
http --- undefined requested 'PUT /-/user/org.couchdb.user:tshaw'
express:router errorReportingMiddleware : /-/user/org.couchdb.user:tshaw +0ms
express:router <anonymous> : /-/user/org.couchdb.user:tshaw +0ms
express:router compression : /-/user/org.couchdb.user:tshaw +0ms
express:router router : /-/user/org.couchdb.user:tshaw +1ms
express:router dispatching PUT /-/user/org.couchdb.user:tshaw +0ms
express:router <anonymous> : /-/user/org.couchdb.user:tshaw +0ms
express:router jsonParser : /-/user/org.couchdb.user:tshaw +0ms
express:router <anonymous> : /-/user/org.couchdb.user:tshaw +1ms
express:router encodeScopePackage : /-/user/org.couchdb.user:tshaw +0ms
fatal--- uncaught exception, please report this
TypeError: Cannot read property 'usergroups' of undefined
at Query.<anonymous> (/usr/lib/node_modules/verdaccio-mysql/lib/index.js:56:36)
at Query.<anonymous> (/usr/lib/node_modules/verdaccio-mysql/node_modules/mysql/lib/Connection.js:526:10)
at Query._callback (/usr/lib/node_modules/verdaccio-mysql/node_modules/mysql/lib/Connection.js:488:16)
at Query.Sequence.end (/usr/lib/node_modules/verdaccio-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
at Query._handleFinalResultPacket (/usr/lib/node_modules/verdaccio-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:149:8)
at Query.OkPacket (/usr/lib/node_modules/verdaccio-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:74:10)
at Protocol._parsePacket (/usr/lib/node_modules/verdaccio-mysql/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/usr/lib/node_modules/verdaccio-mysql/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/usr/lib/node_modules/verdaccio-mysql/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/usr/lib/node_modules/verdaccio-mysql/node_modules/mysql/lib/protocol/Protocol.js:38:16)
Verdaccio config
auth:
mysql:
connection:
host: "127.0.0.1"
port: 3306
user: "verdaccio"
password: "password"
database: "verdaccio"
queries:
add_user: "INSERT INTO `users`(`username`,`password`) VALUES (?,PASSWORD(?));"
update_user: "UPDATE `users` SET `password`= PASSWORD(?) WHERE `username`=? AND `password`=PASSWORD(?);"
auth_user: "SELECT u.`username`, GROUP_CONCAT(g.`name`) AS usergroups FROM `users` u LEFT JOIN `user_group` ug ON ug.`username` = u.`username` LEFT JOIN `groups` g ON ug.`group` = g.`name` WHERE u.`username` = ? AND u.`password` = PASSWORD(?)"
I implemented Verdaccio with MYSQL authentication and it is working fine.
I can't find any option to disable the creation of new users as with the htpasswd authentication method which has the option 'max_users:'
Is it possible to configure any parameter to disable user creation with 'npm adduser' command?
$ tsc
src/index.ts:117:17 - error TS2794: Expected 1 arguments, but got 0. Did you forget to include 'void' in your type argument to 'Promise'?
117 resolve();
~~~~~~~~~
../../.nvm/versions/node/v16.0.0/lib/node_modules/typescript/lib/lib.es2015.promise.d.ts:33:34
33 new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
~~~~~~~~~~~~~~~~~~~~~~~~~
An argument for 'value' was not provided.
Found 1 error.
fix - index.ts line 117 - added true parameter to resolve()
private async test() : Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
const connection = mysql.createConnection(this.config);
connection.query('SELECT 1', (err, res) => {
if(err){
this.logger.error('MySQL - Test connection did not work');
this.logger.error('MySQL - Error: '+ err.message);
reject();
}
connection.destroy();
resolve(true);
return;
})
});
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.