/* * Copyright (C) Sapphirecode - All Rights Reserved * This file is part of Auth-Server-Helper which is released under MIT. * See file 'LICENSE' for full license details. * Created by Timo Hocker , January 2021 */ /* eslint-disable no-console */ import http from 'http'; import ks from '../lib/KeyStore'; export class Response extends http.IncomingMessage { body?: string; } export function get ( // eslint-disable-next-line default-param-last headers: http.OutgoingHttpHeaders = {}, body?: string ): Promise { return new Promise ((resolve) => { const req = http.request ('http://localhost:3000', { headers, method: typeof body === 'string' ? 'POST' : 'GET' }, (res: Response) => { let data = ''; res.on ('data', (d) => { data += d; }); res.on ('end', () => { res.body = data; resolve (res); }); }); if (typeof body === 'string') req.write (body); req.end (); }); } export function modify_signature (signature: string): string { const dec = signature.split ('.'); dec[1] = ''; return dec.join ('.'); } /* eslint-disable dot-notation */ export function assert_keystore_state (): void { if (Object.keys (ks['_keys']).length !== 0) { console.warn ('keystore gc not running!'); ks['_keys'] = {}; } } /* eslint-enable dot-notation */ export function flush_routine (install_clock = true):void { if (install_clock) { jasmine.clock () .install (); } jasmine.clock () .mockDate (new Date); jasmine.clock () .tick (30 * 24 * 60 * 60 * 1000); if (install_clock) { jasmine.clock () .uninstall (); } }