Skip to content

Commit

Permalink
revert: package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
amydevs authored and addievo committed Oct 17, 2023
1 parent 93cdef8 commit 56c3139
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
21 changes: 18 additions & 3 deletions src/PolykeyClient.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { FileSystem } from './types';
import type { StreamFactory } from '@matrixai/rpc';
import type { WebSocketConfig } from '@matrixai/ws/dist/types';
import path from 'path';
import Logger from '@matrixai/logger';
import { CreateDestroyStartStop } from '@matrixai/async-init/dist/CreateDestroyStartStop';
import { RPCClient } from '@matrixai/rpc';
import { middleware as rpcMiddleware } from '@matrixai/rpc';
import { WebSocketClient } from '@matrixai/ws';
import * as clientMiddleware from './client/middleware';
import { Session } from './sessions';
import * as utils from './utils';
Expand Down Expand Up @@ -35,15 +37,19 @@ interface PolykeyClient extends CreateDestroyStartStop {}
class PolykeyClient {
static async createPolykeyClient({
nodePath = config.defaultsUser.nodePath,
streamFactory,
wsPort,
wsHost,
wsConfig,
streamKeepAliveTimeoutTime,
parserBufferByteLimit,
fs = require('fs'),
logger = new Logger(this.name),
fresh = false,
}: {
nodePath?: string;
streamFactory: StreamFactory;
wsPort: number;
wsHost: string;
wsConfig?: Partial<WebSocketConfig>;
streamKeepAliveTimeoutTime?: number;
parserBufferByteLimit?: number;
fs?: FileSystem;
Expand All @@ -61,9 +67,15 @@ class PolykeyClient {
logger: logger.getChild(Session.name),
fresh,
});
const ws = await WebSocketClient.createWebSocketClient({
host: wsHost,
port: wsPort,
config: wsConfig,
logger: logger.getChild('WebSocketClient'),
});
const rpcClientClient = new RPCClient({
manifest: clientClientManifest,
streamFactory,
streamFactory: () => ws.connection.newStream(),
middlewareFactory: rpcMiddleware.defaultClientMiddlewareWrapper(
clientMiddleware.middlewareClient(session),
parserBufferByteLimit,
Expand All @@ -79,6 +91,7 @@ class PolykeyClient {
fs,
logger,
});
pkClient.ws = ws;
await pkClient.start();
logger.info(`Created ${this.name}`);
return pkClient;
Expand All @@ -88,6 +101,7 @@ class PolykeyClient {
public readonly session: Session;
public readonly rpcClientClient: RPCClient<typeof clientClientManifest>;

protected ws: WebSocketClient;
protected fs: FileSystem;
protected logger: Logger;

Expand Down Expand Up @@ -124,6 +138,7 @@ class PolykeyClient {

public async destroy() {
this.logger.info(`Destroying ${this.constructor.name}`);
await this.ws.destroy({ force: true });
await this.session.destroy();
this.logger.info(`Destroyed ${this.constructor.name}`);
}
Expand Down
6 changes: 3 additions & 3 deletions src/identities/providers/github/GitHubProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class GitHubProvider extends Provider {
protected logger: Logger;

public constructor({
clientId,
logger,
}: {
clientId,
logger,
}: {
clientId: string;
logger?: Logger;
}) {
Expand Down
41 changes: 17 additions & 24 deletions tests/PolykeyClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,14 @@ describe('PolykeyClient', () => {
});
await session.writeToken('dummy' as SessionToken);
// Using fresh: true means that any token would be destroyed
const webSocketClient = await WebSocketClient.createWebSocketClient({
config: {
verifyPeer: false,
},
host: pkAgent.clientServiceHost,
port: pkAgent.clientServicePort,
logger,
});
const wsconfig = {
verifyPeer: false,
};
const pkClient = await PolykeyClient.createPolykeyClient({
streamFactory: () => webSocketClient.connection.newStream(),
nodePath,
wsHost: pkAgent.clientServiceHost,
wsPort: pkAgent.clientServicePort,
wsConfig: wsconfig,
fs,
logger,
fresh: true,
Expand All @@ -77,26 +74,22 @@ describe('PolykeyClient', () => {
expect(await session.readToken()).toBeDefined();
await pkClient.destroy();
expect(await session.readToken()).toBeUndefined();
await webSocketClient.destroy({ force: true });
});
test('end to end with authentication logic', async () => {
const webSocketClient = await WebSocketClient.createWebSocketClient({
config: {
verifyPeer: true,
verifyCallback: async (certs) => {
await clientUtils.verifyServerCertificateChain(
[pkAgent.keyRing.getNodeId()],
certs,
);
},
const wsconfig = {
verifyPeer: true,
verifyCallback: async (certs) => {
await clientUtils.verifyServerCertificateChain(
[pkAgent.keyRing.getNodeId()],
certs,
);
},
host: pkAgent.clientServiceHost,
port: pkAgent.clientServicePort,
logger: logger.getChild(WebSocketClient.name),
});
};
const pkClient = await PolykeyClient.createPolykeyClient({
streamFactory: () => webSocketClient.connection.newStream(),
nodePath,
wsPort: pkAgent.clientServicePort,
wsHost: pkAgent.clientServiceHost,
wsConfig: wsconfig,
fs,
logger: logger.getChild(PolykeyClient.name),
fresh: true,
Expand Down

0 comments on commit 56c3139

Please sign in to comment.