diff --git a/package-lock.json b/package-lock.json index 0d2835b8..b9de4432 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,7 +40,7 @@ "nexpect": "^0.6.0", "node-gyp-build": "^4.4.0", "nodemon": "^3.0.1", - "polykey": "^1.2.1-alpha.45", + "polykey": "^1.2.1-alpha.46", "prettier": "^3.0.0", "shelljs": "^0.8.5", "shx": "^0.3.4", @@ -1476,9 +1476,9 @@ ] }, "node_modules/@matrixai/quic": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@matrixai/quic/-/quic-1.1.1.tgz", - "integrity": "sha512-C3CizeW/0lQ+tu+J9sKB7Sl7vx4CJq1t875B5Y5C5Ao0cZcjK1Xi10lSRILcce1RdoCpUGlbVFosat7YdONiGg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@matrixai/quic/-/quic-1.1.4.tgz", + "integrity": "sha512-WhwoFzw2fuxDCxzY/WTZnMHg2snSGpGvifh4K6iRPfnvUfKME0ikFty7EMkRt8bQiAes4yxBbcI72/wBSeTYMA==", "dev": true, "dependencies": { "@matrixai/async-cancellable": "^1.1.1", @@ -1486,23 +1486,23 @@ "@matrixai/async-locks": "^4.0.0", "@matrixai/contexts": "^1.2.0", "@matrixai/errors": "^1.2.0", - "@matrixai/events": "^3.2.0", - "@matrixai/logger": "^3.1.0", + "@matrixai/events": "^3.2.3", + "@matrixai/logger": "^3.1.2", "@matrixai/resources": "^1.1.5", - "@matrixai/timer": "^1.1.1", + "@matrixai/timer": "^1.1.3", "ip-num": "^1.5.0" }, "optionalDependencies": { - "@matrixai/quic-darwin-arm64": "1.1.1", - "@matrixai/quic-darwin-x64": "1.1.1", - "@matrixai/quic-linux-x64": "1.1.1", - "@matrixai/quic-win32-x64": "1.1.1" + "@matrixai/quic-darwin-arm64": "1.1.4", + "@matrixai/quic-darwin-x64": "1.1.4", + "@matrixai/quic-linux-x64": "1.1.4", + "@matrixai/quic-win32-x64": "1.1.4" } }, "node_modules/@matrixai/quic-darwin-arm64": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@matrixai/quic-darwin-arm64/-/quic-darwin-arm64-1.1.1.tgz", - "integrity": "sha512-tTtJ1ppYzanlZLXnIBcyHPf+yzVCmn3CJHnA5ymMOJBfGN1zB6+ZPbuEWql/4+DveBn0qTMgbWzWGhv4xpi3Kg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@matrixai/quic-darwin-arm64/-/quic-darwin-arm64-1.1.4.tgz", + "integrity": "sha512-/Dho39T4sjbdOeC01F4rDesssQ9nvfdH57Ap95870LoY1KwXWh+c7cAtdv9FVma2R+9cqdKNkfsMFcS68Y15KA==", "cpu": [ "arm64" ], @@ -1512,9 +1512,9 @@ ] }, "node_modules/@matrixai/quic-darwin-x64": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@matrixai/quic-darwin-x64/-/quic-darwin-x64-1.1.1.tgz", - "integrity": "sha512-XBhAO/fdY44s78zqhTwtUit5IU6ewZ3IZAbmKXDXQCpUQwJEORd9BV6kLfS+apiB8FGNgmaCsUoO8DoUMXr1eA==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@matrixai/quic-darwin-x64/-/quic-darwin-x64-1.1.4.tgz", + "integrity": "sha512-soxYopXZjoHxSMvpoNEKQQS1uQcXK2aIuaJHDgZINz4UbeLW0NsoEqMgUJKXeWZNR+aaVxhL5fE5+5Ypwej80Q==", "cpu": [ "x64" ], @@ -1524,9 +1524,9 @@ ] }, "node_modules/@matrixai/quic-linux-x64": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@matrixai/quic-linux-x64/-/quic-linux-x64-1.1.1.tgz", - "integrity": "sha512-EOT9u53Sw0NW6pesSYXO0KFdsh0sMXmrUr+9ZrlqlIIKRylPEUcvGgL5d1QTyMtNnwXoCl2azSkmX1QYg4tHFw==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@matrixai/quic-linux-x64/-/quic-linux-x64-1.1.4.tgz", + "integrity": "sha512-LRKkVX++UZEj00XhfD0cPe4uFQJeHOBpQl+v6BIL7LSB9KxsmQRgbDh5mvxvWAwnh5EI51aSgn4auWEdHMDjTw==", "cpu": [ "x64" ], @@ -1536,9 +1536,9 @@ ] }, "node_modules/@matrixai/quic-win32-x64": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@matrixai/quic-win32-x64/-/quic-win32-x64-1.1.1.tgz", - "integrity": "sha512-czHsmQ5YfYR2QXx4GxHaT9KveeeAnivHu3uUd+4KxKlTHBN8XM36X4y7ZuNxGvJjhhitidJ88NwxTQWe54hZGg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@matrixai/quic-win32-x64/-/quic-win32-x64-1.1.4.tgz", + "integrity": "sha512-JNIQn1GRCRDm23v7hkqNVRm0oV928AHVfNPXJOB6FqBtbmbe/DaqUnppFi3qqUxm5Agguhd1rgNfKkL4HRhq8A==", "cpu": [ "x64" ], @@ -1554,9 +1554,9 @@ "devOptional": true }, "node_modules/@matrixai/rpc": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/@matrixai/rpc/-/rpc-0.4.4.tgz", - "integrity": "sha512-P2UcXrJhbMvcBJwyIK0QNQnSL9/pHeu/E4ERQxTir8bF/YRZEFzScm4y6g8TzcgZCBjSMsawnPveXroBXsITxg==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@matrixai/rpc/-/rpc-0.5.0.tgz", + "integrity": "sha512-Qgv2ovsQk/SEzGC8ARAQXLMY8mB0DoyI43TNsu3wF+d6p33ZnGvrzbNpHykD4+b14bzNQPU5Vk3JOAOjyXtjbQ==", "dev": true, "dependencies": { "@matrixai/async-init": "^1.10.0", @@ -7488,9 +7488,9 @@ } }, "node_modules/polykey": { - "version": "1.2.1-alpha.45", - "resolved": "https://registry.npmjs.org/polykey/-/polykey-1.2.1-alpha.45.tgz", - "integrity": "sha512-MorGIn87Mr/w6XDT3SJt3YFJ1YaNb6LWfuCjbKl7/+77q3GxJRk7k189XivdZ8f1XmAu/AGbkC/Fzk0a1/SHOA==", + "version": "1.2.1-alpha.46", + "resolved": "https://registry.npmjs.org/polykey/-/polykey-1.2.1-alpha.46.tgz", + "integrity": "sha512-h7TdfB7TPud71wgQxWwKux4YxpF1ZbUa5YNrc94YTrRuUWZg34J9dLGM1aYUrwJTy3hIbjdBnU5u4jPxKJD+hw==", "dev": true, "dependencies": { "@matrixai/async-cancellable": "^1.1.1", @@ -7503,9 +7503,9 @@ "@matrixai/id": "^3.3.6", "@matrixai/logger": "^3.1.2", "@matrixai/mdns": "^1.2.5", - "@matrixai/quic": "^1.1.1", + "@matrixai/quic": "^1.1.4", "@matrixai/resources": "^1.1.5", - "@matrixai/rpc": "^0.4.4", + "@matrixai/rpc": "^0.5.0", "@matrixai/timer": "^1.1.3", "@matrixai/workers": "^1.3.7", "@matrixai/ws": "^1.1.7", diff --git a/package.json b/package.json index bb19e9b4..cdc4a77e 100644 --- a/package.json +++ b/package.json @@ -132,7 +132,7 @@ "nexpect": "^0.6.0", "node-gyp-build": "^4.4.0", "nodemon": "^3.0.1", - "polykey": "^1.2.1-alpha.45", + "polykey": "^1.2.1-alpha.46", "prettier": "^3.0.0", "shelljs": "^0.8.5", "shx": "^0.3.4", diff --git a/src/errors.ts b/src/errors.ts index 1d983e08..9d26dbf2 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -66,7 +66,7 @@ class ErrorPolykeyCLIUnhandledRejection extends ErrorPolykeyCLI { } /** - * Asychronous deadlocks is a logic error. + * Asynchronous deadlocks is a logic error. * If these exceptions occur, there is a bug. */ class ErrorPolykeyCLIAsynchronousDeadlock extends ErrorPolykeyCLI { diff --git a/src/nodes/CommandFind.ts b/src/nodes/CommandFind.ts index 8d2d95b4..83ea1d09 100644 --- a/src/nodes/CommandFind.ts +++ b/src/nodes/CommandFind.ts @@ -51,14 +51,15 @@ class CommandFind extends CommandPolykey { }, logger: this.logger.getChild(PolykeyClient.name), }); - const result = { + const result: { + success: boolean; + message: string; + id: string; + address?: { host: Host | Hostname; port: Port }; + } = { success: false, message: '', id: '', - address: { - host: '', - port: 0, - }, }; let foundAddress: | { @@ -111,7 +112,7 @@ class CommandFind extends CommandPolykey { }); } process.stdout.write(outputFormatted); - // Like ping it should error when failing to find node for automation reasons. + // Like ping, it should error when failing to find node for automation reasons. if (!result.success) { throw new errors.ErrorPolykeyCLINodeFindFailed(result.message); } diff --git a/src/nodes/CommandPing.ts b/src/nodes/CommandPing.ts index 410e1cf3..258e64e5 100644 --- a/src/nodes/CommandPing.ts +++ b/src/nodes/CommandPing.ts @@ -48,7 +48,7 @@ class CommandPing extends CommandPolykey { }, logger: this.logger.getChild(PolykeyClient.name), }); - let error; + let error: any; const statusMessage = await binUtils.retryAuthentication( (auth) => pkClient.rpcClient.methods.nodesPing({ diff --git a/src/secrets/CommandEdit.ts b/src/secrets/CommandEdit.ts index 541f8920..73207a6e 100644 --- a/src/secrets/CommandEdit.ts +++ b/src/secrets/CommandEdit.ts @@ -87,7 +87,7 @@ class CommandEdit extends CommandPolykey { secretName: secretPath[1], secretContent: content.toString('binary'), }); - await this.fs.promises.rmdir(tmpDir, { recursive: true }); + await this.fs.promises.rm(tmpDir, { recursive: true, force: true }); // Windows // TODO: complete windows impl } finally { diff --git a/src/types.ts b/src/types.ts index a0377f61..a6ded81e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -18,7 +18,7 @@ type AgentStatusLiveData = Omit & { }; /** - * PolykeyAgent Starting Input when Backgrounded + * PolykeyAgent Starting Input when backgrounded * When using advanced serialization, rich structures like * Map, Set and more can be passed over IPC * However traditional classes cannot be diff --git a/src/utils/ExitHandlers.ts b/src/utils/ExitHandlers.ts index 198ec309..609e6443 100644 --- a/src/utils/ExitHandlers.ts +++ b/src/utils/ExitHandlers.ts @@ -5,8 +5,8 @@ import * as errors from '../errors'; class ExitHandlers { /** - * Mutate this array to control handlers - * Handlers will be executed in reverse order + * Mutate this array to control handlers. + * Handlers will be executed in reverse order. */ public handlers: Array<(signal?: NodeJS.Signals) => Promise>; protected _exiting: boolean = false; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 6183f308..1b345101 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -242,7 +242,7 @@ function outputFormatterList(items: Array): string { * @param options * @param options.columns - Can either be an `Array` or `Record`. * If it is `Record`, the `number` values will be used as the initial padding lengths. - * The object is also mutated if any cells exceed the inital padding lengths. + * The object is also mutated if any cells exceed the initial padding lengths. * This parameter can also be supplied to filter the columns that will be displayed. * @param options.includeHeaders - Defaults to `True` * @param options.includeRowCount - Defaults to `False`. diff --git a/tests/TestProvider.ts b/tests/TestProvider.ts index 29f1f49d..ba97c1c2 100644 --- a/tests/TestProvider.ts +++ b/tests/TestProvider.ts @@ -82,13 +82,13 @@ class TestProvider extends Provider { authIdentityId: IdentityId, identityId: IdentityId, ): Promise { - let providerToken = await this.getToken(authIdentityId); + const providerToken = await this.getToken(authIdentityId); if (!providerToken) { throw new identitiesErrors.ErrorProviderUnauthenticated( `${authIdentityId} has not been authenticated`, ); } - providerToken = await this.checkToken(providerToken, authIdentityId); + await this.checkToken(providerToken, authIdentityId); const user = this.users[identityId]; if (!user) { return; @@ -106,13 +106,13 @@ class TestProvider extends Provider { authIdentityId: IdentityId, searchTerms: Array = [], ): AsyncGenerator { - let providerToken = await this.getToken(authIdentityId); + const providerToken = await this.getToken(authIdentityId); if (!providerToken) { throw new identitiesErrors.ErrorProviderUnauthenticated( `${authIdentityId} has not been authenticated`, ); } - providerToken = await this.checkToken(providerToken, authIdentityId); + await this.checkToken(providerToken, authIdentityId); for (const [k, v] of Object.entries(this.users) as Array< [ IdentityId, @@ -152,8 +152,8 @@ class TestProvider extends Provider { await this.checkToken(providerToken, authIdentityId); const linkId = this.linkIdCounter.toString() as ProviderIdentityClaimId; this.linkIdCounter++; - const identityClainEncoded = tokenUtils.generateSignedToken(identityClaim); - this.links[linkId] = JSON.stringify(identityClainEncoded); + const identityClaimEncoded = tokenUtils.generateSignedToken(identityClaim); + this.links[linkId] = JSON.stringify(identityClaimEncoded); this.userLinks[authIdentityId] = this.userLinks[authIdentityId] ? this.userLinks[authIdentityId] : []; diff --git a/tests/agent/start.test.ts b/tests/agent/start.test.ts index d56b82b1..732ee776 100644 --- a/tests/agent/start.test.ts +++ b/tests/agent/start.test.ts @@ -265,8 +265,8 @@ describe('start', () => { ]); // These will be the last line of STDERR // The readline library will automatically trim off newlines - let stdErrLine1; - let stdErrLine2; + let stdErrLine1: string; + let stdErrLine2: string; const rlErr1 = readline.createInterface(agentProcess1.stderr!); const rlErr2 = readline.createInterface(agentProcess2.stderr!); const agentStartedProm1 = promise<[number, string]>(); @@ -310,8 +310,7 @@ describe('start', () => { }, globalThis.defaultTimeout * 2, ); - // FIXME: disabled for now, both are succeeding when 1 should fail - test.skip( + test( 'concurrent with bootstrap results in 1 success', async () => { const password = 'abc123'; @@ -360,8 +359,8 @@ describe('start', () => { ]); // These will be the last line of STDERR // The readline library will automatically trim off newlines - let stdErrLine1; - let stdErrLine2; + let stdErrLine1: string; + let stdErrLine2: string; const rlErr1 = readline.createInterface(agentProcess.stderr!); const rlErr2 = readline.createInterface(bootstrapProcess.stderr!); const agentStartedProm1 = promise<[number, string]>(); @@ -679,7 +678,7 @@ describe('start', () => { ); const statusInfo2 = await status.waitFor('LIVE'); expect(statusInfo2.status).toBe('LIVE'); - // Node Id hasn't changed + // Node ID hasn't changed expect(statusInfo1.data.nodeId).toStrictEqual(statusInfo2.data.nodeId); agentProcess2.kill('SIGTERM'); await testUtils.processExit(agentProcess2); @@ -874,7 +873,7 @@ describe('start', () => { globalThis.defaultTimeout * 2, ); describe('start with global agent', () => { - let agentDataDir; + let agentDataDir: string; let agent1Status: StatusLive; let agent1Close: () => Promise; let agent2Status: StatusLive; diff --git a/tests/agent/status.test.ts b/tests/agent/status.test.ts index 1247d7ab..e23e12bc 100644 --- a/tests/agent/status.test.ts +++ b/tests/agent/status.test.ts @@ -63,7 +63,7 @@ describe('status', () => { logger, ); await status.waitFor('STARTING'); - let exitCode, stdout; + let exitCode: number, stdout: string; ({ exitCode, stdout } = await testUtils.pkExec( ['agent', 'status', '--format', 'json'], { @@ -132,9 +132,9 @@ describe('status', () => { }); }); describe('status with global agent', () => { - let agentDir; - let agentPassword; - let agentClose; + let agentDir: string; + let agentPassword: string; + let agentClose: () => Promise; beforeEach(async () => { ({ agentDir, agentPassword, agentClose } = await testUtils.setupTestAgent(logger)); diff --git a/tests/agent/unlock.test.ts b/tests/agent/unlock.test.ts index 2221ce5c..408bee78 100644 --- a/tests/agent/unlock.test.ts +++ b/tests/agent/unlock.test.ts @@ -9,9 +9,9 @@ describe('unlock', () => { const logger = new Logger('unlock test', LogLevel.WARN, [ new StreamHandler(), ]); - let agentDir; - let agentPassword; - let agentClose; + let agentDir: string; + let agentPassword: string; + let agentClose: () => Promise; beforeEach(async () => { ({ agentDir, agentPassword, agentClose } = await testUtils.setupTestAgent(logger)); @@ -27,7 +27,7 @@ describe('unlock', () => { logger, fresh: true, }); - let exitCode, stdout; + let exitCode: number, stdout: string; ({ exitCode } = await testUtils.pkExec(['agent', 'unlock'], { env: { PK_NODE_PATH: agentDir, diff --git a/tests/bootstrap.test.ts b/tests/bootstrap.test.ts index ceb23736..fd550019 100644 --- a/tests/bootstrap.test.ts +++ b/tests/bootstrap.test.ts @@ -56,10 +56,10 @@ describe('bootstrap', () => { const passwordPath = path.join(dataDir, 'password'); await fs.promises.writeFile(passwordPath, password); const keyPair = keysUtils.generateKeyPair(); - const privateKeyjwK = keysUtils.privateKeyToJWK(keyPair.privateKey); + const privateKeyJWK = keysUtils.privateKeyToJWK(keyPair.privateKey); const privateKeyJWE = keysUtils.wrapWithPassword( password, - privateKeyjwK, + privateKeyJWK, keysUtils.passwordOpsLimits.min, keysUtils.passwordMemLimits.min, ); @@ -99,8 +99,7 @@ describe('bootstrap', () => { const password = 'password'; await fs.promises.mkdir(path.join(dataDir, 'polykey')); await fs.promises.writeFile(path.join(dataDir, 'polykey', 'test'), ''); - let exitCode, stdout, stderr; - ({ exitCode, stdout, stderr } = await testUtils.pkExec( + const { exitCode: exitCode1, stderr: stderr1 } = await testUtils.pkExec( [ 'bootstrap', '--node-path', @@ -117,13 +116,13 @@ describe('bootstrap', () => { }, cwd: dataDir, }, - )); + ); const errorBootstrapExistingState = new bootstrapErrors.ErrorBootstrapExistingState(); - testUtils.expectProcessError(exitCode, stderr, [ + testUtils.expectProcessError(exitCode1, stderr1, [ errorBootstrapExistingState, ]); - ({ exitCode, stdout, stderr } = await testUtils.pkExec( + const { exitCode: exitCode2, stdout: stdout2 } = await testUtils.pkExec( [ 'bootstrap', '--node-path', @@ -139,9 +138,9 @@ describe('bootstrap', () => { }, cwd: dataDir, }, - )); - expect(exitCode).toBe(0); - const recoveryCode = stdout.trim(); + ); + expect(exitCode2).toBe(0); + const recoveryCode = stdout2.trim(); expect( recoveryCode.split(' ').length === 12 || recoveryCode.split(' ').length === 24, @@ -183,8 +182,8 @@ describe('bootstrap', () => { ]); // These will be the last line of STDERR // The readline library will automatically trim off newlines - let stdErrLine1; - let stdErrLine2; + let stdErrLine1: string | undefined; + let stdErrLine2: string | undefined; const rlErr1 = readline.createInterface(bootstrapProcess1.stderr!); const rlErr2 = readline.createInterface(bootstrapProcess2.stderr!); rlErr1.on('line', (l) => { @@ -208,14 +207,14 @@ describe('bootstrap', () => { // It's either the first or second process if (index === 0) { expect(stdErrLine1).toBeDefined(); - testUtils.expectProcessError(exitCode!, stdErrLine1, [ + testUtils.expectProcessError(exitCode!, stdErrLine1!, [ errorStatusLocked, ]); const [exitCode2] = await testUtils.processExit(bootstrapProcess2); expect(exitCode2).toBe(0); } else if (index === 1) { expect(stdErrLine2).toBeDefined(); - testUtils.expectProcessError(exitCode!, stdErrLine2, [ + testUtils.expectProcessError(exitCode!, stdErrLine2!, [ errorStatusLocked, ]); const [exitCode2] = await testUtils.processExit(bootstrapProcess1); diff --git a/tests/identities/allowDisallowPermissions.test.ts b/tests/identities/allowDisallowPermissions.test.ts index c31e5452..f395f134 100644 --- a/tests/identities/allowDisallowPermissions.test.ts +++ b/tests/identities/allowDisallowPermissions.test.ts @@ -101,7 +101,7 @@ describe('allow/disallow/permissions', () => { }); }); test('allows/disallows/gets gestalt permissions by node', async () => { - let exitCode, stdout; + let exitCode: number, stdout: string; // Add the node to our node graph, otherwise we won't be able to contact it await testUtils.pkStdio( [ @@ -213,7 +213,7 @@ describe('allow/disallow/permissions', () => { }); test('allows/disallows/gets gestalt permissions by identity', async () => { // Can't test with target executable due to mocking - let exitCode, stdout; + let exitCode: number, stdout: string; // Add the node to our node graph, otherwise we won't be able to contact it await testUtils.pkStdio( [ @@ -250,7 +250,7 @@ describe('allow/disallow/permissions', () => { // This is because trusting the identity sets it in our gestalt graph, // which we need in order to set permissions // This command should fail first time since the identity won't be linked - // to any nodes. It will trigger this process via discovery and we must + // to any nodes. It will trigger this process via discovery, and we must // wait and then retry await testUtils.pkStdio(['identities', 'trust', providerString], { env: { @@ -341,7 +341,7 @@ describe('allow/disallow/permissions', () => { }); }); test('should fail on invalid inputs', async () => { - let exitCode; + let exitCode: number; // Allow // Invalid gestalt id ({ exitCode } = await testUtils.pkExec( diff --git a/tests/identities/authenticateAuthenticated.test.ts b/tests/identities/authenticateAuthenticated.test.ts index 402915d5..631ba2b7 100644 --- a/tests/identities/authenticateAuthenticated.test.ts +++ b/tests/identities/authenticateAuthenticated.test.ts @@ -57,7 +57,7 @@ describe('authenticate/authenticated', () => { }); test('authenticates identity with a provider and gets authenticated identity', async () => { // Can't test with target command due to mocking - let exitCode, stdout; + let exitCode: number, stdout: string; // Authenticate an identity ({ exitCode, stdout } = await testUtils.pkStdio( [ @@ -117,7 +117,7 @@ describe('authenticate/authenticated', () => { }); }); test('should fail on invalid inputs', async () => { - let exitCode; + let exitCode: number; // Authenticate // Invalid provider ({ exitCode } = await testUtils.pkStdio( diff --git a/tests/identities/claim.test.ts b/tests/identities/claim.test.ts index 8077903d..d46b99f8 100644 --- a/tests/identities/claim.test.ts +++ b/tests/identities/claim.test.ts @@ -120,7 +120,7 @@ describe('claim', () => { expect(exitCode).toBe(sysexits.NOPERM); }); test('should fail on invalid inputs', async () => { - let exitCode; + let exitCode: number; // Invalid provider ({ exitCode } = await testUtils.pkStdio( ['identities', 'claim', `:${testToken.identityId}`], diff --git a/tests/identities/discoverGet.test.ts b/tests/identities/discoverGet.test.ts index 1d3212b7..a7744699 100644 --- a/tests/identities/discoverGet.test.ts +++ b/tests/identities/discoverGet.test.ts @@ -43,7 +43,7 @@ describe('discover/get', () => { dataDir = await fs.promises.mkdtemp( path.join(globalThis.tmpDir, 'polykey-test-'), ); - // Setup the remote gestalt state here + // Set up the remote gestalt state here // Setting up remote nodes nodeA = await PolykeyAgent.createPolykeyAgent({ password, @@ -283,9 +283,8 @@ describe('discover/get', () => { pkAgent.discovery.visitedVertices.clear(); }); test('should fail on invalid inputs', async () => { - let exitCode; // Discover - ({ exitCode } = await testUtils.pkStdio( + const { exitCode } = await testUtils.pkStdio( ['identities', 'discover', 'invalid'], { env: { @@ -294,15 +293,15 @@ describe('discover/get', () => { }, cwd: dataDir, }, - )); + ); expect(exitCode).toBe(sysexits.USAGE); // Get - ({ exitCode } = await testUtils.pkStdio(['identities', 'get', 'invalid'], { + await testUtils.pkStdio(['identities', 'get', 'invalid'], { env: { PK_NODE_PATH: nodePath, PK_PASSWORD: password, }, cwd: dataDir, - })); + }); }); }); diff --git a/tests/identities/search.test.ts b/tests/identities/search.test.ts index 0d02fa23..ce8748d7 100644 --- a/tests/identities/search.test.ts +++ b/tests/identities/search.test.ts @@ -146,7 +146,7 @@ describe('search', () => { }); test('finds connected identities', async () => { // Can't test with target executable due to mocking - let exitCode, stdout; + let exitCode: number, stdout: string; let searchResults: Array; // Search with no authenticated identities // Should return nothing @@ -185,7 +185,10 @@ describe('search', () => { }, )); expect(exitCode).toBe(0); - searchResults = stdout.split('\n').slice(undefined, -1).map(JSON.parse); + searchResults = stdout + .split('\n') + .slice(undefined, -1) + .map((v) => JSON.parse(v)); expect(searchResults).toHaveLength(3); expect(searchResults).toContainEqual(user1); expect(searchResults).toContainEqual(user2); @@ -214,7 +217,10 @@ describe('search', () => { }, )); expect(exitCode).toBe(0); - searchResults = stdout.split('\n').slice(undefined, -1).map(JSON.parse); + searchResults = stdout + .split('\n') + .slice(undefined, -1) + .map((v) => JSON.parse(v)); expect(searchResults).toHaveLength(6); expect(searchResults).toContainEqual(user1); expect(searchResults).toContainEqual(user2); @@ -234,7 +240,10 @@ describe('search', () => { }, )); expect(exitCode).toBe(0); - searchResults = stdout.split('\n').slice(undefined, -1).map(JSON.parse); + searchResults = stdout + .split('\n') + .slice(undefined, -1) + .map((v) => JSON.parse(v)); expect(searchResults).toHaveLength(2); expect(searchResults).toContainEqual(user4); expect(searchResults).toContainEqual(user5); @@ -270,7 +279,10 @@ describe('search', () => { }, )); expect(exitCode).toBe(0); - searchResults = stdout.split('\n').slice(undefined, -1).map(JSON.parse); + searchResults = stdout + .split('\n') + .slice(undefined, -1) + .map((v) => JSON.parse(v)); expect(searchResults).toHaveLength(5); expect(searchResults).toContainEqual(user4); expect(searchResults).toContainEqual(user5); @@ -297,7 +309,10 @@ describe('search', () => { }, )); expect(exitCode).toBe(0); - searchResults = stdout.split('\n').slice(undefined, -1).map(JSON.parse); + searchResults = stdout + .split('\n') + .slice(undefined, -1) + .map((v) => JSON.parse(v)); expect(searchResults).toHaveLength(5); expect(searchResults).toContainEqual(user4); expect(searchResults).toContainEqual(user5); @@ -317,7 +332,10 @@ describe('search', () => { }, )); expect(exitCode).toBe(0); - searchResults = stdout.split('\n').slice(undefined, -1).map(JSON.parse); + searchResults = stdout + .split('\n') + .slice(undefined, -1) + .map((v) => JSON.parse(v)); expect(searchResults).toHaveLength(3); expect(searchResults).toContainEqual(user3); expect(searchResults).toContainEqual(user6); @@ -334,11 +352,14 @@ describe('search', () => { }, )); expect(exitCode).toBe(0); - searchResults = stdout.split('\n').slice(undefined, -1).map(JSON.parse); + searchResults = stdout + .split('\n') + .slice(undefined, -1) + .map((v) => JSON.parse(v)); expect(searchResults).toHaveLength(2); }); test('should fail on invalid inputs', async () => { - let exitCode; + let exitCode: number; // Invalid identity id ({ exitCode } = await testUtils.pkStdio( ['identities', 'search', '--identity-id', ''], diff --git a/tests/identities/trustUntrustList.test.ts b/tests/identities/trustUntrustList.test.ts index 610361c0..ece56feb 100644 --- a/tests/identities/trustUntrustList.test.ts +++ b/tests/identities/trustUntrustList.test.ts @@ -103,9 +103,9 @@ describe('trust/untrust/list', () => { }); }); test( - 'trusts and untrusts a gestalt by node, adds it to the gestalt graph, and lists the gestalt with notify permission', + 'trusts and un-trusts a gestalt by node, adds it to the gestalt graph, and lists the gestalt with notify permission', async () => { - let exitCode, stdout; + let exitCode: number, stdout: string; // Add the node to our node graph and authenticate an identity on the // provider // This allows us to contact the members of the gestalt we want to trust @@ -233,9 +233,9 @@ describe('trust/untrust/list', () => { globalThis.defaultTimeout * 2, ); test( - 'trusts and untrusts a gestalt by identity, adds it to the gestalt graph, and lists the gestalt with notify permission', + 'trusts and un-trusts a gestalt by identity, adds it to the gestalt graph, and lists the gestalt with notify permission', async () => { - let exitCode, stdout; + let exitCode: number, stdout: string; // Add the node to our node graph and authenticate an identity on the // provider // This allows us to contact the members of the gestalt we want to trust @@ -377,7 +377,7 @@ describe('trust/untrust/list', () => { globalThis.defaultTimeout * 2, ); test('should fail on invalid inputs', async () => { - let exitCode; + let exitCode: number; // Trust ({ exitCode } = await testUtils.pkStdio( ['identities', 'trust', 'invalid'], diff --git a/tests/keys/cert.test.ts b/tests/keys/cert.test.ts index 4fb281fb..7e118a8c 100644 --- a/tests/keys/cert.test.ts +++ b/tests/keys/cert.test.ts @@ -3,9 +3,9 @@ import * as testUtils from '../utils'; describe('cert', () => { const logger = new Logger('cert test', LogLevel.WARN, [new StreamHandler()]); - let agentDir; - let agentPassword; - let agentClose; + let agentDir: string; + let agentPassword: string; + let agentClose: () => Promise; beforeEach(async () => { ({ agentDir, agentPassword, agentClose } = await testUtils.setupTestAgent(logger)); diff --git a/tests/keys/certchain.test.ts b/tests/keys/certchain.test.ts index c2f70a66..dc53eec1 100644 --- a/tests/keys/certchain.test.ts +++ b/tests/keys/certchain.test.ts @@ -5,9 +5,9 @@ describe('certchain', () => { const logger = new Logger('certchain test', LogLevel.WARN, [ new StreamHandler(), ]); - let agentDir; - let agentPassword; - let agentClose; + let agentDir: string; + let agentPassword: string; + let agentClose: () => Promise; beforeEach(async () => { ({ agentDir, agentPassword, agentClose } = await testUtils.setupTestAgent(logger)); diff --git a/tests/keys/encryptDecrypt.test.ts b/tests/keys/encryptDecrypt.test.ts index 65988197..7522901e 100644 --- a/tests/keys/encryptDecrypt.test.ts +++ b/tests/keys/encryptDecrypt.test.ts @@ -11,9 +11,9 @@ describe('encrypt-decrypt', () => { const logger = new Logger('encrypt-decrypt test', LogLevel.WARN, [ new StreamHandler(), ]); - let agentDir; - let agentPassword; - let agentClose; + let agentDir: string; + let agentPassword: string; + let agentClose: () => Promise; let agentStatus: StatusLive; beforeEach(async () => { ({ agentDir, agentPassword, agentClose, agentStatus } = @@ -48,8 +48,8 @@ describe('encrypt-decrypt', () => { }); }); test('encrypts data using NodeId', async () => { - const targetkeyPair = keysUtils.generateKeyPair(); - const targetNodeId = keysUtils.publicKeyToNodeId(targetkeyPair.publicKey); + const targetKeyPair = keysUtils.generateKeyPair(); + const targetNodeId = keysUtils.publicKeyToNodeId(targetKeyPair.publicKey); const dataPath = path.join(agentDir, 'data'); await fs.promises.writeFile(dataPath, 'abc', { @@ -78,14 +78,14 @@ describe('encrypt-decrypt', () => { }); const encrypted = JSON.parse(stdout).encryptedData; const decrypted = keysUtils.decryptWithPrivateKey( - targetkeyPair, + targetKeyPair, Buffer.from(encrypted, 'binary'), ); expect(decrypted?.toString()).toBe('abc'); }); test('encrypts data using JWK file', async () => { - const targetkeyPair = keysUtils.generateKeyPair(); - const publicJWK = keysUtils.publicKeyToJWK(targetkeyPair.publicKey); + const targetKeyPair = keysUtils.generateKeyPair(); + const publicJWK = keysUtils.publicKeyToJWK(targetKeyPair.publicKey); const dataPath = path.join(agentDir, 'data'); const jwkPath = path.join(agentDir, 'jwk'); @@ -109,7 +109,7 @@ describe('encrypt-decrypt', () => { }); const encrypted = JSON.parse(stdout).encryptedData; const decrypted = keysUtils.decryptWithPrivateKey( - targetkeyPair, + targetKeyPair, Buffer.from(encrypted, 'binary'), ); expect(decrypted?.toString()).toBe('abc'); diff --git a/tests/keys/keypair.test.ts b/tests/keys/keypair.test.ts index 3bdfa930..840877fd 100644 --- a/tests/keys/keypair.test.ts +++ b/tests/keys/keypair.test.ts @@ -5,9 +5,9 @@ describe('keypair', () => { const logger = new Logger('keypair test', LogLevel.WARN, [ new StreamHandler(), ]); - let agentDir; - let agentPassword; - let agentClose; + let agentDir: string; + let agentPassword: string; + let agentClose: () => Promise; beforeEach(async () => { ({ agentDir, agentPassword, agentClose } = await testUtils.setupTestAgent(logger)); diff --git a/tests/keys/password.test.ts b/tests/keys/password.test.ts index b6f85fab..bb568cbd 100644 --- a/tests/keys/password.test.ts +++ b/tests/keys/password.test.ts @@ -7,9 +7,9 @@ describe('password', () => { const logger = new Logger('password test', LogLevel.WARN, [ new StreamHandler(), ]); - let agentDir; - let agentPassword; - let agentClose; + let agentDir: string; + let agentPassword: string; + let agentClose: () => Promise; beforeEach(async () => { ({ agentDir, agentPassword, agentClose } = await testUtils.setupTestAgent(logger)); diff --git a/tests/keys/private.test.ts b/tests/keys/private.test.ts index 93f5d9c3..f7dc5020 100644 --- a/tests/keys/private.test.ts +++ b/tests/keys/private.test.ts @@ -5,9 +5,9 @@ describe('private', () => { const logger = new Logger('private test', LogLevel.WARN, [ new StreamHandler(), ]); - let agentDir; - let agentPassword; - let agentClose; + let agentDir: string; + let agentPassword: string; + let agentClose: () => Promise; beforeEach(async () => { ({ agentDir, agentPassword, agentClose } = await testUtils.setupTestAgent(logger)); diff --git a/tests/keys/public.test.ts b/tests/keys/public.test.ts index 93365791..ca45c55a 100644 --- a/tests/keys/public.test.ts +++ b/tests/keys/public.test.ts @@ -5,9 +5,9 @@ describe('public', () => { const logger = new Logger('public test', LogLevel.WARN, [ new StreamHandler(), ]); - let agentDir; - let agentPassword; - let agentClose; + let agentDir: string; + let agentPassword: string; + let agentClose: () => Promise; beforeEach(async () => { ({ agentDir, agentPassword, agentClose } = await testUtils.setupTestAgent(logger)); diff --git a/tests/keys/signVerify.test.ts b/tests/keys/signVerify.test.ts index 039b035f..011b40a6 100644 --- a/tests/keys/signVerify.test.ts +++ b/tests/keys/signVerify.test.ts @@ -12,9 +12,9 @@ describe('sign-verify', () => { const logger = new Logger('sign-verify test', LogLevel.WARN, [ new StreamHandler(), ]); - let agentDir; - let agentPassword; - let agentClose; + let agentDir: string; + let agentPassword: string; + let agentClose: () => Promise; let agentStatus: StatusLive; beforeEach(async () => { ({ agentDir, agentPassword, agentClose, agentStatus } = diff --git a/tests/nodes/find.test.ts b/tests/nodes/find.test.ts index b40b49cc..7b4540be 100644 --- a/tests/nodes/find.test.ts +++ b/tests/nodes/find.test.ts @@ -129,7 +129,7 @@ describe('find', () => { ); }); // FIXME: Bug with RPC, we can't respond after timeout since client timeout forces close. - test.skip( + test( 'fails to find an unknown node', async () => { const unknownNodeId = nodesUtils.decodeNodeId( @@ -158,7 +158,6 @@ describe('find', () => { unknownNodeId!, )}`, id: nodesUtils.encodeNodeId(unknownNodeId!), - address: [], }); }, globalThis.failedConnectionTimeout, diff --git a/tests/nodes/ping.test.ts b/tests/nodes/ping.test.ts index 93bf010b..c9e8cb56 100644 --- a/tests/nodes/ping.test.ts +++ b/tests/nodes/ping.test.ts @@ -83,8 +83,7 @@ describe('ping', () => { recursive: true, }); }); - // FIXME: skipped because problem with RPC processing messages after timeout - test.skip( + test( 'fails when pinging an offline node', async () => { const { exitCode, stdout, stderr } = await testUtils.pkStdio( @@ -112,8 +111,7 @@ describe('ping', () => { }, globalThis.failedConnectionTimeout, ); - // FIXME: skipped because problem with RPC processing messages after timeout - test.skip( + test( 'fails if node cannot be found', async () => { const fakeNodeId = nodesUtils.decodeNodeId( diff --git a/tests/notifications/sendReadClear.test.ts b/tests/notifications/sendReadClear.test.ts index aab51d3f..5bf85e8b 100644 --- a/tests/notifications/sendReadClear.test.ts +++ b/tests/notifications/sendReadClear.test.ts @@ -62,9 +62,9 @@ describe('send/read/claim', () => { test( 'sends, receives, and clears notifications', async () => { - let exitCode, stdout; + let exitCode: number, stdout: string; let readNotifications: Array; - // Add receiver to sender's node graph so it can be contacted + // Add receiver to sender's node graph, so it can be contacted ({ exitCode } = await testUtils.pkExec( [ 'nodes', @@ -82,7 +82,7 @@ describe('send/read/claim', () => { }, )); expect(exitCode).toBe(0); - // Add sender to receiver's node graph so it can be trusted + // Add sender to receiver's node graph, so it can be trusted ({ exitCode } = await testUtils.pkExec( [ 'nodes', @@ -176,7 +176,7 @@ describe('send/read/claim', () => { readNotifications = stdout .split('\n') .slice(undefined, -1) - .map(JSON.parse); + .map((v) => JSON.parse(v)); expect(readNotifications).toHaveLength(3); expect(readNotifications[0]).toMatchObject({ data: { @@ -220,7 +220,7 @@ describe('send/read/claim', () => { readNotifications = stdout .split('\n') .slice(undefined, -1) - .map(JSON.parse); + .map((v) => JSON.parse(v)); expect(readNotifications).toHaveLength(0); // Read notifications on reverse order ({ exitCode, stdout } = await testUtils.pkExec( @@ -237,7 +237,7 @@ describe('send/read/claim', () => { readNotifications = stdout .split('\n') .slice(undefined, -1) - .map(JSON.parse); + .map((v) => JSON.parse(v)); expect(readNotifications).toHaveLength(3); expect(readNotifications[0]).toMatchObject({ data: { @@ -281,7 +281,7 @@ describe('send/read/claim', () => { readNotifications = stdout .split('\n') .slice(undefined, -1) - .map(JSON.parse); + .map((v) => JSON.parse(v)); expect(readNotifications).toHaveLength(1); expect(readNotifications[0]).toMatchObject({ data: { @@ -293,13 +293,13 @@ describe('send/read/claim', () => { isRead: true, }); // Clear notifications - ({ exitCode } = await testUtils.pkExec(['notifications', 'clear'], { + await testUtils.pkExec(['notifications', 'clear'], { env: { PK_NODE_PATH: receiverAgentDir, PK_PASSWORD: receiverAgentPassword, }, cwd: receiverAgentDir, - })); + }); // Check there are no more notifications ({ exitCode, stdout } = await testUtils.pkExec( ['notifications', 'read', '--format', 'json'], @@ -315,7 +315,7 @@ describe('send/read/claim', () => { readNotifications = stdout .split('\n') .slice(undefined, -1) - .map(JSON.parse); + .map((v) => JSON.parse(v)); expect(readNotifications).toHaveLength(0); }, globalThis.defaultTimeout * 3, diff --git a/tests/utils/exec.ts b/tests/utils/exec.ts index 6f3635d4..d1785609 100644 --- a/tests/utils/exec.ts +++ b/tests/utils/exec.ts @@ -150,7 +150,7 @@ async function pk(args: Array): Promise { * Runs pk command functionally with mocked STDIO * Both stdout and stderr are the entire output including newlines * This can only be used serially, because the mocks it relies on are global singletons - * If it is used concurrently, the mocking side-effects can conflict + * If it is used concurrently, the mocking side effects can conflict */ async function pkStdio( args: Array = [], @@ -164,7 +164,7 @@ async function pkStdio( opts.cwd ?? (await fs.promises.mkdtemp(path.join(globalThis.tmpDir, 'polykey-test-'))); // Parse the arguments of process.stdout.write and process.stderr.write - const parseArgs = (args) => { + const parseArgs = (args: Array) => { const data = args[0]; if (typeof data === 'string') { return data; @@ -526,7 +526,7 @@ async function processExit( /** * Checks exit code and stderr against ErrorPolykey - * Errors should contain all of the errors in the expected error chain + * Errors should contain all the errors in the expected error chain * starting with the outermost error (excluding ErrorPolykeyRemote) * When using this function, the command must be run with --format=json */ diff --git a/tests/utils/utils.ts b/tests/utils/utils.ts index a51e0ad9..cd638469 100644 --- a/tests/utils/utils.ts +++ b/tests/utils/utils.ts @@ -12,7 +12,7 @@ function describeIf(condition: boolean) { function trackTimers() { const timerMap: Map = new Map(); const oldClearTimeout = globalThis.clearTimeout; - const newClearTimeout = (...args) => { + const newClearTimeout = (...args: Array) => { timerMap.delete(args[0]); // @ts-ignore: slight type mismatch oldClearTimeout(...args); @@ -23,7 +23,7 @@ function trackTimers() { const newSetTimeout = (handler: TimerHandler, timeout?: number) => { const prom = promise(); const stack = Error(); - const newCallback = async (...args) => { + const newCallback = async (...args: Array) => { // @ts-ignore: only expecting functions await handler(...args); prom.resolveP(); diff --git a/tests/vaults/vaults.test.ts b/tests/vaults/vaults.test.ts index a99b22f6..d5639d9c 100644 --- a/tests/vaults/vaults.test.ts +++ b/tests/vaults/vaults.test.ts @@ -741,7 +741,7 @@ describe('CLI vaults', () => { }); test.todo('test formatting of the output'); }); - // Fixme: tempermental problem with formatting the output. Fails sometimes due to an added space + // Fixme: temperamental problem with formatting the output. Fails sometimes due to an added space describe('commandScanNode', () => { test( 'should return the vaults names and ids of the remote vault',