Skip to content

Commit

Permalink
fix: consolidated all spawning functions in tests/utils/exec.ts
Browse files Browse the repository at this point in the history
This is to key every major spawning command in one place in case we need to modify how we spawn using `ts-node`.
  • Loading branch information
tegefaulkes committed Jul 27, 2022
1 parent 25249f3 commit 882516f
Show file tree
Hide file tree
Showing 34 changed files with 571 additions and 543 deletions.
18 changes: 10 additions & 8 deletions tests/bin/agent/lock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { mocked } from 'jest-mock';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import Session from '@/sessions/Session';
import config from '@/config';
import * as testBinUtils from '../utils';
import * as execUtils from '../../utils/exec';
import { runTestIfPlatforms } from '../../utils';
import { globalRootKeyPems } from '../../fixtures/globalRootKeyPems';

Expand All @@ -18,22 +18,24 @@ describe('lock', () => {
let agentPassword: string;
let agentClose: () => Promise<void>;
beforeEach(async () => {
({ agentDir, agentPassword, agentClose } =
await testBinUtils.setupTestAgent(globalRootKeyPems[0], logger));
({ agentDir, agentPassword, agentClose } = await execUtils.setupTestAgent(
globalRootKeyPems[0],
logger,
));
});
afterEach(async () => {
await agentClose();
});
runTestIfPlatforms('docker')('lock deletes the session token', async () => {
await testBinUtils.pkStdio(
await execUtils.pkStdio(
['agent', 'unlock'],
{
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
agentDir,
);
const { exitCode } = await testBinUtils.pkStdio(
const { exitCode } = await execUtils.pkStdio(
['agent', 'lock'],
{
PK_NODE_PATH: agentDir,
Expand All @@ -57,7 +59,7 @@ describe('lock', () => {
mockedPrompts.mockImplementation(async (_opts: any) => {
return { password };
});
await testBinUtils.pkStdio(
await execUtils.pkStdio(
['agent', 'unlock'],
{
PK_NODE_PATH: agentDir,
Expand All @@ -66,15 +68,15 @@ describe('lock', () => {
agentDir,
);
// Session token is deleted
await testBinUtils.pkStdio(
await execUtils.pkStdio(
['agent', 'lock'],
{
PK_NODE_PATH: agentDir,
},
agentDir,
);
// Will prompt to reauthenticate
await testBinUtils.pkStdio(
await execUtils.pkStdio(
['agent', 'status'],
{
PK_NODE_PATH: agentDir,
Expand Down
26 changes: 14 additions & 12 deletions tests/bin/agent/lockall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import Session from '@/sessions/Session';
import config from '@/config';
import * as errors from '@/errors';
import * as testBinUtils from '../utils';
import * as execUtils from '../../utils/exec';
import { runTestIfPlatforms } from '../../utils';
import { globalRootKeyPems } from '../../fixtures/globalRootKeyPems';

Expand All @@ -24,24 +24,26 @@ describe('lockall', () => {
let agentPassword;
let agentClose;
beforeEach(async () => {
({ agentDir, agentPassword, agentClose } =
await testBinUtils.setupTestAgent(globalRootKeyPems[0], logger));
({ agentDir, agentPassword, agentClose } = await execUtils.setupTestAgent(
globalRootKeyPems[0],
logger,
));
});
afterEach(async () => {
await agentClose();
});
runTestIfPlatforms('docker')(
'lockall deletes the session token',
async () => {
await testBinUtils.pkStdio(
await execUtils.pkStdio(
['agent', 'unlock'],
{
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
agentDir,
);
const { exitCode } = await testBinUtils.pkStdio(
const { exitCode } = await execUtils.pkStdio(
['agent', 'lockall'],
{
PK_NODE_PATH: agentDir,
Expand All @@ -62,15 +64,15 @@ describe('lockall', () => {
'lockall ensures reauthentication is required',
async () => {
const password = agentPassword;
await testBinUtils.pkStdio(
await execUtils.pkStdio(
['agent', 'unlock'],
{
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
agentDir,
);
await testBinUtils.pkStdio(
await execUtils.pkStdio(
['agent', 'lockall'],
{
PK_NODE_PATH: agentDir,
Expand All @@ -82,7 +84,7 @@ describe('lockall', () => {
mockedPrompts.mockImplementation(async (_opts: any) => {
return { password };
});
await testBinUtils.pkStdio(
await execUtils.pkStdio(
['agent', 'status'],
{
PK_NODE_PATH: agentDir,
Expand All @@ -97,7 +99,7 @@ describe('lockall', () => {
runTestIfPlatforms('docker')(
'lockall causes old session tokens to fail',
async () => {
await testBinUtils.pkStdio(
await execUtils.pkStdio(
['agent', 'unlock'],
{
PK_NODE_PATH: agentDir,
Expand All @@ -112,7 +114,7 @@ describe('lockall', () => {
});
const token = await session.readToken();
await session.stop();
await testBinUtils.pkStdio(
await execUtils.pkStdio(
['agent', 'lockall'],
{
PK_NODE_PATH: agentDir,
Expand All @@ -121,15 +123,15 @@ describe('lockall', () => {
agentDir,
);
// Old token is invalid
const { exitCode, stderr } = await testBinUtils.pkStdio(
const { exitCode, stderr } = await execUtils.pkStdio(
['agent', 'status', '--format', 'json'],
{
PK_NODE_PATH: agentDir,
PK_TOKEN: token,
},
agentDir,
);
testBinUtils.expectProcessError(exitCode, stderr, [
execUtils.expectProcessError(exitCode, stderr, [
new errors.ErrorClientAuthDenied(),
]);
},
Expand Down
Loading

0 comments on commit 882516f

Please sign in to comment.