diff --git a/README.md b/README.md index 2a0d8c7..9034fee 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,18 @@ const export = keystore.export_verification_data(); keystore.import_verification_data(export); ``` +### Exporting and importing blacklist entries across server instances + +```js +const {blacklist} = require('@sapphirecode/auth-server-helper'); + +const export = blacklist.export_blacklist(); + +// second instance + +blacklist.import_blacklist(export); +``` + ## License MIT © Timo Hocker diff --git a/lib/Blacklist.ts b/lib/Blacklist.ts index 6029b68..2d3d73b 100644 --- a/lib/Blacklist.ts +++ b/lib/Blacklist.ts @@ -43,6 +43,14 @@ class Blacklist { return true; } + + public export_blacklist (): Signature[] { + return this._signatures; + } + + public import_blacklist (data: Signature[]): void { + this._signatures.push (...data); + } } const bl = (new Blacklist); diff --git a/test/spec/Blacklist.ts b/test/spec/Blacklist.ts index bfa56d5..3edc32a 100644 --- a/test/spec/Blacklist.ts +++ b/test/spec/Blacklist.ts @@ -5,7 +5,7 @@ * Created by Timo Hocker , December 2020 */ -import blacklist from '../../lib/Blacklist'; +import blacklist, { Blacklist } from '../../lib/Blacklist'; import { clock_finalize, clock_setup } from '../Helper'; // eslint-disable-next-line max-lines-per-function @@ -60,4 +60,16 @@ describe ('blacklist', () => { expect (blacklist.is_valid ('baz')) .toBeFalse (); }); + + it ('should export and import data', () => { + const exp = blacklist.export_blacklist (); + // eslint-disable-next-line dot-notation + expect (blacklist['_signatures']) + .toEqual (exp); + const bl2 = (new Blacklist); + bl2.import_blacklist (exp); + // eslint-disable-next-line dot-notation + expect (bl2['_signatures']) + .toEqual (exp); + }); });