Skip to content

Commit 610fe52

Browse files
committed
test: importing test utils as testUtils
1 parent 35dce98 commit 610fe52

36 files changed

Lines changed: 2220 additions & 2139 deletions

tests/bin/agent/lock.test.ts

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
66
import Session from '@/sessions/Session';
77
import config from '@/config';
88
import * as execUtils from '../../utils/exec';
9-
import { testIf } from '../../utils';
9+
import * as testUtils from '../../utils';
1010
import { globalRootKeyPems } from '../../fixtures/globalRootKeyPems';
11-
import {
12-
isTestPlatformEmpty,
13-
isTestPlatformDocker,
14-
} from '../../utils/platform';
1511

1612
jest.mock('prompts');
1713
const mockedPrompts = mocked(prompts.prompt);
@@ -30,35 +26,34 @@ describe('lock', () => {
3026
afterEach(async () => {
3127
await agentClose();
3228
});
33-
testIf(isTestPlatformEmpty || isTestPlatformDocker)(
34-
'lock deletes the session token',
35-
async () => {
36-
await execUtils.pkStdio(
37-
['agent', 'unlock'],
38-
{
39-
PK_NODE_PATH: agentDir,
40-
PK_PASSWORD: agentPassword,
41-
},
42-
agentDir,
43-
);
44-
const { exitCode } = await execUtils.pkStdio(
45-
['agent', 'lock'],
46-
{
47-
PK_NODE_PATH: agentDir,
48-
},
49-
agentDir,
50-
);
51-
expect(exitCode).toBe(0);
52-
const session = await Session.createSession({
53-
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
54-
fs,
55-
logger,
56-
});
57-
expect(await session.readToken()).toBeUndefined();
58-
await session.stop();
59-
},
60-
);
61-
testIf(isTestPlatformEmpty)(
29+
testUtils.testIf(
30+
testUtils.isTestPlatformEmpty || testUtils.isTestPlatformDocker,
31+
)('lock deletes the session token', async () => {
32+
await execUtils.pkStdio(
33+
['agent', 'unlock'],
34+
{
35+
PK_NODE_PATH: agentDir,
36+
PK_PASSWORD: agentPassword,
37+
},
38+
agentDir,
39+
);
40+
const { exitCode } = await execUtils.pkStdio(
41+
['agent', 'lock'],
42+
{
43+
PK_NODE_PATH: agentDir,
44+
},
45+
agentDir,
46+
);
47+
expect(exitCode).toBe(0);
48+
const session = await Session.createSession({
49+
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
50+
fs,
51+
logger,
52+
});
53+
expect(await session.readToken()).toBeUndefined();
54+
await session.stop();
55+
});
56+
testUtils.testIf(testUtils.isTestPlatformEmpty)(
6257
'lock ensures re-authentication is required',
6358
async () => {
6459
const password = agentPassword;

tests/bin/agent/lockall.test.ts

Lines changed: 68 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ import Session from '@/sessions/Session';
77
import config from '@/config';
88
import * as errors from '@/errors';
99
import * as execUtils from '../../utils/exec';
10-
import { testIf } from '../../utils';
10+
import * as testUtils from '../../utils';
1111
import { globalRootKeyPems } from '../../fixtures/globalRootKeyPems';
12-
import {
13-
isTestPlatformEmpty,
14-
isTestPlatformDocker,
15-
} from '../../utils/platform';
1612

1713
/**
1814
* Mock prompts module which is used prompt for password
@@ -36,35 +32,34 @@ describe('lockall', () => {
3632
afterEach(async () => {
3733
await agentClose();
3834
});
39-
testIf(isTestPlatformEmpty || isTestPlatformDocker)(
40-
'lockall deletes the session token',
41-
async () => {
42-
await execUtils.pkStdio(
43-
['agent', 'unlock'],
44-
{
45-
PK_NODE_PATH: agentDir,
46-
PK_PASSWORD: agentPassword,
47-
},
48-
agentDir,
49-
);
50-
const { exitCode } = await execUtils.pkStdio(
51-
['agent', 'lockall'],
52-
{
53-
PK_NODE_PATH: agentDir,
54-
},
55-
agentDir,
56-
);
57-
expect(exitCode).toBe(0);
58-
const session = await Session.createSession({
59-
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
60-
fs,
61-
logger,
62-
});
63-
expect(await session.readToken()).toBeUndefined();
64-
await session.stop();
65-
},
66-
);
67-
testIf(isTestPlatformEmpty)(
35+
testUtils.testIf(
36+
testUtils.isTestPlatformEmpty || testUtils.isTestPlatformDocker,
37+
)('lockall deletes the session token', async () => {
38+
await execUtils.pkStdio(
39+
['agent', 'unlock'],
40+
{
41+
PK_NODE_PATH: agentDir,
42+
PK_PASSWORD: agentPassword,
43+
},
44+
agentDir,
45+
);
46+
const { exitCode } = await execUtils.pkStdio(
47+
['agent', 'lockall'],
48+
{
49+
PK_NODE_PATH: agentDir,
50+
},
51+
agentDir,
52+
);
53+
expect(exitCode).toBe(0);
54+
const session = await Session.createSession({
55+
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
56+
fs,
57+
logger,
58+
});
59+
expect(await session.readToken()).toBeUndefined();
60+
await session.stop();
61+
});
62+
testUtils.testIf(testUtils.isTestPlatformEmpty)(
6863
'lockall ensures reauthentication is required',
6964
async () => {
7065
const password = agentPassword;
@@ -100,44 +95,43 @@ describe('lockall', () => {
10095
mockedPrompts.mockClear();
10196
},
10297
);
103-
testIf(isTestPlatformEmpty || isTestPlatformDocker)(
104-
'lockall causes old session tokens to fail',
105-
async () => {
106-
await execUtils.pkStdio(
107-
['agent', 'unlock'],
108-
{
109-
PK_NODE_PATH: agentDir,
110-
PK_PASSWORD: agentPassword,
111-
},
112-
agentDir,
113-
);
114-
const session = await Session.createSession({
115-
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
116-
fs,
117-
logger,
118-
});
119-
const token = await session.readToken();
120-
await session.stop();
121-
await execUtils.pkStdio(
122-
['agent', 'lockall'],
123-
{
124-
PK_NODE_PATH: agentDir,
125-
PK_PASSWORD: agentPassword,
126-
},
127-
agentDir,
128-
);
129-
// Old token is invalid
130-
const { exitCode, stderr } = await execUtils.pkStdio(
131-
['agent', 'status', '--format', 'json'],
132-
{
133-
PK_NODE_PATH: agentDir,
134-
PK_TOKEN: token,
135-
},
136-
agentDir,
137-
);
138-
execUtils.expectProcessError(exitCode, stderr, [
139-
new errors.ErrorClientAuthDenied(),
140-
]);
141-
},
142-
);
98+
testUtils.testIf(
99+
testUtils.isTestPlatformEmpty || testUtils.isTestPlatformDocker,
100+
)('lockall causes old session tokens to fail', async () => {
101+
await execUtils.pkStdio(
102+
['agent', 'unlock'],
103+
{
104+
PK_NODE_PATH: agentDir,
105+
PK_PASSWORD: agentPassword,
106+
},
107+
agentDir,
108+
);
109+
const session = await Session.createSession({
110+
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
111+
fs,
112+
logger,
113+
});
114+
const token = await session.readToken();
115+
await session.stop();
116+
await execUtils.pkStdio(
117+
['agent', 'lockall'],
118+
{
119+
PK_NODE_PATH: agentDir,
120+
PK_PASSWORD: agentPassword,
121+
},
122+
agentDir,
123+
);
124+
// Old token is invalid
125+
const { exitCode, stderr } = await execUtils.pkStdio(
126+
['agent', 'status', '--format', 'json'],
127+
{
128+
PK_NODE_PATH: agentDir,
129+
PK_TOKEN: token,
130+
},
131+
agentDir,
132+
);
133+
execUtils.expectProcessError(exitCode, stderr, [
134+
new errors.ErrorClientAuthDenied(),
135+
]);
136+
});
143137
});

0 commit comments

Comments
 (0)