From 2f4dbe85643ddf383904615f739926bd21730195 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Mon, 16 Jul 2018 19:53:26 +0200 Subject: [PATCH] fix: add RemoteUser type for auth --- package.json | 2 +- src/lib/auth.js | 4 ++-- src/lib/constants.js | 2 +- test/flow/plugins/auth/example.auth.plugin.js | 14 ++++++++++---- .../middleware/example.middleware.plugin.js | 8 +++++++- yarn.lock | Bin 348500 -> 348500 bytes 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 8e3eb2cf7..8ea99371f 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "devDependencies": { "@commitlint/cli": "6.1.3", "@commitlint/config-conventional": "6.1.3", - "@verdaccio/types": "3.3.3", + "@verdaccio/types": "3.4.0", "babel-cli": "6.26.0", "babel-core": "6.26.0", "babel-eslint": "8.2.2", diff --git a/src/lib/auth.js b/src/lib/auth.js index 8a1cce9d3..d15656d2e 100644 --- a/src/lib/auth.js +++ b/src/lib/auth.js @@ -10,7 +10,7 @@ import {getDefaultPlugins} from './auth-utils'; import {getMatchedPackagesSpec} from './config-utils'; -import type {Config, Logger, Callback, IPluginAuth} from '@verdaccio/types'; +import type {Config, Logger, Callback, IPluginAuth, RemoteUser} from '@verdaccio/types'; import type {$Response, NextFunction} from 'express'; import type {$RequestExtend, JWTPayload} from '../../types'; import type {IAuth} from '../../types'; @@ -118,7 +118,7 @@ class Auth implements IAuth { /** * Allow user to access a package. */ - allow_access(packageName: string, user: string, callback: Callback) { + allow_access(packageName: string, user: RemoteUser, callback: Callback) { let plugins = this.plugins.slice(0); // $FlowFixMe let pkg = Object.assign({name: packageName}, getMatchedPackagesSpec(packageName, this.config.packages)); diff --git a/src/lib/constants.js b/src/lib/constants.js index 0b21dbb15..9e9f8edb6 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -67,7 +67,7 @@ export const API_MESSAGE = { }; export const API_ERROR = { - BAD_USERNAME_PASSWORD: 'bad username/password, access denied {APP}', + BAD_USERNAME_PASSWORD: 'bad username/password, access denied', NO_PACKAGE: 'no such package available', NOT_ALLOWED: 'not allowed to access package', INTERNAL_SERVER_ERROR: 'internal server error', diff --git a/test/flow/plugins/auth/example.auth.plugin.js b/test/flow/plugins/auth/example.auth.plugin.js index 9527d51e7..f3e3d4728 100644 --- a/test/flow/plugins/auth/example.auth.plugin.js +++ b/test/flow/plugins/auth/example.auth.plugin.js @@ -9,6 +9,7 @@ import type { Config as AppConfig, PackageAccess, IPluginAuth, + RemoteUser, Logger, PluginOptions } from '@verdaccio/types'; @@ -30,11 +31,11 @@ class ExampleAuthPlugin implements IPluginAuth { cb(); } - allow_access(user: string, pkg: PackageAccess, cb: verdaccio$Callback): void { + allow_access(user: RemoteUser, pkg: PackageAccess, cb: verdaccio$Callback): void { cb(); } - allow_publish(user: string, pkg: PackageAccess, cb: verdaccio$Callback): void { + allow_publish(user: RemoteUser, pkg: PackageAccess, cb: verdaccio$Callback): void { cb(); } } @@ -50,7 +51,12 @@ const options: PluginOptions = { } const auth = new ExampleAuthPlugin(config1, options); +const remoteUser: RemoteUser = { + groups: [], + real_groups: [], + name: 'test' +}; auth.authenticate('user', 'pass', () => {}); -auth.allow_access('packageName', {}, () => {}); -auth.allow_publish('packageName', {}, () => {}); +auth.allow_access(remoteUser, {}, () => {}); +auth.allow_publish(remoteUser, {}, () => {}); diff --git a/test/flow/plugins/middleware/example.middleware.plugin.js b/test/flow/plugins/middleware/example.middleware.plugin.js index 2e5767f7e..0789a0385 100644 --- a/test/flow/plugins/middleware/example.middleware.plugin.js +++ b/test/flow/plugins/middleware/example.middleware.plugin.js @@ -11,14 +11,20 @@ import type { Config as AppConfig, IPluginMiddleware, IStorageManager, + RemoteUser, IBasicAuth, } from '@verdaccio/types'; import type { IUploadTarball, IReadTarball } from '@verdaccio/streams'; export default class ExampleMiddlewarePlugin implements IPluginMiddleware { register_middlewares(app: any, auth: IBasicAuth, storage: IStorageManager): void { + const remoteUser: RemoteUser = { + groups: [], + real_groups: [], + name: 'test' + }; auth.authenticate('user', 'password', () => {}); - auth.allow_access('packageName', 'user', () => {}); + auth.allow_access('packageName', remoteUser, () => {}); auth.add_user('user', 'password', () => {}); auth.aesEncrypt(new Buffer('pass')); // storage diff --git a/yarn.lock b/yarn.lock index 99bb7f272502bcc8516237bc3d15e648682c3f52..0eafbcc11b48659386edd4f64927dbcaf2379a5a 100644 GIT binary patch delta 104 zcmcbzNc74g(G7iyEGBveO4I*|vRF@EFV8*shN6HzP(-gJy-L~G($F-`B+1w^(IVB- zEY;M+Jk=z{*wQR1&BVYg#XQy6DAB~!BxSOrfk?BqQoFViBM>tIF*6XeY}Zy|)zk+7 DzTzF7 delta 104 zcmcbzNc74g(G7iyEXI1qO4A$cS*<6pm*<{*Ls380m2sa;!%5r~<9m>Gy!wreY~YU%?3 Ds)rr3