2018-07-14 12:16:27 +02:00
|
|
|
// @flow
|
|
|
|
|
2018-07-15 19:26:58 +02:00
|
|
|
// this file is not aim to be tested, just to check flow definitions
|
|
|
|
|
2018-07-14 12:16:27 +02:00
|
|
|
import Config from '../../../../src/lib/config';
|
|
|
|
import LoggerApi from '../../../../src/lib/logger';
|
|
|
|
|
|
|
|
import type {
|
|
|
|
Config as AppConfig,
|
2018-07-16 17:34:59 +02:00
|
|
|
PackageAccess,
|
2018-07-15 19:26:58 +02:00
|
|
|
IPluginAuth,
|
2018-07-16 19:53:26 +02:00
|
|
|
RemoteUser,
|
2018-07-14 12:16:27 +02:00
|
|
|
Logger,
|
|
|
|
PluginOptions
|
|
|
|
} from '@verdaccio/types';
|
|
|
|
|
2018-07-15 19:26:58 +02:00
|
|
|
class ExampleAuthPlugin implements IPluginAuth {
|
2018-07-14 12:16:27 +02:00
|
|
|
config: AppConfig;
|
|
|
|
logger: Logger;
|
|
|
|
|
|
|
|
constructor(config: AppConfig, options: PluginOptions) {
|
|
|
|
this.config = config;
|
|
|
|
this.logger = options.logger;
|
|
|
|
}
|
|
|
|
|
2018-07-16 07:20:11 +02:00
|
|
|
adduser(user: string, password: string, cb: verdaccio$Callback): void {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
2018-07-14 12:16:27 +02:00
|
|
|
authenticate(user: string, password: string, cb: verdaccio$Callback): void {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
2018-07-16 19:53:26 +02:00
|
|
|
allow_access(user: RemoteUser, pkg: PackageAccess, cb: verdaccio$Callback): void {
|
2018-07-14 12:16:27 +02:00
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
2018-07-16 19:53:26 +02:00
|
|
|
allow_publish(user: RemoteUser, pkg: PackageAccess, cb: verdaccio$Callback): void {
|
2018-07-14 12:16:27 +02:00
|
|
|
cb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 20:50:29 +02:00
|
|
|
type SubTypePackageAccess = PackageAccess & {
|
|
|
|
sub?: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
class ExampleAuthCustomPlugin implements IPluginAuth {
|
|
|
|
config: AppConfig;
|
|
|
|
logger: Logger;
|
|
|
|
|
|
|
|
constructor(config: AppConfig, options: PluginOptions) {
|
|
|
|
this.config = config;
|
|
|
|
this.logger = options.logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
adduser(user: string, password: string, cb: verdaccio$Callback): void {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
authenticate(user: string, password: string, cb: verdaccio$Callback): void {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
allow_access(user: RemoteUser, pkg: SubTypePackageAccess, cb: verdaccio$Callback): void {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
allow_publish(user: RemoteUser, pkg: SubTypePackageAccess, cb: verdaccio$Callback): void {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-14 12:16:27 +02:00
|
|
|
const config1: AppConfig = new Config({
|
|
|
|
storage: './storage',
|
|
|
|
self_path: '/home/sotrage'
|
|
|
|
});
|
|
|
|
|
|
|
|
const options: PluginOptions = {
|
|
|
|
config: config1,
|
|
|
|
logger: LoggerApi.logger.child()
|
|
|
|
}
|
|
|
|
|
2018-07-15 19:26:58 +02:00
|
|
|
const auth = new ExampleAuthPlugin(config1, options);
|
2018-07-16 20:50:29 +02:00
|
|
|
const authSub = new ExampleAuthCustomPlugin(config1, options);
|
2018-07-16 19:53:26 +02:00
|
|
|
const remoteUser: RemoteUser = {
|
|
|
|
groups: [],
|
|
|
|
real_groups: [],
|
|
|
|
name: 'test'
|
|
|
|
};
|
2018-07-15 19:26:58 +02:00
|
|
|
|
|
|
|
auth.authenticate('user', 'pass', () => {});
|
2018-07-16 19:53:26 +02:00
|
|
|
auth.allow_access(remoteUser, {}, () => {});
|
|
|
|
auth.allow_publish(remoteUser, {}, () => {});
|
2018-07-16 20:50:29 +02:00
|
|
|
authSub.authenticate('user', 'pass', () => {});
|
|
|
|
authSub.allow_access(remoteUser, {sub: true}, () => {});
|
|
|
|
authSub.allow_publish(remoteUser, {sub: true}, () => {});
|