Skip to content

Commit

Permalink
tests: fixing up tests
Browse files Browse the repository at this point in the history
* Related #527

[ci skip]
  • Loading branch information
tegefaulkes committed Aug 18, 2023
1 parent 8f70698 commit 7c3fb75
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 149 deletions.
19 changes: 6 additions & 13 deletions src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ class PolykeyAgent {
keyRingConfig = {},
certManagerConfig = {},
networkConfig = {},
quicServerConfig = {},
quicClientConfig = {},
quicConfig = {},
nodeConnectionManagerConfig = {},
seedNodes = {},
workers,
Expand Down Expand Up @@ -149,8 +148,7 @@ class PolykeyAgent {
connectionHolePunchIntervalTime?: number;
};
networkConfig?: NetworkConfig;
quicServerConfig?: PolykeyQUICConfig;
quicClientConfig?: PolykeyQUICConfig;
quicConfig?: PolykeyQUICConfig;
seedNodes?: SeedNodes;
workers?: number;
status?: Status;
Expand Down Expand Up @@ -198,14 +196,9 @@ class PolykeyAgent {
...config.defaults.networkConfig,
...utils.filterEmptyObject(networkConfig),
};
const quicServerConfig_ = {
...config.defaults.quicServerConfig,
...utils.filterEmptyObject(quicServerConfig),
};
// TODO: rename
const quicClientConfig_ = {
...config.defaults.quicClientConfig,
...utils.filterEmptyObject(quicClientConfig),
const quicConfig_ = {
...config.defaults.quicConfig,
...utils.filterEmptyObject(quicConfig),
};
await utils.mkdirExists(fs, nodePath);
const statusPath = path.join(nodePath, config.defaults.statusBase);
Expand Down Expand Up @@ -401,7 +394,7 @@ class PolykeyAgent {
nodeGraph,
seedNodes,
quicSocket,
quicConfig: quicClientConfig_,
quicConfig: quicConfig_,
...nodeConnectionManagerConfig_,
tlsConfig,
crypto,
Expand Down
18 changes: 4 additions & 14 deletions src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Sigchain } from '../sigchain';
import { ACL } from '../acl';
import { GestaltGraph } from '../gestalts';
import { KeyRing } from '../keys';
import { NodeConnectionManager, NodeGraph, NodeManager } from '../nodes';
import { NodeGraph, NodeManager } from '../nodes';
import { VaultManager } from '../vaults';
import { NotificationsManager } from '../notifications';
import { mkdirExists } from '../utils';
Expand Down Expand Up @@ -153,21 +153,11 @@ async function bootstrapState({
logger,
lazy: true,
});
const nodeConnectionManager = new NodeConnectionManager({

This comment has been minimized.

Copy link
@CMCDragonkai

CMCDragonkai Oct 4, 2023

Member

This removed the nodeConnectionManager from the bootstrapState function.

Primarily because no connections is actually being made.

However there is downstream domains that depend on the NCM, before they end up creating their state. Here you are hacking it so that {} as any just satisfies the type.

I wonder if that's a good idea. Certainly we don't actually need to run this, but perhaps state creation should be something we can separate out into a different static function...

// No streams are created
handleStream: () => {},
keyRing,
nodeGraph,
quicClientConfig: {} as any, // No connections are attempted
crypto: {} as any, // No connections are attempted
quicSocket: {} as any, // No connections are attempted
logger: logger.getChild(NodeConnectionManager.name),
});
const nodeManager = new NodeManager({
db,
keyRing,
nodeGraph,
nodeConnectionManager,
nodeConnectionManager: {} as any, // No connections are attempted
sigchain,
taskManager,
gestaltGraph,
Expand All @@ -177,7 +167,7 @@ async function bootstrapState({
await NotificationsManager.createNotificationsManager({
acl,
db,
nodeConnectionManager,
nodeConnectionManager: {} as any, // No connections are attempted
nodeManager,
keyRing,
logger: logger.getChild(NotificationsManager.name),
Expand All @@ -188,7 +178,7 @@ async function bootstrapState({
db,
gestaltGraph,
keyRing,
nodeConnectionManager,
nodeConnectionManager: {} as any, // No connections are attempted
vaultsPath,
notificationsManager,
logger: logger.getChild(VaultManager.name),
Expand Down
6 changes: 1 addition & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ const config = {
handlerTimeoutTime: 60_000, // 1 minute
handlerTimeoutGraceTime: 2_000, // 2 seconds
},
quicServerConfig: {
keepAliveIntervalTime: 10_000, // 10 seconds
maxIdleTimeout: 60_000, // 1 minute
},
quicClientConfig: {
quicConfig: {
keepAliveIntervalTime: 10_000, // 10 seconds
maxIdleTimeout: 60_000, // 1 minute
},
Expand Down
9 changes: 7 additions & 2 deletions tests/agent/handlers/nodesClaimsGet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ describe('nodesClaimsGet', () => {
cert: tlsConfig.certChainPem,
verifyPeer: false,
},
crypto,
crypto: {
key: keysUtils.generateKey(),
ops: crypto,
},
logger,
});
const handleStream = async (
Expand Down Expand Up @@ -134,7 +137,9 @@ describe('nodesClaimsGet', () => {
logger,
});
quicClient = await QUICClient.createQUICClient({
crypto,
crypto: {
ops: crypto,
},
config: {
verifyPeer: false,
},
Expand Down
9 changes: 7 additions & 2 deletions tests/agent/handlers/nodesClosestLocalNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ describe('nodesClosestLocalNode', () => {
cert: tlsConfig.certChainPem,
verifyPeer: false,
},
crypto,
crypto: {
key: keysUtils.generateKey(),
ops: crypto,
},
logger,
});
const handleStream = async (
Expand Down Expand Up @@ -133,7 +136,9 @@ describe('nodesClosestLocalNode', () => {
logger,
});
quicClient = await QUICClient.createQUICClient({
crypto,
crypto: {
ops: crypto,
},
config: {
verifyPeer: false,
},
Expand Down
9 changes: 7 additions & 2 deletions tests/agent/handlers/nodesCrossSignClaim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ describe('nodesCrossSignClaim', () => {
verifyPeer: true,
verifyAllowFail: true,
},
crypto,
crypto: {
key: keysUtils.generateKey(),
ops: crypto,
},
logger,
});
const handleStream = async (
Expand Down Expand Up @@ -186,7 +189,9 @@ describe('nodesCrossSignClaim', () => {
localNodeId = keysUtils.publicKeyToNodeId(clientKeyPair.publicKey);
const tlsConfigClient = await tlsTestsUtils.createTLSConfig(clientKeyPair);
quicClient = await QUICClient.createQUICClient({
crypto,
crypto: {
ops: crypto,
},
config: {
key: tlsConfigClient.keyPrivatePem,
cert: tlsConfigClient.certChainPem,
Expand Down
16 changes: 9 additions & 7 deletions tests/agent/handlers/nodesHolePunchMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ describe('nodesHolePunchMessage', () => {
keyRing.keyPair,
);
nodeConnectionManager = new NodeConnectionManager({
quicClientConfig: {
key: tlsConfigClient.keyPrivatePem,
cert: tlsConfigClient.certChainPem,
},
tlsConfig: tlsConfigClient,
crypto,
quicSocket,
keyRing,
Expand All @@ -128,7 +125,7 @@ describe('nodesHolePunchMessage', () => {
logger,
});
await nodeManager.start();
await nodeConnectionManager.start({ nodeManager });
await nodeConnectionManager.start({ nodeManager, handleStream: () => {} });
await taskManager.startProcessing();

// Setting up server
Expand All @@ -153,7 +150,10 @@ describe('nodesHolePunchMessage', () => {
verifyPeer: true,
verifyAllowFail: true,
},
crypto,
crypto: {
key: keysUtils.generateKey(),
ops: crypto,
},
logger,
});
const handleStream = async (
Expand Down Expand Up @@ -200,7 +200,9 @@ describe('nodesHolePunchMessage', () => {
logger,
});
quicClient = await QUICClient.createQUICClient({
crypto,
crypto: {
ops: crypto,
},
config: {
key: tlsConfigClient.keyPrivatePem,
cert: tlsConfigClient.certChainPem,
Expand Down
16 changes: 9 additions & 7 deletions tests/agent/handlers/notificationsSend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ describe('notificationsSend', () => {
keyRing.keyPair,
);
nodeConnectionManager = new NodeConnectionManager({
quicClientConfig: {
key: tlsConfigClient.keyPrivatePem,
cert: tlsConfigClient.certChainPem,
},
tlsConfig: tlsConfigClient,
crypto,
quicSocket,
keyRing,
Expand All @@ -151,7 +148,7 @@ describe('notificationsSend', () => {
logger,
});
await nodeManager.start();
await nodeConnectionManager.start({ nodeManager });
await nodeConnectionManager.start({ nodeManager, handleStream: () => {} });
await taskManager.startProcessing();
notificationsManager =
await NotificationsManager.createNotificationsManager({
Expand Down Expand Up @@ -183,7 +180,10 @@ describe('notificationsSend', () => {
verifyPeer: true,
verifyAllowFail: true,
},
crypto,
crypto: {
key: keysUtils.generateKey(),
ops: crypto,
},
logger,
});
const handleStream = async (
Expand Down Expand Up @@ -230,7 +230,9 @@ describe('notificationsSend', () => {
logger,
});
quicClient = await QUICClient.createQUICClient({
crypto,
crypto: {
ops: crypto,
},
config: {
key: tlsConfigClient.keyPrivatePem,
cert: tlsConfigClient.certChainPem,
Expand Down
4 changes: 2 additions & 2 deletions tests/client/handlers/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ describe('agentStatus', () => {
nodeIdEncoded: nodesUtils.encodeNodeId(pkAgent.keyRing.getNodeId()),
clientHost: pkAgent.webSocketServerClient.getHost(),
clientPort: pkAgent.webSocketServerClient.getPort(),
agentHost: pkAgent.quicServerAgent.host,
agentPort: pkAgent.quicServerAgent.port,
agentHost: pkAgent.quicSocket.host,
agentPort: pkAgent.quicSocket.port,
publicKeyJwk: keysUtils.publicKeyToJWK(pkAgent.keyRing.keyPair.publicKey),
certChainPEM: await pkAgent.certManager.getCertPEMsChainPEM(),
});
Expand Down
42 changes: 14 additions & 28 deletions tests/client/handlers/gestalts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,8 @@ describe('gestaltsDiscoverByIdentity', () => {
nodeConnectionManager = new NodeConnectionManager({
keyRing,
nodeGraph,
quicClientConfig: {
// @ts-ignore: TLS not needed for this test
key: undefined,
// @ts-ignore: TLS not needed for this test
cert: undefined,
},
// @ts-ignore: TLS not needed for this test
tlsConfig: {},
crypto,
quicSocket,
connectionConnectTime: 2000,
Expand All @@ -471,7 +467,7 @@ describe('gestaltsDiscoverByIdentity', () => {
logger,
});
await nodeManager.start();
await nodeConnectionManager.start({ nodeManager });
await nodeConnectionManager.start({ nodeManager, handleStream: () => {} });
discovery = await Discovery.createDiscovery({
db,
gestaltGraph,
Expand Down Expand Up @@ -637,12 +633,8 @@ describe('gestaltsDiscoverByNode', () => {
nodeConnectionManager = new NodeConnectionManager({
keyRing,
nodeGraph,
quicClientConfig: {
// @ts-ignore: TLS not needed for this test
key: undefined,
// @ts-ignore: TLS not needed for this test
cert: undefined,
},
// @ts-ignore: TLS not needed for this test
tlsConfig: {},
crypto,
quicSocket,
connectionConnectTime: 2000,
Expand All @@ -660,7 +652,7 @@ describe('gestaltsDiscoverByNode', () => {
logger,
});
await nodeManager.start();
await nodeConnectionManager.start({ nodeManager });
await nodeConnectionManager.start({ nodeManager, handleStream: () => {} });
discovery = await Discovery.createDiscovery({
db,
gestaltGraph,
Expand Down Expand Up @@ -1264,10 +1256,8 @@ describe('gestaltsGestaltTrustByIdentity', () => {
nodeConnectionManager = new NodeConnectionManager({
keyRing,
nodeGraph,
quicClientConfig: {
key: tlsConfig.keyPrivatePem,
cert: tlsConfig.certChainPem,
},
// @ts-ignore: TLS not needed for this test
tlsConfig: {},
crypto,
quicSocket,
connectionConnectTime: 2000,
Expand All @@ -1285,7 +1275,7 @@ describe('gestaltsGestaltTrustByIdentity', () => {
logger,
});
await nodeManager.start();
await nodeConnectionManager.start({ nodeManager });
await nodeConnectionManager.start({ nodeManager, handleStream: () => {} });
discovery = await Discovery.createDiscovery({
db,
gestaltGraph,
Expand Down Expand Up @@ -1785,12 +1775,8 @@ describe('gestaltsGestaltTrustByNode', () => {
nodeConnectionManager = new NodeConnectionManager({
keyRing,
nodeGraph,
quicClientConfig: {
// @ts-ignore: TLS not needed for this test
key: undefined,
// @ts-ignore: TLS not needed for this test
cert: undefined,
},
// @ts-ignore: TLS not needed for this test
tlsConfig: {},
crypto,
quicSocket,
connectionConnectTime: 2000,
Expand All @@ -1808,10 +1794,10 @@ describe('gestaltsGestaltTrustByNode', () => {
logger,
});
await nodeManager.start();
await nodeConnectionManager.start({ nodeManager });
await nodeConnectionManager.start({ nodeManager, handleStream: () => {} });
await nodeManager.setNode(nodeIdRemote, {
host: node.quicServerAgent.host as Host,
port: node.quicServerAgent.port as Port,
host: node.quicSocket.host as Host,
port: node.quicSocket.port as Port,
});
discovery = await Discovery.createDiscovery({
db,
Expand Down
Loading

0 comments on commit 7c3fb75

Please sign in to comment.