From 1ebcd2063755c7e43c1549932336c099b47eb9ae Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Wed, 13 Sep 2023 16:49:06 +1000 Subject: [PATCH] feat: consolidating client service logic into `ClientService` [ci skip] --- src/PolykeyAgent.ts | 121 ++-- src/client/ClientService.ts | 176 +++++ src/client/errors.ts | 21 + src/client/events.ts | 28 + src/client/handlers/agentStatus.ts | 8 +- tests/PolykeyClient.test.ts | 4 +- tests/client/ClientService.test.ts | 42 ++ tests/client/authenticationMiddleware.test.ts | 36 +- tests/client/handlers/agent.test.ts | 122 ++-- tests/client/handlers/gestalts.test.ts | 283 ++++---- tests/client/handlers/identities.test.ts | 620 ++++++++---------- tests/client/handlers/keys.test.ts | 191 +++--- tests/client/handlers/nodes.test.ts | 199 +++--- tests/client/handlers/notifications.test.ts | 171 +++-- tests/client/handlers/vaults.test.ts | 333 +++++----- tests/client/timeoutMiddleware.test.ts | 59 +- tests/discovery/Discovery.test.ts | 4 +- .../NodeConnectionManager.general.test.ts | 4 +- .../NodeConnectionManager.seednodes.test.ts | 8 +- .../NodeConnectionManager.timeout.test.ts | 4 +- tests/nodes/NodeManager.test.ts | 4 +- .../NotificationsManager.test.ts | 4 +- tests/vaults/VaultManager.test.ts | 20 +- 23 files changed, 1268 insertions(+), 1194 deletions(-) create mode 100644 src/client/ClientService.ts create mode 100644 src/client/events.ts create mode 100644 tests/client/ClientService.test.ts diff --git a/src/PolykeyAgent.ts b/src/PolykeyAgent.ts index 1e7e23db8f..3057167f67 100644 --- a/src/PolykeyAgent.ts +++ b/src/PolykeyAgent.ts @@ -9,9 +9,11 @@ import path from 'path'; import process from 'process'; import Logger from '@matrixai/logger'; import { DB } from '@matrixai/db'; -import { CreateDestroyStartStop } from '@matrixai/async-init/dist/CreateDestroyStartStop'; +import { + CreateDestroyStartStop, + ready, +} from '@matrixai/async-init/dist/CreateDestroyStartStop'; import RPCServer from './rpc/RPCServer'; -import WebSocketServer from './websockets/WebSocketServer'; import * as rpcUtilsMiddleware from './rpc/utils/middleware'; import * as clientUtilsMiddleware from './client/utils/middleware'; import { WorkerManager } from './workers'; @@ -42,6 +44,7 @@ import * as workersUtils from './workers/utils'; import TaskManager from './tasks/TaskManager'; import { serverManifest as clientServerManifest } from './client/handlers'; import { serverManifest as agentServerManifest } from './agent/handlers'; +import ClientService from './client/ClientService'; /** * Optional configuration for `PolykeyAgent`. @@ -105,7 +108,7 @@ class PolykeyAgent { * All optional configuration is deep-merged with defaults. * * If any of the optional dependencies is injected, their lifecycle will not - * be managed by `PolykeyAgent`. Furthermore if you inject an optional + * be managed by `PolykeyAgent`. Furthermore, if you inject an optional * dependency, make sure you are injecting all upstream transitive * dependencies at the same time. For example if you inject `acl`, you must * also inject `db`. @@ -134,8 +137,7 @@ class PolykeyAgent { vaultManager, notificationsManager, sessionManager, - rpcServerClient, - webSocketServerClient, + clientService, rpcServerAgent, fs = require('fs'), logger = new Logger(this.name), @@ -159,8 +161,7 @@ class PolykeyAgent { vaultManager?: VaultManager; notificationsManager?: NotificationsManager; sessionManager?: SessionManager; - rpcServerClient?: RPCServer; - webSocketServerClient?: WebSocketServer; + clientService?: ClientService; rpcServerAgent?: RPCServer; fs?: FileSystem; logger?: Logger; @@ -447,9 +448,9 @@ class PolykeyAgent { if (optionsDefaulted.keys.recoveryCode != null) { await sessionManager.resetKey(); } - if (rpcServerClient == null) { + if (clientService == null) { pkAgentProm = utils.promise(); - rpcServerClient = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ manifest: clientServerManifest({ acl: acl, certManager: certManager, @@ -468,30 +469,23 @@ class PolykeyAgent { sessionManager: sessionManager, vaultManager: vaultManager, }), - middlewareFactory: rpcUtilsMiddleware.defaultServerMiddlewareWrapper( - clientUtilsMiddleware.middlewareServer(sessionManager, keyRing), - optionsDefaulted.rpc.parserBufferSize, - ), - sensitive: false, - handlerTimeoutTime: optionsDefaulted.rpc.callTimeoutTime, - handlerTimeoutGraceTime: optionsDefaulted.rpc.callTimeoutTime + 2000, - logger: logger.getChild(RPCServer.name + 'Client'), + tlsConfig, + options: { + middlewareFactory: clientUtilsMiddleware.middlewareServer( + sessionManager, + keyRing, + ), + host: optionsDefaulted.clientServiceHost, + port: optionsDefaulted.clientServicePort, + keepAliveTimeoutTime: optionsDefaulted.client.keepAliveTimeoutTime, + keepAliveIntervalTime: + optionsDefaulted.client.keepAliveIntervalTime, + rpcCallTimeoutTime: optionsDefaulted.rpc.callTimeoutTime, + rpcParserBufferSize: optionsDefaulted.rpc.parserBufferSize, + }, + logger: logger.getChild(ClientService.name), }); } - webSocketServerClient = - webSocketServerClient ?? - (await WebSocketServer.createWebSocketServer({ - connectionCallback: (rpcStream) => - rpcServerClient!.handleStream(rpcStream), - host: optionsDefaulted.clientServiceHost, - port: optionsDefaulted.clientServicePort, - tlsConfig, - // FIXME: Not sure about this, maxIdleTimeout doesn't seem to be used? - maxIdleTimeout: optionsDefaulted.client.keepAliveTimeoutTime, - pingIntervalTime: optionsDefaulted.client.keepAliveIntervalTime, - pingTimeoutTimeTime: optionsDefaulted.client.keepAliveTimeoutTime, - logger: logger.getChild('WebSocketServer'), - })); if (rpcServerAgent == null) { rpcServerAgent = await RPCServer.createRPCServer({ manifest: agentServerManifest({ @@ -519,8 +513,7 @@ class PolykeyAgent { } catch (e) { logger.warn(`Failed Creating ${this.name}`); await rpcServerAgent?.destroy(true); - await rpcServerClient?.destroy(); - await webSocketServerClient?.stop(true); + await clientService?.stop({ force: true }); await sessionManager?.stop(); await notificationsManager?.stop(); await vaultManager?.stop(); @@ -556,8 +549,7 @@ class PolykeyAgent { vaultManager, notificationsManager, sessionManager, - rpcServerClient, - webSocketServerClient, + clientService, rpcServerAgent, fs, logger, @@ -600,8 +592,7 @@ class PolykeyAgent { public readonly sessionManager: SessionManager; public readonly fs: FileSystem; public readonly logger: Logger; - public readonly rpcServerClient: RPCServer; - public readonly webSocketServerClient: WebSocketServer; + public readonly clientService: ClientService; public readonly rpcServerAgent: RPCServer; protected workerManager: PolykeyWorkerManagerInterface | undefined; @@ -625,7 +616,7 @@ class PolykeyAgent { keyPrivatePem: keysUtils.privateKeyToPEM(data.keyPair.privateKey), certChainPem: await this.certManager.getCertPEMsChainPEM(), }; - this.webSocketServerClient.setTlsConfig(tlsConfig); + this.clientService.setTlsConfig(tlsConfig); this.nodeConnectionManager.updateTlsConfig(tlsConfig); this.logger.info(`${KeyRing.name} change propagated`); }; @@ -649,8 +640,7 @@ class PolykeyAgent { vaultManager, notificationsManager, sessionManager, - rpcServerClient, - webSocketServerClient, + clientService, rpcServerAgent, fs, logger, @@ -673,8 +663,7 @@ class PolykeyAgent { vaultManager: VaultManager; notificationsManager: NotificationsManager; sessionManager: SessionManager; - rpcServerClient: RPCServer; - webSocketServerClient: WebSocketServer; + clientService: ClientService; rpcServerAgent: RPCServer; fs: FileSystem; logger: Logger; @@ -698,13 +687,30 @@ class PolykeyAgent { this.vaultManager = vaultManager; this.notificationsManager = notificationsManager; this.sessionManager = sessionManager; - this.rpcServerClient = rpcServerClient; - this.webSocketServerClient = webSocketServerClient; + this.clientService = clientService; this.rpcServerAgent = rpcServerAgent; this.fs = fs; } - // TODO: add getters for runtime service information? + @ready(new errors.ErrorPolykeyAgentNotRunning()) + get clientServiceHost() { + return this.clientService.host; + } + + @ready(new errors.ErrorPolykeyAgentNotRunning()) + get clientServicePort() { + return this.clientService.port; + } + + @ready(new errors.ErrorPolykeyAgentNotRunning()) + get agentServiceHost() { + return this.nodeConnectionManager.host as string; + } + + @ready(new errors.ErrorPolykeyAgentNotRunning()) + get agentServicePort() { + return this.nodeConnectionManager.port as number; + } public async start({ password, @@ -775,13 +781,12 @@ class PolykeyAgent { ), certChainPem: await this.certManager.getCertPEMsChainPEM(), }; - // Client server - await this.webSocketServerClient.start({ + await this.clientService.start({ tlsConfig, - host: optionsDefaulted.clientServiceHost, - port: optionsDefaulted.clientServicePort, - connectionCallback: (streamPair) => - this.rpcServerClient.handleStream(streamPair), + options: { + host: optionsDefaulted.clientServiceHost, + port: optionsDefaulted.clientServicePort, + }, }); await this.nodeManager.start(); this.nodeConnectionManager.addEventListener( @@ -812,10 +817,10 @@ class PolykeyAgent { await this.status.finishStart({ pid: process.pid, nodeId: this.keyRing.getNodeId(), - clientHost: this.webSocketServerClient.getHost(), - clientPort: this.webSocketServerClient.getPort(), - agentHost: this.nodeConnectionManager.host, - agentPort: this.nodeConnectionManager.port, + clientHost: this.clientServiceHost, + clientPort: this.clientServicePort, + agentHost: this.agentServiceHost, + agentPort: this.agentServicePort, }); this.logger.info(`Started ${this.constructor.name}`); } catch (e) { @@ -840,7 +845,7 @@ class PolykeyAgent { this.handleEventNodeStream, ); await this.nodeManager?.stop(); - await this.webSocketServerClient.stop(true); + await this.clientService.stop({ force: true }); await this.identitiesManager?.stop(); await this.gestaltGraph?.stop(); await this.acl?.stop(); @@ -881,7 +886,7 @@ class PolykeyAgent { ); await this.nodeGraph.stop(); await this.nodeManager.stop(); - await this.webSocketServerClient.stop(true); + await this.clientService.stop({ force: true }); await this.identitiesManager.stop(); await this.gestaltGraph.stop(); await this.acl.stop(); @@ -930,7 +935,7 @@ class PolykeyAgent { await this.discovery.destroy(); await this.nodeGraph.destroy(); await this.rpcServerAgent.destroy(); - await this.rpcServerClient.destroy(); + await this.clientService.destroy({ force: true }); await this.identitiesManager.destroy(); await this.gestaltGraph.destroy(); await this.acl.destroy(); diff --git a/src/client/ClientService.ts b/src/client/ClientService.ts new file mode 100644 index 0000000000..78ccd09a2b --- /dev/null +++ b/src/client/ClientService.ts @@ -0,0 +1,176 @@ +import type { + JSONRPCRequest, + JSONRPCResponse, + MiddlewareFactory, + ServerManifest, +} from '../rpc/types'; +import type { TLSConfig } from '../network/types'; +import Logger from '@matrixai/logger'; +import { CreateDestroyStartStop } from '@matrixai/async-init/dist/CreateDestroyStartStop'; +import * as errors from './errors'; +import * as events from './events'; +import WebSocketServer from '../websockets/WebSocketServer'; +import RPCServer from '../rpc/RPCServer'; +import * as rpcUtilsMiddleware from '../rpc/utils/middleware'; +import config from '../config'; + +interface ClientService extends CreateDestroyStartStop {} +@CreateDestroyStartStop( + new errors.ErrorClientServiceRunning(), + new errors.ErrorClientServiceDestroyed(), + { + eventStart: events.EventClientServiceStart, + eventStarted: events.EventClientServiceStarted, + eventStop: events.EventClientServiceStop, + eventStopped: events.EventClientServiceStopped, + eventDestroy: events.EventClientServiceDestroy, + eventDestroyed: events.EventClientServiceDestroyed, + }, +) +class ClientService { + public static async createClientService({ + manifest, + tlsConfig, + options: { + middlewareFactory, + host = config.defaultsUser.clientServiceHost, + port = config.defaultsUser.clientServicePort, + keepAliveTimeoutTime = config.defaultsSystem.clientKeepAliveTimeoutTime, + keepAliveIntervalTime = config.defaultsSystem.clientKeepAliveIntervalTime, + rpcCallTimeoutTime = config.defaultsSystem.rpcCallTimeoutTime, + rpcParserBufferSize = config.defaultsSystem.rpcParserBufferSize, + }, + logger = new Logger(this.name), + }: { + manifest: ServerManifest; + tlsConfig: TLSConfig; + options: { + middlewareFactory?: MiddlewareFactory< + JSONRPCRequest, + JSONRPCRequest, + JSONRPCResponse, + JSONRPCResponse + >; + host?: string; + port?: number; + keepAliveTimeoutTime?: number; + keepAliveIntervalTime?: number; + rpcCallTimeoutTime?: number; + rpcParserBufferSize?: number; + }; + logger?: Logger; + }): Promise { + logger.info(`Creating ${this.name}`); + + const rpcServer = await RPCServer.createRPCServer({ + handlerTimeoutGraceTime: 2000, // TODO: this will be removed. + handlerTimeoutTime: rpcCallTimeoutTime, + manifest, + middlewareFactory: rpcUtilsMiddleware.defaultServerMiddlewareWrapper( + // ClientUtilsMiddleware.middlewareServer(sessionManager, keyRing), + middlewareFactory, + rpcParserBufferSize, + ), + sensitive: false, + logger: logger.getChild(RPCServer.name), + }); + + const webSocketServer = await WebSocketServer.createWebSocketServer({ + connectionCallback: (rpcStream) => rpcServer.handleStream(rpcStream), + host, + port, + tlsConfig, + // FIXME: Not sure about this, maxIdleTimeout doesn't seem to be used? + maxIdleTimeout: keepAliveTimeoutTime, + pingIntervalTime: keepAliveIntervalTime, + pingTimeoutTimeTime: keepAliveTimeoutTime, + logger: logger.getChild(WebSocketServer.name), + }); + + const clientService = new ClientService({ + rpcServer, + webSocketServer, + logger, + }); + await clientService.start({ + tlsConfig, + options: { + host, + port, + }, + }); + logger.info(`Created ${this.name}`); + return clientService; + } + + protected rpcServer: RPCServer; + protected webSocketServer: WebSocketServer; + protected logger: Logger; + + constructor({ + rpcServer, + webSocketServer, + logger, + }: { + rpcServer: RPCServer; + webSocketServer: WebSocketServer; + logger: Logger; + }) { + this.rpcServer = rpcServer; + this.webSocketServer = webSocketServer; + this.logger = logger; + } + + get host() { + return this.webSocketServer.getHost(); + } + + get port() { + return this.webSocketServer.getPort(); + } + + public async start({ + tlsConfig, + options: { + host = config.defaultsUser.clientServiceHost, + port = config.defaultsUser.clientServicePort, + }, + }: { + tlsConfig: TLSConfig; + options: { + host?: string; + port?: number; + }; + }): Promise { + this.logger.info(`Starting ${this.constructor.name}`); + await this.webSocketServer.start({ + tlsConfig, + host, + port, + connectionCallback: (rpcStream) => this.rpcServer.handleStream(rpcStream), + }); + this.logger.info(`Started ${this.constructor.name}`); + } + + public async stop({ + force = false, + }: { force?: boolean } = {}): Promise { + this.logger.info(`Stopping ${this.constructor.name}`); + await this.webSocketServer.stop(force); + this.logger.info(`Stopped ${this.constructor.name}`); + } + + public async destroy({ + force = false, + }: { force?: boolean } = {}): Promise { + this.logger.info(`Destroying ${this.constructor.name}`); + await this.rpcServer.destroy(force); + this.logger.info(`Destroyed ${this.constructor.name}`); + } + + public setTlsConfig(tlsConfig: TLSConfig): void { + this.webSocketServer.setTlsConfig(tlsConfig); + } +} + +export default ClientService; diff --git a/src/client/errors.ts b/src/client/errors.ts index e9acc8027a..d2276b6f49 100644 --- a/src/client/errors.ts +++ b/src/client/errors.ts @@ -17,9 +17,30 @@ class ErrorClientAuthDenied extends ErrorClient { exitCode = sysexits.NOPERM; } +class ErrorClientService extends ErrorClient {} + +class ErrorClientServiceRunning extends ErrorClientService { + static description = 'ClientService is running'; + exitCode = sysexits.USAGE; +} + +class ErrorClientServiceNotRunning extends ErrorClientService { + static description = 'ClientService is not running'; + exitCode = sysexits.USAGE; +} + +class ErrorClientServiceDestroyed extends ErrorClientService { + static description = 'ClientService is destroyed'; + exitCode = sysexits.USAGE; +} + export { ErrorClient, ErrorClientAuthMissing, ErrorClientAuthFormat, ErrorClientAuthDenied, + ErrorClientService, + ErrorClientServiceRunning, + ErrorClientServiceNotRunning, + ErrorClientServiceDestroyed, }; diff --git a/src/client/events.ts b/src/client/events.ts new file mode 100644 index 0000000000..dbb118f201 --- /dev/null +++ b/src/client/events.ts @@ -0,0 +1,28 @@ +import { AbstractEvent } from '@matrixai/events'; + +abstract class EventsClient extends AbstractEvent {} + +abstract class EventsClientService extends EventsClient {} + +class EventClientServiceStart extends EventsClientService {} + +class EventClientServiceStarted extends EventsClientService {} + +class EventClientServiceStop extends EventsClientService {} + +class EventClientServiceStopped extends EventsClientService {} + +class EventClientServiceDestroy extends EventsClientService {} + +class EventClientServiceDestroyed extends EventsClientService {} + +export { + EventsClient, + EventsClientService, + EventClientServiceStart, + EventClientServiceStarted, + EventClientServiceStop, + EventClientServiceStopped, + EventClientServiceDestroy, + EventClientServiceDestroyed, +}; diff --git a/src/client/handlers/agentStatus.ts b/src/client/handlers/agentStatus.ts index 25bdf2b6c8..b2ae92c6a2 100644 --- a/src/client/handlers/agentStatus.ts +++ b/src/client/handlers/agentStatus.ts @@ -18,10 +18,10 @@ class AgentStatusHandler extends UnaryHandler< return { pid: process.pid, nodeIdEncoded: nodesUtils.encodeNodeId(pkAgent.keyRing.getNodeId()), - clientHost: pkAgent.webSocketServerClient.getHost(), - clientPort: pkAgent.webSocketServerClient.getPort(), - agentHost: pkAgent.nodeConnectionManager.host, - agentPort: pkAgent.nodeConnectionManager.port, + clientHost: pkAgent.clientServiceHost, + clientPort: pkAgent.clientServicePort, + agentHost: pkAgent.agentServiceHost, + agentPort: pkAgent.agentServicePort, publicKeyJwk: keysUtils.publicKeyToJWK(pkAgent.keyRing.keyPair.publicKey), certChainPEM: await pkAgent.certManager.getCertPEMsChainPEM(), }; diff --git a/tests/PolykeyClient.test.ts b/tests/PolykeyClient.test.ts index 6e0558e911..fe319c73ec 100644 --- a/tests/PolykeyClient.test.ts +++ b/tests/PolykeyClient.test.ts @@ -55,8 +55,8 @@ describe('PolykeyClient', () => { // Using fresh: true means that any token would be destroyed const webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [pkAgent.keyRing.getNodeId()], - host: pkAgent.webSocketServerClient.getHost(), - port: pkAgent.webSocketServerClient.getPort(), + host: pkAgent.clientServiceHost, + port: pkAgent.clientServicePort, logger, }); const pkClient = await PolykeyClient.createPolykeyClient({ diff --git a/tests/client/ClientService.test.ts b/tests/client/ClientService.test.ts new file mode 100644 index 0000000000..008b0d9d14 --- /dev/null +++ b/tests/client/ClientService.test.ts @@ -0,0 +1,42 @@ +import type { TLSConfig } from '@/network/types'; +import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger'; +import ClientService from '@/client/ClientService'; +import * as keysUtils from '@/keys/utils'; +import * as utils from '../utils'; + +describe(`ClientService tests`, () => { + const logger = new Logger(`${ClientService.name} test`, LogLevel.WARN, [ + new StreamHandler( + formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`, + ), + ]); + const localHost = '127.0.0.1'; + + let clientService: ClientService; + let tlsConfig: TLSConfig; + + beforeEach(async () => { + tlsConfig = await utils.createTLSConfig(keysUtils.generateKeyPair()); + }); + afterEach(async () => { + await clientService?.stop({ force: true }); + }); + + test('ClientService readiness', async () => { + clientService = await ClientService.createClientService({ + manifest: {}, + options: { + host: localHost, + }, + tlsConfig, + logger, + }); + await clientService.stop({ force: true }); + // Should be a noop + await clientService.stop({ force: true }); + await clientService.destroy(); + // Should be a noop + await clientService.destroy(); + }); + // TODO: tests? +}); diff --git a/tests/client/authenticationMiddleware.test.ts b/tests/client/authenticationMiddleware.test.ts index 6d94b0db30..73ab8ba647 100644 --- a/tests/client/authenticationMiddleware.test.ts +++ b/tests/client/authenticationMiddleware.test.ts @@ -10,7 +10,6 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger'; import { DB } from '@matrixai/db'; import KeyRing from '@/keys/KeyRing'; import * as keysUtils from '@/keys/utils'; -import RPCServer from '@/rpc/RPCServer'; import TaskManager from '@/tasks/TaskManager'; import CertManager from '@/keys/CertManager'; import RPCClient from '@/rpc/RPCClient'; @@ -20,16 +19,16 @@ import * as authMiddleware from '@/client/utils/authenticationMiddleware'; import { UnaryCaller } from '@/rpc/callers'; import { UnaryHandler } from '@/rpc/handlers'; import * as rpcUtilsMiddleware from '@/rpc/utils/middleware'; -import WebSocketServer from '@/websockets/WebSocketServer'; import WebSocketClient from '@/websockets/WebSocketClient'; +import ClientService from '@/client/ClientService'; import * as testsUtils from '../utils'; describe('authenticationMiddleware', () => { const logger = new Logger('agentUnlock test', LogLevel.WARN, [ new StreamHandler(), ]); - const password = 'helloworld'; - const host = '127.0.0.1'; + const password = 'helloWorld'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; @@ -37,7 +36,7 @@ describe('authenticationMiddleware', () => { let certManager: CertManager; let session: Session; let sessionManager: SessionManager; - let clientServer: WebSocketServer; + let clientService: ClientService; let clientClient: WebSocketClient; let tlsConfig: TLSConfig; @@ -79,7 +78,7 @@ describe('authenticationMiddleware', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await clientServer?.stop(true); + await clientService?.stop({ force: true }); await clientClient?.destroy(true); await certManager.stop(); await taskManager.stop(); @@ -103,27 +102,24 @@ describe('authenticationMiddleware', () => { return input; } } - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { testHandler: new EchoHandler({ logger }), }, - middlewareFactory: rpcUtilsMiddleware.defaultServerMiddlewareWrapper( - authMiddleware.authenticationMiddlewareServer(sessionManager, keyRing), - ), - logger, - }); - clientServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => { - rpcServer.handleStream(streamPair); + options: { + host: localhost, + middlewareFactory: authMiddleware.authenticationMiddlewareServer( + sessionManager, + keyRing, + ), }, - host, - tlsConfig, - logger, + logger: logger.getChild(ClientService.name), }); clientClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, - port: clientServer.getPort(), + host: localhost, + port: clientService.port, logger, }); const rpcClient = await RPCClient.createRPCClient({ diff --git a/tests/client/handlers/agent.test.ts b/tests/client/handlers/agent.test.ts index 00cbb058d4..66c80525a7 100644 --- a/tests/client/handlers/agent.test.ts +++ b/tests/client/handlers/agent.test.ts @@ -7,12 +7,10 @@ import { DB } from '@matrixai/db'; import { running } from '@matrixai/async-init'; import KeyRing from '@/keys/KeyRing'; import * as keysUtils from '@/keys/utils'; -import RPCServer from '@/rpc/RPCServer'; import TaskManager from '@/tasks/TaskManager'; import { AgentLockAllHandler } from '@/client/handlers/agentLockAll'; import RPCClient from '@/rpc/RPCClient'; import { Session, SessionManager } from '@/sessions'; -import WebSocketServer from '@/websockets/WebSocketServer'; import WebSocketClient from '@/websockets/WebSocketClient'; import { agentLockAll, @@ -31,6 +29,7 @@ import CertManager from '@/keys/CertManager'; import * as rpcUtilsMiddleware from '@/rpc/utils/middleware'; import * as clientUtilsAuthMiddleware from '@/client/utils/authenticationMiddleware'; import * as clientUtils from '@/client/utils'; +import ClientService from '@/client/ClientService'; import * as testsUtils from '../../utils'; describe('agentLockAll', () => { @@ -40,14 +39,14 @@ describe('agentLockAll', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let taskManager: TaskManager; let sessionManager: SessionManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; beforeEach(async () => { @@ -77,7 +76,7 @@ describe('agentLockAll', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await taskManager.stop(); await keyRing.stop(); @@ -89,26 +88,24 @@ describe('agentLockAll', () => { }); test('locks all current sessions', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { agentLockAll: new AgentLockAllHandler({ db, sessionManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, + port: clientService.port, logger: logger.getChild('client'), - port: webSocketServer.getPort(), }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -128,11 +125,11 @@ describe('agentStatus', () => { const logger = new Logger('agentStatus test', LogLevel.WARN, [ new StreamHandler(), ]); - const password = 'helloworld'; - const host = '127.0.0.1'; + const password = 'helloWorld'; + const localhost = '127.0.0.1'; let dataDir: string; let pkAgent: PolykeyAgent; - let clientServer: WebSocketServer; + let clientService: ClientService; let clientClient: WebSocketClient; let tlsConfig: TLSConfig; @@ -156,7 +153,7 @@ describe('agentStatus', () => { tlsConfig = await testsUtils.createTLSConfig(pkAgent.keyRing.keyPair); }); afterEach(async () => { - await clientServer?.stop(true); + await clientService?.stop({ force: true }); await clientClient?.destroy(true); await pkAgent.stop(); await fs.promises.rm(dataDir, { @@ -166,26 +163,22 @@ describe('agentStatus', () => { }); test('get status', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { agentStatus: new AgentStatusHandler({ pkAgentProm: Promise.resolve(pkAgent), }), }, - logger: logger.getChild('RPCServer'), - }); - clientServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => { - rpcServer.handleStream(streamPair); + options: { + host: localhost, }, - host, - tlsConfig, - logger, + logger: logger.getChild(ClientService.name), }); clientClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [pkAgent.keyRing.getNodeId()], - host, - port: clientServer.getPort(), + host: localhost, + port: clientService.port, logger, }); const rpcClient = await RPCClient.createRPCClient({ @@ -200,10 +193,10 @@ describe('agentStatus', () => { expect(result).toStrictEqual({ pid: process.pid, nodeIdEncoded: nodesUtils.encodeNodeId(pkAgent.keyRing.getNodeId()), - clientHost: pkAgent.webSocketServerClient.getHost(), - clientPort: pkAgent.webSocketServerClient.getPort(), - agentHost: pkAgent.nodeConnectionManager.host, - agentPort: pkAgent.nodeConnectionManager.port, + clientHost: pkAgent.clientServiceHost, + clientPort: pkAgent.clientServicePort, + agentHost: pkAgent.agentServiceHost, + agentPort: pkAgent.agentServicePort, publicKeyJwk: keysUtils.publicKeyToJWK(pkAgent.keyRing.keyPair.publicKey), certChainPEM: await pkAgent.certManager.getCertPEMsChainPEM(), }); @@ -216,14 +209,14 @@ describe('agentStop', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let nodePath: string; let db: DB; let keyRing: KeyRing; let taskManager: TaskManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let pkAgent: PolykeyAgent; @@ -262,7 +255,7 @@ describe('agentStop', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await taskManager.stop(); await keyRing.stop(); @@ -274,25 +267,23 @@ describe('agentStop', () => { }); test('stops the agent', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { agentStop: new AgentStopHandler({ pkAgentProm: Promise.resolve(pkAgent), }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -324,8 +315,8 @@ describe('agentUnlock', () => { const logger = new Logger('agentUnlock test', LogLevel.WARN, [ new StreamHandler(), ]); - const password = 'helloworld'; - const host = '127.0.0.1'; + const password = 'helloWorld'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; @@ -334,7 +325,7 @@ describe('agentUnlock', () => { let session: Session; let sessionManager: SessionManager; let clientClient: WebSocketClient; - let clientServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; beforeEach(async () => { @@ -375,7 +366,7 @@ describe('agentUnlock', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await clientServer.stop(true); + await clientService?.stop({ force: true }); await clientClient.destroy(true); await certManager.stop(); await taskManager.stop(); @@ -388,29 +379,26 @@ describe('agentUnlock', () => { }); test('unlock', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { agentUnlock: new AgentUnlockHandler({}), }, - middlewareFactory: rpcUtilsMiddleware.defaultServerMiddlewareWrapper( - clientUtilsAuthMiddleware.authenticationMiddlewareServer( - sessionManager, - keyRing, - ), - ), - logger, - }); - clientServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger, + options: { + host: localhost, + middlewareFactory: + clientUtilsAuthMiddleware.authenticationMiddlewareServer( + sessionManager, + keyRing, + ), + }, + logger: logger.getChild(ClientService.name), }); clientClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger, - port: clientServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { diff --git a/tests/client/handlers/gestalts.test.ts b/tests/client/handlers/gestalts.test.ts index 470cd0221d..f4b1c7c4b2 100644 --- a/tests/client/handlers/gestalts.test.ts +++ b/tests/client/handlers/gestalts.test.ts @@ -20,13 +20,11 @@ import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger'; import { DB } from '@matrixai/db'; import KeyRing from '@/keys/KeyRing'; import * as keysUtils from '@/keys/utils'; -import RPCServer from '@/rpc/RPCServer'; import TaskManager from '@/tasks/TaskManager'; import { GestaltsActionsGetByIdentityHandler } from '@/client/handlers/gestaltsActionsGetByIdentity'; import { GestaltsActionsSetByIdentityHandler } from '@/client/handlers/gestaltsActionsSetByIdentity'; import { GestaltsActionsUnsetByIdentityHandler } from '@/client/handlers/gestaltsActionsUnsetByIdentity'; import RPCClient from '@/rpc/RPCClient'; -import WebSocketServer from '@/websockets/WebSocketServer'; import WebSocketClient from '@/websockets/WebSocketClient'; import GestaltGraph from '@/gestalts/GestaltGraph'; import ACL from '@/acl/ACL'; @@ -68,6 +66,7 @@ import * as gestaltUtils from '@/gestalts/utils'; import * as gestaltsErrors from '@/gestalts/errors'; import { sleep } from '@/utils/utils'; import PolykeyAgent from '@/PolykeyAgent'; +import ClientService from '@/client/ClientService'; import * as testsUtils from '../../utils'; import TestProvider from '../../identities/TestProvider'; import * as testUtils from '../../utils/utils'; @@ -87,7 +86,7 @@ describe('gestaltsActionsByIdentity', () => { let keyRing: KeyRing; let taskManager: TaskManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let acl: ACL; let gestaltGraph: GestaltGraph; @@ -123,7 +122,7 @@ describe('gestaltsActionsByIdentity', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await acl.stop(); await gestaltGraph.stop(); @@ -137,7 +136,8 @@ describe('gestaltsActionsByIdentity', () => { }); test('sets/unsets/gets actions by identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsActionsGetByIdentity: new GestaltsActionsGetByIdentityHandler({ db, @@ -153,19 +153,16 @@ describe('gestaltsActionsByIdentity', () => { gestaltGraph, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -242,7 +239,7 @@ describe('gestaltsActionsByNode', () => { let keyRing: KeyRing; let taskManager: TaskManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let acl: ACL; let gestaltGraph: GestaltGraph; @@ -278,7 +275,7 @@ describe('gestaltsActionsByNode', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await acl.stop(); await gestaltGraph.stop(); @@ -292,7 +289,8 @@ describe('gestaltsActionsByNode', () => { }); test('sets/unsets/gets actions by node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsActionsGetByNode: new GestaltsActionsGetByNodeHandler({ db, @@ -307,19 +305,16 @@ describe('gestaltsActionsByNode', () => { gestaltGraph, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -372,7 +367,7 @@ describe('gestaltsDiscoverByIdentity', () => { let keyRing: KeyRing; let taskManager: TaskManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let acl: ACL; let gestaltGraph: GestaltGraph; @@ -476,7 +471,7 @@ describe('gestaltsDiscoverByIdentity', () => { await nodeManager.stop(); await sigchain.stop(); await identitiesManager.stop(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await acl.stop(); await gestaltGraph.stop(); @@ -490,25 +485,23 @@ describe('gestaltsDiscoverByIdentity', () => { }); test('discovers by identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsDiscoveryByIdentity: new GestaltsDiscoveryByIdentityHandler({ discovery, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -548,7 +541,7 @@ describe('gestaltsDiscoverByNode', () => { let keyRing: KeyRing; let taskManager: TaskManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let acl: ACL; let gestaltGraph: GestaltGraph; @@ -650,7 +643,7 @@ describe('gestaltsDiscoverByNode', () => { await nodeManager.stop(); await sigchain.stop(); await identitiesManager.stop(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await acl.stop(); await gestaltGraph.stop(); @@ -664,25 +657,23 @@ describe('gestaltsDiscoverByNode', () => { }); test('discovers by node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsDiscoveryByNode: new GestaltsDiscoveryByNodeHandler({ discovery, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -723,7 +714,7 @@ describe('gestaltsGestaltGetByIdentity', () => { let keyRing: KeyRing; let taskManager: TaskManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let acl: ACL; let gestaltGraph: GestaltGraph; @@ -759,7 +750,7 @@ describe('gestaltsGestaltGetByIdentity', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await acl.stop(); await gestaltGraph.stop(); @@ -773,26 +764,24 @@ describe('gestaltsGestaltGetByIdentity', () => { }); test('gets gestalt by identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltGetByIdentity: new GestaltsGestaltGetByIdentityHandler({ db, gestaltGraph, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -870,7 +859,7 @@ describe('gestaltsGestaltGetByNode', () => { let keyRing: KeyRing; let taskManager: TaskManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let acl: ACL; let gestaltGraph: GestaltGraph; @@ -906,7 +895,7 @@ describe('gestaltsGestaltGetByNode', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await acl.stop(); await gestaltGraph.stop(); @@ -920,26 +909,24 @@ describe('gestaltsGestaltGetByNode', () => { }); test('gets gestalt by node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltGetByNode: new GestaltsGestaltGetByNodeHandler({ db, gestaltGraph, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1015,7 +1002,7 @@ describe('gestaltsGestaltList', () => { let keyRing: KeyRing; let taskManager: TaskManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let acl: ACL; let gestaltGraph: GestaltGraph; @@ -1051,7 +1038,7 @@ describe('gestaltsGestaltList', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await acl.stop(); await gestaltGraph.stop(); @@ -1065,26 +1052,24 @@ describe('gestaltsGestaltList', () => { }); test('lists gestalts', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltList: new GestaltsGestaltListHandler({ db, gestaltGraph, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1155,7 +1140,7 @@ describe('gestaltsGestaltTrustByIdentity', () => { let keyRing: KeyRing; let taskManager: TaskManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let acl: ACL; let gestaltGraph: GestaltGraph; @@ -1280,7 +1265,7 @@ describe('gestaltsGestaltTrustByIdentity', () => { await nodeManager.stop(); await sigchain.stop(); await identitiesManager.stop(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await acl.stop(); await gestaltGraph.stop(); @@ -1294,7 +1279,8 @@ describe('gestaltsGestaltTrustByIdentity', () => { }); test('trusts an identity (already set in gestalt graph)', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltTrustByIdentity: new GestaltsGestaltTrustByIdentityHandler({ @@ -1303,19 +1289,16 @@ describe('gestaltsGestaltTrustByIdentity', () => { discovery, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1356,7 +1339,8 @@ describe('gestaltsGestaltTrustByIdentity', () => { }); test('trusts an identity (new identity)', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltTrustByIdentity: new GestaltsGestaltTrustByIdentityHandler({ @@ -1365,19 +1349,16 @@ describe('gestaltsGestaltTrustByIdentity', () => { discovery, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1415,7 +1396,8 @@ describe('gestaltsGestaltTrustByIdentity', () => { }); test('cannot trust a disconnected identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltTrustByIdentity: new GestaltsGestaltTrustByIdentityHandler({ @@ -1424,19 +1406,16 @@ describe('gestaltsGestaltTrustByIdentity', () => { discovery, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1466,7 +1445,8 @@ describe('gestaltsGestaltTrustByIdentity', () => { }); test('trust extends to entire gestalt', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltTrustByIdentity: new GestaltsGestaltTrustByIdentityHandler({ @@ -1475,19 +1455,16 @@ describe('gestaltsGestaltTrustByIdentity', () => { discovery, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1532,7 +1509,8 @@ describe('gestaltsGestaltTrustByIdentity', () => { }); test('links trusted identity to an existing node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltTrustByIdentity: new GestaltsGestaltTrustByIdentityHandler({ @@ -1541,19 +1519,16 @@ describe('gestaltsGestaltTrustByIdentity', () => { discovery, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1614,7 +1589,7 @@ describe('gestaltsGestaltTrustByNode', () => { let keyRing: KeyRing; let taskManager: TaskManager; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let acl: ACL; let gestaltGraph: GestaltGraph; @@ -1750,8 +1725,8 @@ describe('gestaltsGestaltTrustByNode', () => { await nodeManager.start(); await nodeConnectionManager.start({ host: localhost as Host }); await nodeManager.setNode(nodeIdRemote, { - host: node.nodeConnectionManager.host as Host, - port: node.nodeConnectionManager.port as Port, + host: node.agentServiceHost as Host, + port: node.agentServicePort as Port, }); discovery = await Discovery.createDiscovery({ db, @@ -1773,7 +1748,7 @@ describe('gestaltsGestaltTrustByNode', () => { await nodeManager.stop(); await sigchain.stop(); await identitiesManager.stop(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await acl.stop(); await gestaltGraph.stop(); @@ -1793,7 +1768,8 @@ describe('gestaltsGestaltTrustByNode', () => { }); test('trusts a node (already set in gestalt graph)', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltTrustByNode: new GestaltsGestaltTrustByNodeHandler({ db, @@ -1801,19 +1777,16 @@ describe('gestaltsGestaltTrustByNode', () => { discovery, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1837,7 +1810,8 @@ describe('gestaltsGestaltTrustByNode', () => { }); test('trusts a node (new node)', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltTrustByNode: new GestaltsGestaltTrustByNodeHandler({ db, @@ -1845,19 +1819,16 @@ describe('gestaltsGestaltTrustByNode', () => { discovery, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1880,7 +1851,8 @@ describe('gestaltsGestaltTrustByNode', () => { }); test('trust extends to entire gestalt', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { gestaltsGestaltTrustByNode: new GestaltsGestaltTrustByNodeHandler({ db, @@ -1888,19 +1860,16 @@ describe('gestaltsGestaltTrustByNode', () => { discovery, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { diff --git a/tests/client/handlers/identities.test.ts b/tests/client/handlers/identities.test.ts index d4d3e1a22d..ac033a8c56 100644 --- a/tests/client/handlers/identities.test.ts +++ b/tests/client/handlers/identities.test.ts @@ -2,8 +2,8 @@ import type { TLSConfig } from '@/network/types'; import type { IdentityId, ProviderId } from '@/ids'; import type { ClientRPCResponseResult } from '@/client/types'; import type { - IdentityMessage, IdentityInfoMessage, + IdentityMessage, } from '@/client/handlers/types'; import type { Claim } from '@/claims/types'; import type GestaltGraph from '@/gestalts/GestaltGraph'; @@ -15,13 +15,12 @@ import path from 'path'; import os from 'os'; import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger'; import { DB } from '@matrixai/db'; +import { encodeProviderIdentityId } from '@/ids'; import Sigchain from '@/sigchain/Sigchain'; import KeyRing from '@/keys/KeyRing'; import * as keysUtils from '@/keys/utils'; -import RPCServer from '@/rpc/RPCServer'; import { IdentitiesAuthenticateHandler } from '@/client/handlers/identitiesAuthenticate'; import RPCClient from '@/rpc/RPCClient'; -import WebSocketServer from '@/websockets/WebSocketServer'; import WebSocketClient from '@/websockets/WebSocketClient'; import IdentitiesManager from '@/identities/IdentitiesManager'; import * as validationErrors from '@/validation/errors'; @@ -48,9 +47,9 @@ import { } from '@/client'; import * as claimsUtils from '@/claims/utils'; import * as nodesUtils from '@/nodes/utils'; -import { encodeProviderIdentityId } from '@/ids'; import Token from '@/tokens/Token'; import * as identitiesErrors from '@/identities/errors'; +import ClientService from '@/client/ClientService'; import * as testUtils from '../../utils'; import * as testsUtils from '../../utils'; import TestProvider from '../../identities/TestProvider'; @@ -62,12 +61,12 @@ describe('identitiesAuthenticate', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; let testProvider: TestProvider; @@ -109,7 +108,7 @@ describe('identitiesAuthenticate', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -121,25 +120,23 @@ describe('identitiesAuthenticate', () => { }); test('authenticates identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesAuthenticate: new IdentitiesAuthenticateHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -161,7 +158,7 @@ describe('identitiesAuthenticate', () => { expect(message.response).toBeUndefined(); const authRequest = message.request!; expect(authRequest.url).toBe('test.com'); - expect(authRequest.dataMap['userCode']).toBe('randomtestcode'); + expect(authRequest.dataMap['userCode']).toBe('randomTestCode'); } if (step === 1) { expect(message.request).toBeUndefined(); @@ -185,25 +182,23 @@ describe('identitiesAuthenticate', () => { }); test('cannot authenticate invalid provider', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesAuthenticate: new IdentitiesAuthenticateHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -232,12 +227,12 @@ describe('identitiesAuthenticatedGet', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; const providerToken = { @@ -272,7 +267,7 @@ describe('identitiesAuthenticatedGet', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -284,25 +279,23 @@ describe('identitiesAuthenticatedGet', () => { }); test('gets an authenticated identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesAuthenticatedGet: new IdentitiesAuthenticatedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -336,25 +329,35 @@ describe('identitiesAuthenticatedGet', () => { }); test('does not get an unauthenticated identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesAuthenticatedGet: new IdentitiesAuthenticatedGetHandler({ identitiesManager, }), }, - logger, + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, + clientService = await ClientService.createClientService({ tlsConfig, - logger: logger.getChild('server'), + manifest: { + identitiesAuthenticatedGet: new IdentitiesAuthenticatedGetHandler({ + identitiesManager, + }), + }, + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -388,25 +391,23 @@ describe('identitiesAuthenticatedGet', () => { }); test('gets authenticated identities from multiple providers', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesAuthenticatedGet: new IdentitiesAuthenticatedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -464,25 +465,23 @@ describe('identitiesAuthenticatedGet', () => { }); test('gets authenticated identities a specific provider', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesAuthenticatedGet: new IdentitiesAuthenticatedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -546,12 +545,12 @@ describe('identitiesClaim', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; let mockedAddClaim: jest.SpyInstance; @@ -630,7 +629,7 @@ describe('identitiesClaim', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await sigchain.stop(); @@ -644,25 +643,23 @@ describe('identitiesClaim', () => { }); test('claims identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesClaim: new IdentitiesClaimHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -690,25 +687,23 @@ describe('identitiesClaim', () => { }); test('cannot claim invalid identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesClaim: new IdentitiesClaimHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -750,12 +745,12 @@ describe('identitiesInfoConnectedGet', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; const testToken = { @@ -793,7 +788,7 @@ describe('identitiesInfoConnectedGet', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -805,25 +800,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('gets connected identities from a single provider', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -890,25 +883,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('gets connected identities to a particular identity id', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -972,25 +963,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('gets connected identities from multiple providers', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1062,25 +1051,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('gets connected identities from all providers', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1153,25 +1140,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('searches for identities matching a search term', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1232,25 +1217,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('searches for identities matching multiple search terms', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1318,25 +1301,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('searches for identities matching a search term across multiple providers', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1408,25 +1389,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('gets no connected identities', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1480,25 +1459,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('gets one connected identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1564,25 +1541,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('cannot get more identities than available', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1655,25 +1630,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('can only get from authenticated providers', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1733,25 +1706,23 @@ describe('identitiesInfoConnectedGet', () => { }); test('gets disconnected identities', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoConnectedGet: new IdentitiesInfoConnectedGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1783,12 +1754,12 @@ describe('identitiesInfoGet', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; const testToken = { @@ -1826,7 +1797,7 @@ describe('identitiesInfoGet', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -1838,25 +1809,23 @@ describe('identitiesInfoGet', () => { }); test('gets an identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoGet: new IdentitiesInfoGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1903,25 +1872,23 @@ describe('identitiesInfoGet', () => { }); test('searches for a handle across providers', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoGet: new IdentitiesInfoGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1990,25 +1957,23 @@ describe('identitiesInfoGet', () => { }); test('searches for identities matching a search term', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoGet: new IdentitiesInfoGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -2031,14 +1996,13 @@ describe('identitiesInfoGet', () => { url: 'provider1.com/user1', }; provider1.users['user1'] = user1; - const user2 = { + provider2.users['user1'] = { providerId: provider2.id, identityId: 'user1' as IdentityId, name: 'def', email: 'def@test.com', url: 'provider2.com/user1', }; - provider2.users['user1'] = user2; identitiesManager.registerProvider(provider1); identitiesManager.registerProvider(provider2); await identitiesManager.putToken( @@ -2072,25 +2036,23 @@ describe('identitiesInfoGet', () => { }); test('gets no connected identities', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoGet: new IdentitiesInfoGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -2104,22 +2066,20 @@ describe('identitiesInfoGet', () => { // Setup provider const provider = new TestProvider(); - const user1 = { + provider.users['user1'] = { providerId: provider.id, identityId: 'user1' as IdentityId, name: 'User1', email: 'user1@test.com', url: 'test.com/user1', }; - provider.users['user1'] = user1; - const user2 = { + provider.users['user2'] = { providerId: provider.id, identityId: 'user2' as IdentityId, name: 'User2', email: 'user2@test.com', url: 'test.com/user2', }; - provider.users['user2'] = user2; identitiesManager.registerProvider(provider); await identitiesManager.putToken( provider.id, @@ -2140,25 +2100,23 @@ describe('identitiesInfoGet', () => { }); test('gets one connected identity', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoGet: new IdentitiesInfoGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -2181,14 +2139,13 @@ describe('identitiesInfoGet', () => { url: 'test.com/user1', }; provider1.users['user1'] = user1; - const user2 = { + provider2.users['user1'] = { providerId: provider2.id, identityId: 'user1' as IdentityId, name: 'User1', email: 'user1@test.com', url: 'test.com/user1', }; - provider2.users['user1'] = user2; identitiesManager.registerProvider(provider1); identitiesManager.registerProvider(provider2); await identitiesManager.putToken( @@ -2222,25 +2179,23 @@ describe('identitiesInfoGet', () => { }); test('cannot get more identities than available', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoGet: new IdentitiesInfoGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -2311,25 +2266,23 @@ describe('identitiesInfoGet', () => { }); test('can only get from authenticated providers', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInfoGet: new IdentitiesInfoGetHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -2352,14 +2305,13 @@ describe('identitiesInfoGet', () => { url: 'test.com/user1', }; provider1.users['user1'] = user1; - const user2 = { + provider2.users['user1'] = { providerId: provider2.id, identityId: 'user1' as IdentityId, name: 'User2', email: 'user2@test.com', url: 'test.com/user2', }; - provider2.users['user1'] = user2; identitiesManager.registerProvider(provider1); identitiesManager.registerProvider(provider2); await identitiesManager.putToken( @@ -2393,12 +2345,12 @@ describe('identitiesInvite', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; let mockedAddClaim: jest.SpyInstance; @@ -2477,7 +2429,7 @@ describe('identitiesInvite', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await sigchain.stop(); @@ -2497,7 +2449,8 @@ describe('identitiesInvite', () => { const notificationsManager = { sendNotification: jest.fn(), }; - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesInvite: new IdentitiesInviteHandler({ acl: acl as unknown as ACL, @@ -2506,19 +2459,16 @@ describe('identitiesInvite', () => { logger, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -2546,12 +2496,12 @@ describe('identitiesProvidersList', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; const id1 = 'provider1' as ProviderId; @@ -2592,7 +2542,7 @@ describe('identitiesProvidersList', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -2605,25 +2555,23 @@ describe('identitiesProvidersList', () => { }); test('identitiesProvidersList', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesProvidersList: new IdentitiesProvidersListHandler({ identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -2646,12 +2594,12 @@ describe('identitiesTokenPutDeleteGet', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; const testToken = { @@ -2690,7 +2638,7 @@ describe('identitiesTokenPutDeleteGet', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -2702,7 +2650,8 @@ describe('identitiesTokenPutDeleteGet', () => { }); test('puts/deletes/gets tokens', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { identitiesTokenPut: new IdentitiesTokenPutHandler({ identitiesManager, @@ -2717,19 +2666,16 @@ describe('identitiesTokenPutDeleteGet', () => { identitiesManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { diff --git a/tests/client/handlers/keys.test.ts b/tests/client/handlers/keys.test.ts index d8eab0111a..d13e722fd2 100644 --- a/tests/client/handlers/keys.test.ts +++ b/tests/client/handlers/keys.test.ts @@ -9,10 +9,8 @@ import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger'; import { DB } from '@matrixai/db'; import KeyRing from '@/keys/KeyRing'; import * as keysUtils from '@/keys/utils'; -import RPCServer from '@/rpc/RPCServer'; import { KeysCertsChainGetHandler } from '@/client/handlers/keysCertsChainGet'; import RPCClient from '@/rpc/RPCClient'; -import WebSocketServer from '@/websockets/WebSocketServer'; import WebSocketClient from '@/websockets/WebSocketClient'; import IdentitiesManager from '@/identities/IdentitiesManager'; import CertManager from '@/keys/CertManager'; @@ -43,6 +41,7 @@ import { import PolykeyAgent from '@/PolykeyAgent'; import { NodeManager } from '@/nodes'; import { publicKeyToJWK } from '@/keys/utils'; +import ClientService from '@/client/ClientService'; import * as testsUtils from '../../utils'; describe('keysCertsChainGet', () => { @@ -58,7 +57,7 @@ describe('keysCertsChainGet', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; let taskManager: TaskManager; @@ -109,7 +108,7 @@ describe('keysCertsChainGet', () => { mockedGetRootCertChainPems.mockRestore(); await certManager.stop(); await taskManager.stop(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -121,25 +120,23 @@ describe('keysCertsChainGet', () => { }); test('gets the root certchain', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { keysCertsChainGet: new KeysCertsChainGetHandler({ certManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -170,7 +167,7 @@ describe('keysCertsGet', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; let taskManager: TaskManager; @@ -221,7 +218,7 @@ describe('keysCertsGet', () => { mockedGetRootCertPem.mockRestore(); await certManager.stop(); await taskManager.stop(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -233,25 +230,23 @@ describe('keysCertsGet', () => { }); test('gets the root certificate', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { keysCertsGet: new KeysCertsGetHandler({ certManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -278,7 +273,7 @@ describe('keysEncryptDecrypt', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; @@ -310,7 +305,7 @@ describe('keysEncryptDecrypt', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -322,7 +317,8 @@ describe('keysEncryptDecrypt', () => { }); test('encrypts and decrypts data', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { keysEncrypt: new KeysEncryptHandler({ keyRing, @@ -331,19 +327,16 @@ describe('keysEncryptDecrypt', () => { keyRing, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -377,7 +370,7 @@ describe('keysKeyPair', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; @@ -409,7 +402,7 @@ describe('keysKeyPair', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -421,25 +414,23 @@ describe('keysKeyPair', () => { }); test('gets the keypair', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { keysKeyPair: new KeysKeyPairHandler({ keyRing, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -480,7 +471,7 @@ describe('keysKeyPairRenew', () => { let dataDir: string; let pkAgent: PolykeyAgent; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let mockedRefreshBuckets: jest.SpyInstance; @@ -508,7 +499,7 @@ describe('keysKeyPairRenew', () => { }); afterEach(async () => { mockedRefreshBuckets.mockRestore(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await pkAgent.stop(); await fs.promises.rm(dataDir, { @@ -518,25 +509,23 @@ describe('keysKeyPairRenew', () => { }); test('renews the root key pair', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { keysKeyPairRenew: new KeysKeyPairRenewHandler({ certManager: pkAgent.certManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [pkAgent.keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -565,7 +554,7 @@ describe('keysKeyPairRenew', () => { expect(nodeId1.equals(nodeIdStatus1)).toBe(true); // Run command await rpcClient.methods.keysKeyPairRenew({ - password: 'somepassphrase', + password: 'somePassphrase', }); const rootKeyPair2 = pkAgent.keyRing.keyPair; const nodeId2 = pkAgent.keyRing.getNodeId(); @@ -599,7 +588,7 @@ describe('keysKeyPairReset', () => { const localhost = '127.0.0.1'; let dataDir: string; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let pkAgent: PolykeyAgent; let tlsConfig: TLSConfig; let mockedRefreshBuckets: jest.SpyInstance; @@ -628,7 +617,7 @@ describe('keysKeyPairReset', () => { }); afterEach(async () => { mockedRefreshBuckets.mockRestore(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await pkAgent.stop(); await fs.promises.rm(dataDir, { @@ -638,25 +627,23 @@ describe('keysKeyPairReset', () => { }); test('resets the root key pair', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { keysKeyPairReset: new KeysKeyPairResethandler({ certManager: pkAgent.certManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [pkAgent.keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -685,7 +672,7 @@ describe('keysKeyPairReset', () => { expect(nodeId1.equals(nodeIdStatus1)).toBe(true); // Run command await rpcClient.methods.keysKeyPairReset({ - password: 'somepassphrase', + password: 'somePassphrase', }); const rootKeyPair2 = pkAgent.keyRing.keyPair; const nodeId2 = pkAgent.keyRing.getNodeId(); @@ -721,7 +708,7 @@ describe('keysPasswordChange', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; @@ -753,7 +740,7 @@ describe('keysPasswordChange', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -765,25 +752,23 @@ describe('keysPasswordChange', () => { }); test('changes the password', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { keysPasswordChange: new KeysPasswordChangeHandler({ keyRing, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -795,11 +780,11 @@ describe('keysPasswordChange', () => { // Doing the test await rpcClient.methods.keysPasswordChange({ - password: 'newpassword', + password: 'newPassword', }); await keyRing.stop(); await keyRing.start({ - password: 'newpassword', + password: 'newPassword', }); }); }); @@ -815,7 +800,7 @@ describe('keysPublicKey', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; @@ -847,7 +832,7 @@ describe('keysPublicKey', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -859,25 +844,23 @@ describe('keysPublicKey', () => { }); test('gets the public key', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { keysPublicKey: new KeysPublicKeyHandler({ keyRing, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -911,7 +894,7 @@ describe('keysSignVerify', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let identitiesManager: IdentitiesManager; @@ -943,7 +926,7 @@ describe('keysSignVerify', () => { tlsConfig = await testsUtils.createTLSConfig(keyRing.keyPair); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await identitiesManager.stop(); await keyRing.stop(); @@ -955,7 +938,8 @@ describe('keysSignVerify', () => { }); test('signs and verifies with root keypair', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { keysSign: new KeysSignHandler({ keyRing, @@ -964,19 +948,16 @@ describe('keysSignVerify', () => { keyRing, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host: localhost, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { diff --git a/tests/client/handlers/nodes.test.ts b/tests/client/handlers/nodes.test.ts index df2142b2e9..b2b9360380 100644 --- a/tests/client/handlers/nodes.test.ts +++ b/tests/client/handlers/nodes.test.ts @@ -10,10 +10,8 @@ import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger'; import { DB } from '@matrixai/db'; import KeyRing from '@/keys/KeyRing'; import * as keysUtils from '@/keys/utils'; -import RPCServer from '@/rpc/RPCServer'; import { NodesAddHandler } from '@/client/handlers/nodesAdd'; import RPCClient from '@/rpc/RPCClient'; -import WebSocketServer from '@/websockets/WebSocketServer'; import WebSocketClient from '@/websockets/WebSocketClient'; import * as nodesUtils from '@/nodes/utils'; import NodeManager from '@/nodes/NodeManager'; @@ -33,6 +31,7 @@ import TaskManager from '@/tasks/TaskManager'; import Sigchain from '@/sigchain/Sigchain'; import NotificationsManager from '@/notifications/NotificationsManager'; import ACL from '@/acl/ACL'; +import ClientService from '@/client/ClientService'; import * as tlsTestsUtils from '../../utils/tls'; import * as testsUtils from '../../utils/utils'; @@ -43,12 +42,12 @@ describe('nodesAdd', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1' as Host; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let nodeGraph: NodeGraph; let taskManager: TaskManager; @@ -110,7 +109,7 @@ describe('nodesAdd', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host }); + await nodeConnectionManager.start({ host: localhost as Host }); await taskManager.startProcessing(); }); afterEach(async () => { @@ -122,7 +121,7 @@ describe('nodesAdd', () => { await sigchain.stop(); await db.stop(); await keyRing.stop(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await keyRing.stop(); await db.stop(); @@ -133,26 +132,24 @@ describe('nodesAdd', () => { }); test('adds a node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { nodesAdd: new NodesAddHandler({ db, nodeManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -181,26 +178,24 @@ describe('nodesAdd', () => { }); test('cannot add invalid node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { nodesAdd: new NodesAddHandler({ db, nodeManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -256,7 +251,7 @@ describe('nodesClaim', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1' as Host; + const localhost = '127.0.0.1'; const dummyNotification: Notification = { typ: 'notification', data: { @@ -270,7 +265,7 @@ describe('nodesClaim', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let nodeGraph: NodeGraph; let taskManager: TaskManager; @@ -352,7 +347,7 @@ describe('nodesClaim', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host }); + await nodeConnectionManager.start({ host: localhost as Host }); await taskManager.startProcessing(); notificationsManager = await NotificationsManager.createNotificationsManager({ @@ -370,7 +365,7 @@ describe('nodesClaim', () => { mockedClaimNode.mockRestore(); await taskManager.stopProcessing(); await taskManager.stopTasks(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await nodeConnectionManager.stop(); await nodeManager.stop(); @@ -388,26 +383,24 @@ describe('nodesClaim', () => { }); test('claims a node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { nodesClaim: new NodesClaimHandler({ db, nodeManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -427,26 +420,24 @@ describe('nodesClaim', () => { }); test('cannot claim an invalid node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { nodesClaim: new NodesClaimHandler({ db, nodeManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -472,12 +463,12 @@ describe('nodesFind', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1' as Host; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let nodeGraph: NodeGraph; let taskManager: TaskManager; @@ -489,7 +480,7 @@ describe('nodesFind', () => { mockedFindNode = jest .spyOn(NodeConnectionManager.prototype, 'findNode') .mockResolvedValue({ - host: '127.0.0.1' as Host, + host: localhost as Host, port: 11111 as Port, }); dataDir = await fs.promises.mkdtemp( @@ -534,14 +525,14 @@ describe('nodesFind', () => { connectionIdleTimeoutTime: 2000, logger: logger.getChild('NodeConnectionManager'), }); - await nodeConnectionManager.start({ host }); + await nodeConnectionManager.start({ host: localhost as Host }); await taskManager.startProcessing(); }); afterEach(async () => { mockedFindNode.mockRestore(); await taskManager.stopProcessing(); await taskManager.stopTasks(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await sigchain.stop(); await nodeGraph.stop(); @@ -556,25 +547,23 @@ describe('nodesFind', () => { }); test('finds a node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { nodesFind: new NodesFindHandler({ nodeConnectionManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -594,25 +583,23 @@ describe('nodesFind', () => { }); test('cannot find an invalid node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { nodesFind: new NodesFindHandler({ nodeConnectionManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -638,12 +625,12 @@ describe('nodesPing', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1' as Host; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let nodeGraph: NodeGraph; let taskManager: TaskManager; @@ -706,14 +693,14 @@ describe('nodesPing', () => { gestaltGraph: {} as GestaltGraph, logger, }); - await nodeConnectionManager.start({ host }); + await nodeConnectionManager.start({ host: localhost as Host }); await taskManager.startProcessing(); }); afterEach(async () => { mockedPingNode.mockRestore(); await taskManager.stopProcessing(); await taskManager.stopTasks(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await sigchain.stop(); await nodeGraph.stop(); @@ -728,25 +715,23 @@ describe('nodesPing', () => { }); test('pings a node (offline)', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { nodesPing: new NodesPingHandler({ nodeManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -766,25 +751,23 @@ describe('nodesPing', () => { }); test('pings a node (online)', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { nodesPing: new NodesPingHandler({ nodeManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -804,25 +787,23 @@ describe('nodesPing', () => { }); test('cannot ping an invalid node', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { nodesPing: new NodesPingHandler({ nodeManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { diff --git a/tests/client/handlers/notifications.test.ts b/tests/client/handlers/notifications.test.ts index 069bb110c1..1c204101c5 100644 --- a/tests/client/handlers/notifications.test.ts +++ b/tests/client/handlers/notifications.test.ts @@ -11,10 +11,8 @@ import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger'; import { DB } from '@matrixai/db'; import KeyRing from '@/keys/KeyRing'; import * as keysUtils from '@/keys/utils'; -import RPCServer from '@/rpc/RPCServer'; import { NotificationsClearHandler } from '@/client/handlers/notificationsClear'; import RPCClient from '@/rpc/RPCClient'; -import WebSocketServer from '@/websockets/WebSocketServer'; import WebSocketClient from '@/websockets/WebSocketClient'; import { notificationsClear, @@ -31,6 +29,7 @@ import TaskManager from '@/tasks/TaskManager'; import NodeConnectionManager from '@/nodes/NodeConnectionManager'; import NodeManager from '@/nodes/NodeManager'; import NotificationsManager from '@/notifications/NotificationsManager'; +import ClientService from '@/client/ClientService'; import * as tlsTestsUtils from '../../utils/tls'; import * as testNodesUtils from '../../nodes/utils'; @@ -41,12 +40,12 @@ describe('notificationsClear', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1' as Host; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let nodeGraph: NodeGraph; let taskManager: TaskManager; @@ -118,7 +117,7 @@ describe('notificationsClear', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host }); + await nodeConnectionManager.start({ host: localhost as Host }); await taskManager.startProcessing(); notificationsManager = await NotificationsManager.createNotificationsManager({ @@ -140,7 +139,7 @@ describe('notificationsClear', () => { await nodeManager.stop(); await nodeConnectionManager.stop(); await nodeGraph.stop(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await taskManager.stop(); await keyRing.stop(); @@ -151,26 +150,24 @@ describe('notificationsClear', () => { }); test('puts/deletes/gets tokens', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { notificationsClear: new NotificationsClearHandler({ db, notificationsManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -192,7 +189,7 @@ describe('notificationsRead', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1' as Host; + const localhost = '127.0.0.1'; const nodeIdSender = testNodesUtils.generateRandomNodeId(); const nodeIdSenderEncoded = nodesUtils.encodeNodeId(nodeIdSender); const nodeIdReceiverEncoded = 'test'; @@ -200,7 +197,7 @@ describe('notificationsRead', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let nodeGraph: NodeGraph; let taskManager: TaskManager; @@ -273,7 +270,7 @@ describe('notificationsRead', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host }); + await nodeConnectionManager.start({ host: localhost as Host }); await taskManager.start(); notificationsManager = await NotificationsManager.createNotificationsManager({ @@ -289,7 +286,7 @@ describe('notificationsRead', () => { mockedReadNotifications.mockRestore(); await taskManager.stopProcessing(); await taskManager.stopTasks(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await notificationsManager.stop(); await sigchain.stop(); @@ -307,26 +304,24 @@ describe('notificationsRead', () => { }); test('reads a single notification', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { notificationsRead: new NotificationsReadHandler({ db, notificationsManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -373,26 +368,24 @@ describe('notificationsRead', () => { }); test('reads unread notifications', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { notificationsRead: new NotificationsReadHandler({ db, notificationsManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -456,26 +449,24 @@ describe('notificationsRead', () => { }); test('reads notifications in reverse order', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { notificationsRead: new NotificationsReadHandler({ db, notificationsManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -539,26 +530,24 @@ describe('notificationsRead', () => { }); test('reads gestalt invite notifications', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { notificationsRead: new NotificationsReadHandler({ db, notificationsManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -602,26 +591,24 @@ describe('notificationsRead', () => { }); test('reads vault share notifications', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { notificationsRead: new NotificationsReadHandler({ db, notificationsManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -678,26 +665,24 @@ describe('notificationsRead', () => { }); test('reads no notifications', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { notificationsRead: new NotificationsReadHandler({ db, notificationsManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -732,12 +717,12 @@ describe('notificationsSend', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1' as Host; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let nodeGraph: NodeGraph; let taskManager: TaskManager; @@ -809,7 +794,7 @@ describe('notificationsSend', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host }); + await nodeConnectionManager.start({ host: localhost as Host }); await taskManager.start(); notificationsManager = await NotificationsManager.createNotificationsManager({ @@ -825,7 +810,7 @@ describe('notificationsSend', () => { mockedSendNotification.mockRestore(); await taskManager.stopProcessing(); await taskManager.stopTasks(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await notificationsManager.stop(); await sigchain.stop(); @@ -843,25 +828,23 @@ describe('notificationsSend', () => { }); test('sends a notification', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { notificationsSend: new NotificationsSendHandler({ notificationsManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { diff --git a/tests/client/handlers/vaults.test.ts b/tests/client/handlers/vaults.test.ts index bdecb01f6b..8d641cd2e0 100644 --- a/tests/client/handlers/vaults.test.ts +++ b/tests/client/handlers/vaults.test.ts @@ -17,11 +17,9 @@ import VaultManager from '@/vaults/VaultManager'; import KeyRing from '@/keys/KeyRing'; import * as keysUtils from '@/keys/utils'; import GestaltGraph from '@/gestalts/GestaltGraph'; -import WebSocketServer from '@/websockets/WebSocketServer'; import WebSocketClient from '@/websockets/WebSocketClient'; import NotificationsManager from '@/notifications/NotificationsManager'; import ACL from '@/acl/ACL'; -import RPCServer from '@/rpc/RPCServer'; import RPCClient from '@/rpc/RPCClient'; import { vaultsCreate, @@ -61,6 +59,7 @@ import { vaultsVersion, VaultsVersionHandler, } from '@/client'; +import ClientService from '@/client/ClientService'; import * as nodesUtils from '@/nodes/utils'; import * as vaultsUtils from '@/vaults/utils'; import * as vaultsErrors from '@/vaults/errors'; @@ -78,7 +77,7 @@ describe('vaultsClone', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; // Let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -114,7 +113,7 @@ describe('vaultsClone', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -167,12 +166,12 @@ describe('vaultsCreateDeleteList', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -208,7 +207,7 @@ describe('vaultsCreateDeleteList', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -220,7 +219,8 @@ describe('vaultsCreateDeleteList', () => { }); test('creates, lists, and deletes vaults', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsCreate: new VaultsCreateHandler({ vaultManager, @@ -235,19 +235,16 @@ describe('vaultsCreateDeleteList', () => { db, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -294,12 +291,12 @@ describe('vaultsLog', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -358,7 +355,7 @@ describe('vaultsLog', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -370,26 +367,24 @@ describe('vaultsLog', () => { }); test('should get the full log', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsLog: new VaultsLogHandler({ vaultManager, db, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -414,26 +409,24 @@ describe('vaultsLog', () => { }); test('should get a part of the log', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsLog: new VaultsLogHandler({ vaultManager, db, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -458,26 +451,24 @@ describe('vaultsLog', () => { }); test('should get a specific commit', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsLog: new VaultsLogHandler({ vaultManager, db, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -507,13 +498,13 @@ describe('vaultsPermissionSetUnsetGet', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; const nodeId = testsUtils.generateRandomNodeId(); let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; let acl: ACL; @@ -578,7 +569,7 @@ describe('vaultsPermissionSetUnsetGet', () => { }); afterEach(async () => { mockedSendNotification.mockRestore(); - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await notificationsManager.stop(); @@ -593,7 +584,8 @@ describe('vaultsPermissionSetUnsetGet', () => { }); test('sets, gets, and unsets vault permissions', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsPermissionSet: new VaultsPermissionSetHandler({ acl, @@ -614,19 +606,16 @@ describe('vaultsPermissionSetUnsetGet', () => { vaultManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -697,7 +686,7 @@ describe('vaultsPull', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; // Let tlsConfig: TLSConfig; let vaultManager: VaultManager; let acl: ACL; @@ -757,7 +746,7 @@ describe('vaultsPull', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await notificationsManager.stop(); @@ -829,12 +818,12 @@ describe('vaultsRename', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -870,7 +859,7 @@ describe('vaultsRename', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -882,26 +871,24 @@ describe('vaultsRename', () => { }); test('should rename vault', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsRename: new VaultsRenameHandler({ db, vaultManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -935,7 +922,7 @@ describe('vaultsScan', () => { let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; // Let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -971,7 +958,7 @@ describe('vaultsScan', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -1035,12 +1022,12 @@ describe('vaultsSecretsEdit', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -1076,7 +1063,7 @@ describe('vaultsSecretsEdit', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -1088,26 +1075,24 @@ describe('vaultsSecretsEdit', () => { }); test('edits secrets', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsSecretsEdit: new VaultsSecretsEditHandler({ db, vaultManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1148,12 +1133,12 @@ describe('vaultsSecretsMkdir', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -1189,7 +1174,7 @@ describe('vaultsSecretsMkdir', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -1201,26 +1186,24 @@ describe('vaultsSecretsMkdir', () => { }); test('makes a directory', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsSecretsMkdir: new VaultsSecretsMkdirHandler({ db, vaultManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1255,12 +1238,12 @@ describe('vaultsSecretsNewDeleteGet', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -1296,7 +1279,7 @@ describe('vaultsSecretsNewDeleteGet', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -1308,7 +1291,8 @@ describe('vaultsSecretsNewDeleteGet', () => { }); test('creates, gets, and deletes secrets', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsSecretsNew: new VaultsSecretsNewHandler({ db, @@ -1323,19 +1307,16 @@ describe('vaultsSecretsNewDeleteGet', () => { vaultManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1388,13 +1369,13 @@ describe('vaultsSecretsNewDirList', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; const fs: FileSystem = require('fs'); let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -1430,7 +1411,7 @@ describe('vaultsSecretsNewDirList', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -1442,7 +1423,8 @@ describe('vaultsSecretsNewDirList', () => { }); test('adds and lists a directory of secrets', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsSecretsNewDir: new VaultsSecretsNewDirHandler({ db, @@ -1454,19 +1436,16 @@ describe('vaultsSecretsNewDirList', () => { vaultManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1515,13 +1494,13 @@ describe('vaultsSecretsRename', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; const fs: FileSystem = require('fs'); let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -1557,7 +1536,7 @@ describe('vaultsSecretsRename', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -1569,26 +1548,24 @@ describe('vaultsSecretsRename', () => { }); test('renames a secret', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsSecretsRename: new VaultsSecretsRenameHandler({ db, vaultManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1629,13 +1606,13 @@ describe('vaultsSecretsStat', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; const fs: FileSystem = require('fs'); let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; @@ -1671,7 +1648,7 @@ describe('vaultsSecretsStat', () => { }); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -1683,26 +1660,24 @@ describe('vaultsSecretsStat', () => { }); test('stats a file', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsSecretsStat: new VaultsSecretsStatHandler({ db, vaultManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1738,13 +1713,13 @@ describe('vaultsVersion', () => { ), ]); const password = 'helloWorld'; - const host = '127.0.0.1'; + const localhost = '127.0.0.1'; const fs: FileSystem = require('fs'); let dataDir: string; let db: DB; let keyRing: KeyRing; let webSocketClient: WebSocketClient; - let webSocketServer: WebSocketServer; + let clientService: ClientService; let tlsConfig: TLSConfig; let vaultManager: VaultManager; let vaultId: VaultId; @@ -1791,7 +1766,7 @@ describe('vaultsVersion', () => { vaultId = await vaultManager.createVault(vaultName); }); afterEach(async () => { - await webSocketServer.stop(true); + await clientService?.stop({ force: true }); await webSocketClient.destroy(true); await vaultManager.stop(); await db.stop(); @@ -1803,26 +1778,24 @@ describe('vaultsVersion', () => { }); test('should switch a vault to a version', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsVersion: new VaultsVersionHandler({ db, vaultManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { @@ -1861,26 +1834,24 @@ describe('vaultsVersion', () => { }); test('should fail to find a non existent version', async () => { // Setup - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { vaultsVersion: new VaultsVersionHandler({ db, vaultManager, }), }, - logger, - }); - webSocketServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => rpcServer.handleStream(streamPair), - host, - tlsConfig, - logger: logger.getChild('server'), + options: { + host: localhost, + }, + logger: logger.getChild(ClientService.name), }); webSocketClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, + host: localhost, logger: logger.getChild('client'), - port: webSocketServer.getPort(), + port: clientService.port, }); const rpcClient = await RPCClient.createRPCClient({ manifest: { diff --git a/tests/client/timeoutMiddleware.test.ts b/tests/client/timeoutMiddleware.test.ts index 995d74ec2e..a9e9d616af 100644 --- a/tests/client/timeoutMiddleware.test.ts +++ b/tests/client/timeoutMiddleware.test.ts @@ -12,7 +12,6 @@ import { DB } from '@matrixai/db'; import { Timer } from '@matrixai/timer'; import KeyRing from '@/keys/KeyRing'; import * as keysUtils from '@/keys/utils'; -import RPCServer from '@/rpc/RPCServer'; import TaskManager from '@/tasks/TaskManager'; import CertManager from '@/keys/CertManager'; import RPCClient from '@/rpc/RPCClient'; @@ -20,23 +19,23 @@ import * as timeoutMiddleware from '@/client/utils/timeoutMiddleware'; import { UnaryCaller } from '@/rpc/callers'; import { UnaryHandler } from '@/rpc/handlers'; import * as rpcUtilsMiddleware from '@/rpc/utils/middleware'; -import WebSocketServer from '@/websockets/WebSocketServer'; import WebSocketClient from '@/websockets/WebSocketClient'; import { promise } from '@/utils'; +import ClientService from '@/client/ClientService'; import * as testsUtils from '../utils'; describe('timeoutMiddleware', () => { const logger = new Logger('agentUnlock test', LogLevel.WARN, [ new StreamHandler(), ]); - const password = 'helloworld'; - const host = '127.0.0.1'; + const password = 'helloWorld'; + const localhost = '127.0.0.1'; let dataDir: string; let db: DB; let keyRing: KeyRing; let taskManager: TaskManager; let certManager: CertManager; - let clientServer: WebSocketServer; + let clientService: ClientService; let clientClient: WebSocketClient; let tlsConfig: TLSConfig; @@ -70,7 +69,7 @@ describe('timeoutMiddleware', () => { afterEach(async () => { await taskManager.stopProcessing(); await taskManager.stopTasks(); - await clientServer?.stop(true); + await clientService?.stop({ force: true }); await clientClient?.destroy(true); await certManager.stop(); await taskManager.stop(); @@ -99,27 +98,21 @@ describe('timeoutMiddleware', () => { return input; } } - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { testHandler: new EchoHandler({ logger }), }, - middlewareFactory: rpcUtilsMiddleware.defaultServerMiddlewareWrapper( - timeoutMiddleware.timeoutMiddlewareServer, - ), - logger, - }); - clientServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => { - rpcServer.handleStream(streamPair); + options: { + host: localhost, + middlewareFactory: timeoutMiddleware.timeoutMiddlewareServer, }, - host, - tlsConfig, - logger, + logger: logger.getChild(ClientService.name), }); clientClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, - port: clientServer.getPort(), + host: localhost, + port: clientService.port, logger, }); const rpcClient = await RPCClient.createRPCClient({ @@ -149,7 +142,7 @@ describe('timeoutMiddleware', () => { () => {}, () => {}, ); - await rpcServer.destroy(true); + await clientService.destroy({ force: true }); await rpcClient.destroy(); }); test('client side timeout updates', async () => { @@ -166,28 +159,22 @@ describe('timeoutMiddleware', () => { return input; } } - const rpcServer = await RPCServer.createRPCServer({ + clientService = await ClientService.createClientService({ + tlsConfig, manifest: { testHandler: new EchoHandler({ logger }), }, - middlewareFactory: rpcUtilsMiddleware.defaultServerMiddlewareWrapper( - timeoutMiddleware.timeoutMiddlewareServer, - ), - handlerTimeoutTime: 100, - logger, - }); - clientServer = await WebSocketServer.createWebSocketServer({ - connectionCallback: (streamPair) => { - rpcServer.handleStream(streamPair); + options: { + host: localhost, + middlewareFactory: timeoutMiddleware.timeoutMiddlewareServer, + rpcCallTimeoutTime: 100, }, - host, - tlsConfig, - logger, + logger: logger.getChild(ClientService.name), }); clientClient = await WebSocketClient.createWebSocketClient({ expectedNodeIds: [keyRing.getNodeId()], - host, - port: clientServer.getPort(), + host: localhost, + port: clientService.port, logger, }); const rpcClient = await RPCClient.createRPCClient({ diff --git a/tests/discovery/Discovery.test.ts b/tests/discovery/Discovery.test.ts index 094e40e30d..e80734fcc7 100644 --- a/tests/discovery/Discovery.test.ts +++ b/tests/discovery/Discovery.test.ts @@ -207,8 +207,8 @@ describe('Discovery', () => { nodeIdB = nodeB.keyRing.getNodeId(); await testNodesUtils.nodesConnect(nodeA, nodeB); await nodeGraph.setNode(nodeA.keyRing.getNodeId(), { - host: nodeA.nodeConnectionManager.host as Host, - port: nodeA.nodeConnectionManager.port as Port, + host: nodeA.agentServiceHost as Host, + port: nodeA.agentServicePort as Port, }); await nodeB.acl.setNodeAction(nodeA.keyRing.getNodeId(), 'claim'); await nodeA.nodeManager.claimNode(nodeB.keyRing.getNodeId()); diff --git a/tests/nodes/NodeConnectionManager.general.test.ts b/tests/nodes/NodeConnectionManager.general.test.ts index d980e5f154..b139a8b116 100644 --- a/tests/nodes/NodeConnectionManager.general.test.ts +++ b/tests/nodes/NodeConnectionManager.general.test.ts @@ -155,8 +155,8 @@ describe(`${NodeConnectionManager.name} general test`, () => { logger, }); serverAddress = { - host: remotePolykeyAgent.nodeConnectionManager.host as Host, - port: remotePolykeyAgent.nodeConnectionManager.port as Port, + host: remotePolykeyAgent.agentServiceHost as Host, + port: remotePolykeyAgent.agentServicePort as Port, }; }); diff --git a/tests/nodes/NodeConnectionManager.seednodes.test.ts b/tests/nodes/NodeConnectionManager.seednodes.test.ts index b821d0c469..b0a52dd6ff 100644 --- a/tests/nodes/NodeConnectionManager.seednodes.test.ts +++ b/tests/nodes/NodeConnectionManager.seednodes.test.ts @@ -85,8 +85,8 @@ describe(`${NodeConnectionManager.name} seednodes test`, () => { remoteNodeId1 = remotePolykeyAgent1.keyRing.getNodeId(); remoteNodeIdEncoded1 = nodesUtils.encodeNodeId(remoteNodeId1); remoteAddress1 = { - host: remotePolykeyAgent1.nodeConnectionManager.host as Host, - port: remotePolykeyAgent1.nodeConnectionManager.port as Port, + host: remotePolykeyAgent1.agentServiceHost as Host, + port: remotePolykeyAgent1.agentServicePort as Port, }; const nodePathB = path.join(dataDir, 'agentB'); @@ -106,8 +106,8 @@ describe(`${NodeConnectionManager.name} seednodes test`, () => { }); remoteNodeId2 = remotePolykeyAgent2.keyRing.getNodeId(); remoteAddress2 = { - host: remotePolykeyAgent2.nodeConnectionManager.host as Host, - port: remotePolykeyAgent2.nodeConnectionManager.port as Port, + host: remotePolykeyAgent2.agentServiceHost as Host, + port: remotePolykeyAgent2.agentServicePort as Port, }; // Setting up client dependencies diff --git a/tests/nodes/NodeConnectionManager.timeout.test.ts b/tests/nodes/NodeConnectionManager.timeout.test.ts index e739ef3dfb..5d58020b69 100644 --- a/tests/nodes/NodeConnectionManager.timeout.test.ts +++ b/tests/nodes/NodeConnectionManager.timeout.test.ts @@ -75,8 +75,8 @@ describe(`${NodeConnectionManager.name} timeout test`, () => { }); remoteNodeId1 = remotePolykeyAgent1.keyRing.getNodeId(); remoteAddress1 = { - host: remotePolykeyAgent1.nodeConnectionManager.host as Host, - port: remotePolykeyAgent1.nodeConnectionManager.port as Port, + host: remotePolykeyAgent1.agentServiceHost as Host, + port: remotePolykeyAgent1.agentServicePort as Port, }; // Setting up client dependencies diff --git a/tests/nodes/NodeManager.test.ts b/tests/nodes/NodeManager.test.ts index 37b9e3ba16..041fdfa3fb 100644 --- a/tests/nodes/NodeManager.test.ts +++ b/tests/nodes/NodeManager.test.ts @@ -358,8 +358,8 @@ describe(`${NodeManager.name} test`, () => { }); const serverNodeId = server.keyRing.getNodeId(); const serverNodeAddress: NodeAddress = { - host: server.nodeConnectionManager.host as Host, - port: server.nodeConnectionManager.port as Port, + host: server.agentServiceHost as Host, + port: server.agentServicePort as Port, }; await nodeGraph.setNode(serverNodeId, serverNodeAddress); diff --git a/tests/notifications/NotificationsManager.test.ts b/tests/notifications/NotificationsManager.test.ts index 8e12c2551e..03385ee937 100644 --- a/tests/notifications/NotificationsManager.test.ts +++ b/tests/notifications/NotificationsManager.test.ts @@ -146,8 +146,8 @@ describe('NotificationsManager', () => { logger, }); await nodeGraph.setNode(receiver.keyRing.getNodeId(), { - host: receiver.nodeConnectionManager.host as Host, - port: receiver.nodeConnectionManager.port as Port, + host: receiver.agentServiceHost as Host, + port: receiver.agentServicePort as Port, }); }, globalThis.defaultTimeout); afterEach(async () => { diff --git a/tests/vaults/VaultManager.test.ts b/tests/vaults/VaultManager.test.ts index f4a5ddb174..35d170719f 100644 --- a/tests/vaults/VaultManager.test.ts +++ b/tests/vaults/VaultManager.test.ts @@ -515,12 +515,12 @@ describe('VaultManager', () => { // Adding details to each agent await remoteKeynode1.nodeGraph.setNode(remoteKeynode2Id, { - host: remoteKeynode2.nodeConnectionManager.host as Host, - port: remoteKeynode2.nodeConnectionManager.port as Port, + host: remoteKeynode2.agentServiceHost as Host, + port: remoteKeynode2.agentServicePort as Port, }); await remoteKeynode2.nodeGraph.setNode(remoteKeynode1Id, { - host: remoteKeynode1.nodeConnectionManager.host as Host, - port: remoteKeynode1.nodeConnectionManager.port as Port, + host: remoteKeynode1.agentServiceHost as Host, + port: remoteKeynode1.agentServicePort as Port, }); await remoteKeynode1.gestaltGraph.setNode({ @@ -577,12 +577,12 @@ describe('VaultManager', () => { await nodeConnectionManager.start({ host: localhost as Host }); await taskManager.startProcessing(); await nodeGraph.setNode(remoteKeynode1Id, { - host: remoteKeynode1.nodeConnectionManager.host as Host, - port: remoteKeynode1.nodeConnectionManager.port as Port, + host: remoteKeynode1.agentServiceHost as Host, + port: remoteKeynode1.agentServicePort as Port, }); await nodeGraph.setNode(remoteKeynode2Id, { - host: remoteKeynode2.nodeConnectionManager.host as Host, - port: remoteKeynode2.nodeConnectionManager.port as Port, + host: remoteKeynode2.agentServiceHost as Host, + port: remoteKeynode2.agentServicePort as Port, }); }); afterEach(async () => { @@ -1382,8 +1382,8 @@ describe('VaultManager', () => { // Letting nodeGraph know where the remote agent is await nodeGraph.setNode(targetNodeId, { - host: remoteKeynode1.nodeConnectionManager.host as Host, - port: remoteKeynode1.nodeConnectionManager.port as Port, + host: remoteKeynode1.agentServiceHost as Host, + port: remoteKeynode1.agentServicePort as Port, }); await remoteKeynode1.gestaltGraph.setNode({