Skip to content

Commit

Permalink
syntax: general clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed May 26, 2022
1 parent 80c80f1 commit 2d78e92
Showing 1 changed file with 65 additions and 22 deletions.
87 changes: 65 additions & 22 deletions tests/network/Proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as networkUtils from '@/network/utils';
import * as networkErrors from '@/network/errors';
import * as keysUtils from '@/keys/utils';
import * as nodesUtils from '@/nodes/utils';
import { promisify, promise, timerStart, timerStop, poll } from '@/utils';
import { poll, promise, promisify, timerStart, timerStop } from '@/utils';
import * as testUtils from '../utils';

/**
Expand All @@ -27,7 +27,7 @@ async function httpConnect(
path: string,
): Promise<Socket> {
const tokenEncoded = Buffer.from(token, 'utf-8').toString('base64');
const socket = await new Promise<Socket>((resolve, reject) => {
return await new Promise<Socket>((resolve, reject) => {
const req = http.request({
method: 'CONNECT',
path: path,
Expand All @@ -49,7 +49,6 @@ async function httpConnect(
reject(e);
});
});
return socket;
}

/**
Expand Down Expand Up @@ -142,6 +141,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand All @@ -158,6 +159,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand All @@ -171,6 +174,7 @@ describe(Proxy.name, () => {
// Start it again
await proxy.start({
forwardHost: '::1' as Host,
proxyHost: localHost,
serverHost: localHost,
serverPort: port,
tlsConfig: {
Expand All @@ -194,6 +198,7 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -245,6 +250,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -279,6 +286,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -337,6 +346,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -396,6 +407,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -502,6 +515,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -620,6 +635,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -708,7 +725,7 @@ describe(Proxy.name, () => {
await expect(remoteClosedP).resolves.toBeUndefined();
expect(utpConnError.mock.calls.length).toBe(0);
// No TLS socket errors this time
// The client side figured that the node id is incorect
// The client side figured that the node id is incorrect
expect(tlsSocketError.mock.calls.length).toBe(0);
// This time the tls socket is ended from the client side
expect(tlsSocketEnd.mock.calls.length).toBe(1);
Expand Down Expand Up @@ -739,6 +756,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -830,7 +849,7 @@ describe(Proxy.name, () => {
await expect(remoteClosedP).resolves.toBeUndefined();
expect(utpConnError.mock.calls.length).toBe(0);
// No TLS socket errors this time
// The client side figured taht the node id is incorect
// The client side figured that node id is incorrect
expect(tlsSocketError.mock.calls.length).toBe(0);
// This time the tls socket is ended from the client side
expect(tlsSocketEnd.mock.calls.length).toBe(1);
Expand Down Expand Up @@ -864,6 +883,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -994,6 +1015,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -1092,7 +1115,7 @@ describe(Proxy.name, () => {
tlsSocket_!.once('end', resolveEndP);
tlsSocket_!.end();
await endP;
// Force destroy the socket due to buggy tlsSocket and utpConn
// Force destroys the socket due to buggy tlsSocket and utpConn
tlsSocket_!.destroy();
logger.debug('Reverse: finishes tlsSocket ending');
await expect(remoteClosedP).resolves.toBeUndefined();
Expand All @@ -1103,8 +1126,7 @@ describe(Proxy.name, () => {
return proxy.getConnectionForwardCount();
},
(_, result) => {
if (result === 0) return true;
return false;
return result === 0;
},
100,
),
Expand Down Expand Up @@ -1144,6 +1166,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -1296,6 +1320,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -1414,7 +1440,7 @@ describe(Proxy.name, () => {
tlsSocket_!.once('end', resolveEndP);
tlsSocket_!.end();
await endP;
// Force destroy the socket due to buggy tlsSocket and utpConn
// Force destroys the socket due to buggy tlsSocket and utpConn
tlsSocket_!.destroy();
logger.debug('Reverse: finishes tlsSocket ending');
await expect(localClosedP).resolves.toBeUndefined();
Expand All @@ -1427,8 +1453,7 @@ describe(Proxy.name, () => {
return proxy.getConnectionForwardCount();
},
(_, result) => {
if (result === 0) return true;
return false;
return result === 0;
},
100,
),
Expand Down Expand Up @@ -1468,6 +1493,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -1567,7 +1594,7 @@ describe(Proxy.name, () => {
);
expect(proxy.getConnectionForwardCount()).toBe(1);
const { p: endP, resolveP: resolveEndP } = promise<void>();
// By default net sockets have `allowHalfOpen: false`
// By default, net sockets have `allowHalfOpen: false`
// Here we override the behaviour by removing the end listener
// And replacing it with our own, and remember to also force destroy
clientSocket.removeAllListeners('end');
Expand All @@ -1588,8 +1615,7 @@ describe(Proxy.name, () => {
return proxy.getConnectionForwardCount();
},
(_, result) => {
if (result === 0) return true;
return false;
return result === 0;
},
100,
),
Expand Down Expand Up @@ -1625,6 +1651,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -1757,6 +1785,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -1875,6 +1905,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -1978,8 +2010,7 @@ describe(Proxy.name, () => {
return proxy.getConnectionForwardCount();
},
(_, result) => {
if (result === 0) return true;
return false;
return result === 0;
},
100,
),
Expand Down Expand Up @@ -2014,6 +2045,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -2121,6 +2154,8 @@ describe(Proxy.name, () => {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
serverHost: localHost,
serverPort: port,
});
Expand Down Expand Up @@ -2272,7 +2307,8 @@ describe(Proxy.name, () => {
await proxy.start({
serverHost: serverHost(),
serverPort: serverPort(),

proxyHost: localHost,
forwardHost: localHost,
tlsConfig: {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
Expand Down Expand Up @@ -2303,7 +2339,8 @@ describe(Proxy.name, () => {
await proxy.start({
serverHost: serverHost(),
serverPort: serverPort(),

proxyHost: localHost,
forwardHost: localHost,
tlsConfig: {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
Expand Down Expand Up @@ -2343,6 +2380,8 @@ describe(Proxy.name, () => {
await proxy.start({
serverHost: serverHost(),
serverPort: serverPort(),
proxyHost: localHost,
forwardHost: localHost,

tlsConfig: {
keyPrivatePem: keyPairPem.privateKey,
Expand Down Expand Up @@ -2394,6 +2433,8 @@ describe(Proxy.name, () => {
await proxy.start({
serverHost: serverHost(),
serverPort: serverPort(),
proxyHost: localHost,
forwardHost: localHost,

tlsConfig: {
keyPrivatePem: keyPairPem.privateKey,
Expand Down Expand Up @@ -2470,6 +2511,8 @@ describe(Proxy.name, () => {
await proxy.start({
serverHost: serverHost(),
serverPort: serverPort(),
proxyHost: localHost,
forwardHost: localHost,

tlsConfig: {
keyPrivatePem: keyPairPem.privateKey,
Expand Down Expand Up @@ -2590,8 +2633,7 @@ describe(Proxy.name, () => {
return proxy.getConnectionReverseCount();
},
(_, result) => {
if (result === 0) return true;
return false;
return result === 0;
},
100,
),
Expand Down Expand Up @@ -2630,6 +2672,7 @@ describe(Proxy.name, () => {
certChainPem: certPem,
},
proxyHost: localHost,
forwardHost: localHost,
});
const externalHost = proxy.getProxyHost();
const externalPort = proxy.getProxyPort();
Expand Down Expand Up @@ -2697,8 +2740,7 @@ describe(Proxy.name, () => {
return proxy.getConnectionReverseCount();
},
(_, result) => {
if (result === 0) return true;
return false;
return result === 0;
},
100,
),
Expand Down Expand Up @@ -2737,6 +2779,7 @@ describe(Proxy.name, () => {
serverHost: serverHost(),
serverPort: serverPort(),
proxyHost: localHost,
forwardHost: localHost,
tlsConfig: {
keyPrivatePem: keyPairPem.privateKey,
certChainPem: certPem,
Expand Down

0 comments on commit 2d78e92

Please sign in to comment.