fix(core): update

This commit is contained in:
Philipp Kunz 2020-06-10 06:57:47 +00:00
parent 5f8f158ab4
commit b07874f001
2 changed files with 7 additions and 4 deletions

View File

@ -12,7 +12,7 @@ tap.test('should create a valid SmartlogReceiver', async () => {
testReceiver = new smartlogReceiver.SmartlogReceiver({ testReceiver = new smartlogReceiver.SmartlogReceiver({
passphrase: 'hi', passphrase: 'hi',
smartlogInstance: testSmartlog, smartlogInstance: testSmartlog,
validatorFunction: () => { validatorFunction: async () => {
return true; return true;
} }
}); });

View File

@ -6,7 +6,7 @@ import {
ILogDestination, ILogDestination,
} from '@pushrocks/smartlog-interfaces'; } from '@pushrocks/smartlog-interfaces';
export type TValidatorFunction = (logPackage: ILogPackage) => boolean; export type TValidatorFunction = (logPackage: ILogPackage) => Promise<boolean>;
export interface ISmartlogReceiverOptions { export interface ISmartlogReceiverOptions {
smartlogInstance: plugins.smartlog.Smartlog; smartlogInstance: plugins.smartlog.Smartlog;
@ -24,7 +24,7 @@ export class SmartlogReceiver {
constructor(smartlogReceiverOptions: ISmartlogReceiverOptions) { constructor(smartlogReceiverOptions: ISmartlogReceiverOptions) {
this.passphrase = smartlogReceiverOptions.passphrase; this.passphrase = smartlogReceiverOptions.passphrase;
this.validatorFunction = smartlogReceiverOptions.validatorFunction; this.validatorFunction = smartlogReceiverOptions.validatorFunction || (async (logpackageArg) => {return true});
this.smartlogInstance = smartlogReceiverOptions.smartlogInstance; this.smartlogInstance = smartlogReceiverOptions.smartlogInstance;
} }
@ -35,7 +35,10 @@ export class SmartlogReceiver {
const authString = authenticatedLogPackageArg.auth; const authString = authenticatedLogPackageArg.auth;
const logPackage = authenticatedLogPackageArg.logPackage; const logPackage = authenticatedLogPackageArg.logPackage;
if (authString === plugins.smarthash.sha256FromStringSync(this.passphrase)) { if (
authString === plugins.smarthash.sha256FromStringSync(this.passphrase)
&& await this.validatorFunction(logPackage)
) {
// Message authenticated lets clean up. // Message authenticated lets clean up.
logPackage.correlation ? null : (logPackage.correlation = { id: '123', type: 'none' }); logPackage.correlation ? null : (logPackage.correlation = { id: '123', type: 'none' });
logPackage.correlation.id ? null : (logPackage.correlation.id = '123'); logPackage.correlation.id ? null : (logPackage.correlation.id = '123');