0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00
verdaccio/test/flow/plugins/auth/example.auth.plugin.js

102 lines
2.6 KiB
JavaScript
Raw Normal View History

/**
* @prettier
*/
2018-07-14 05:16:27 -05:00
// @flow
// this file is not aim to be tested, just to check flow definitions
2018-07-14 05:16:27 -05:00
import Config from '../../../../src/lib/config';
import LoggerApi from '../../../../src/lib/logger';
import type { Config as AppConfig, PackageAccess, IPluginAuth, RemoteUser, Logger, PluginOptions } from '@verdaccio/types';
2018-07-14 05:16:27 -05:00
class ExampleAuthPlugin implements IPluginAuth {
config: AppConfig;
logger: Logger;
constructor(config: AppConfig, options: PluginOptions) {
this.config = config;
this.logger = options.logger;
}
2018-07-14 05:16:27 -05:00
adduser(user: string, password: string, cb: verdaccio$Callback): void {
cb();
}
2018-07-14 05:16:27 -05:00
changePassword(username, password, newPassword, cb: verdaccio$Callback): void {
cb();
}
authenticate(user: string, password: string, cb: verdaccio$Callback): void {
cb();
}
2018-07-14 05:16:27 -05:00
2018-07-16 12:53:26 -05:00
allow_access(user: RemoteUser, pkg: PackageAccess, cb: verdaccio$Callback): void {
cb();
}
2018-07-14 05:16:27 -05:00
2018-07-16 12:53:26 -05:00
allow_publish(user: RemoteUser, pkg: PackageAccess, cb: verdaccio$Callback): void {
cb();
}
2018-07-14 05:16:27 -05:00
}
2018-07-16 13:50:29 -05:00
type SubTypePackageAccess = PackageAccess & {
sub?: boolean,
};
2018-07-16 13:50:29 -05:00
class ExampleAuthCustomPlugin implements IPluginAuth {
config: AppConfig;
logger: Logger;
2018-07-16 13:50:29 -05:00
constructor(config: AppConfig, options: PluginOptions) {
this.config = config;
this.logger = options.logger;
}
2018-07-16 13:50:29 -05:00
adduser(user: string, password: string, cb: verdaccio$Callback): void {
cb();
}
2018-07-16 13:50:29 -05:00
changePassword(username, password, newPassword, cb: verdaccio$Callback): void {
cb();
}
authenticate(user: string, password: string, cb: verdaccio$Callback): void {
cb();
}
2018-07-16 13:50:29 -05:00
allow_access(user: RemoteUser, pkg: SubTypePackageAccess, cb: verdaccio$Callback): void {
cb();
}
2018-07-16 13:50:29 -05:00
allow_publish(user: RemoteUser, pkg: SubTypePackageAccess, cb: verdaccio$Callback): void {
cb();
}
2018-07-16 13:50:29 -05:00
}
2018-07-14 05:16:27 -05:00
const config1: AppConfig = new Config({
storage: './storage',
self_path: '/home/sotrage',
2018-07-14 05:16:27 -05:00
});
const options: PluginOptions = {
config: config1,
logger: LoggerApi.logger.child(),
};
2018-07-14 05:16:27 -05:00
const auth = new ExampleAuthPlugin(config1, options);
2018-07-16 13:50:29 -05:00
const authSub = new ExampleAuthCustomPlugin(config1, options);
2018-07-16 12:53:26 -05:00
const remoteUser: RemoteUser = {
groups: [],
real_groups: [],
name: 'test',
2018-07-16 12:53:26 -05:00
};
auth.authenticate('user', 'pass', () => {});
2019-01-12 09:45:47 -05:00
auth.allow_access(remoteUser, { access: [], publish: [], proxy: [] }, () => {});
auth.allow_publish(remoteUser, { access: [], publish: [], proxy: [] }, () => {});
2018-07-16 13:50:29 -05:00
authSub.authenticate('user', 'pass', () => {});
2019-01-12 09:45:47 -05:00
authSub.allow_access(remoteUser, { access: [], publish: [], proxy: [], sub: true }, () => {});
authSub.allow_publish(remoteUser, { access: [], publish: [], proxy: [], sub: true }, () => {});