Skip to content

Commit

Permalink
Merge pull request #437 from MatrixAI/feature-conditional_testing_fix
Browse files Browse the repository at this point in the history
Standardise conditional testing fix
  • Loading branch information
CMCDragonkai authored Aug 8, 2022
2 parents 3c206c5 + 8ae818b commit 94ec1d2
Show file tree
Hide file tree
Showing 62 changed files with 2,544 additions and 2,406 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
"no-constant-condition": 0,
"no-useless-escape": 0,
"no-console": "error",
"no-restricted-globals": [
"error",
{
"name": "global",
"message": "Use `globalThis` instead"
}
],
"require-yield": 0,
"eqeqeq": ["error", "smart"],
"spaced-comment": [
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/GRPCClientAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe(GRPCClientAgent.name, () => {
serverHost: host,
serverPort: port,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await testAgentUtils.closeTestAgentClient(client);
await testAgentUtils.closeTestAgentServer(server);
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/service/nodesChainDataGet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('nodesClosestLocalNode', () => {
port: grpcServer.getPort(),
logger,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await grpcClient.destroy();
await grpcServer.stop();
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/service/nodesClosestLocalNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('nodesChainDataGet', () => {
port: grpcServer.getPort(),
logger,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await grpcClient.destroy();
await grpcServer.stop();
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/service/nodesCrossSignClaim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('nodesCrossSignClaim', () => {
port: grpcServer.getPort(),
logger,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await grpcClient.destroy();
await grpcServer.stop();
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/service/nodesHolePunchMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('nodesHolePunchMessage', () => {
port: grpcServer.getPort(),
logger,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await grpcClient.destroy();
await grpcServer.stop();
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/service/notificationsSend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('notificationsSend', () => {
port: grpcServer.getPort(),
logger,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await grpcClient.destroy();
await grpcServer.stop();
Expand Down
8 changes: 5 additions & 3 deletions tests/bin/agent/lock.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 execUtils from '../../utils/exec';
import { runTestIfPlatforms } from '../../utils';
import * as testUtils from '../../utils';
import { globalRootKeyPems } from '../../fixtures/globalRootKeyPems';

jest.mock('prompts');
Expand All @@ -26,7 +26,9 @@ describe('lock', () => {
afterEach(async () => {
await agentClose();
});
runTestIfPlatforms('docker')('lock deletes the session token', async () => {
testUtils.testIf(
testUtils.isTestPlatformEmpty || testUtils.isTestPlatformDocker,
)('lock deletes the session token', async () => {
await execUtils.pkStdio(
['agent', 'unlock'],
{
Expand All @@ -51,7 +53,7 @@ describe('lock', () => {
expect(await session.readToken()).toBeUndefined();
await session.stop();
});
runTestIfPlatforms()(
testUtils.testIf(testUtils.isTestPlatformEmpty)(
'lock ensures re-authentication is required',
async () => {
const password = agentPassword;
Expand Down
138 changes: 68 additions & 70 deletions tests/bin/agent/lockall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Session from '@/sessions/Session';
import config from '@/config';
import * as errors from '@/errors';
import * as execUtils from '../../utils/exec';
import { runTestIfPlatforms } from '../../utils';
import * as testUtils from '../../utils';
import { globalRootKeyPems } from '../../fixtures/globalRootKeyPems';

/**
Expand All @@ -32,35 +32,34 @@ describe('lockall', () => {
afterEach(async () => {
await agentClose();
});
runTestIfPlatforms('docker')(
'lockall deletes the session token',
async () => {
await execUtils.pkStdio(
['agent', 'unlock'],
{
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
agentDir,
);
const { exitCode } = await execUtils.pkStdio(
['agent', 'lockall'],
{
PK_NODE_PATH: agentDir,
},
agentDir,
);
expect(exitCode).toBe(0);
const session = await Session.createSession({
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
fs,
logger,
});
expect(await session.readToken()).toBeUndefined();
await session.stop();
},
);
runTestIfPlatforms()(
testUtils.testIf(
testUtils.isTestPlatformEmpty || testUtils.isTestPlatformDocker,
)('lockall deletes the session token', async () => {
await execUtils.pkStdio(
['agent', 'unlock'],
{
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
agentDir,
);
const { exitCode } = await execUtils.pkStdio(
['agent', 'lockall'],
{
PK_NODE_PATH: agentDir,
},
agentDir,
);
expect(exitCode).toBe(0);
const session = await Session.createSession({
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
fs,
logger,
});
expect(await session.readToken()).toBeUndefined();
await session.stop();
});
testUtils.testIf(testUtils.isTestPlatformEmpty)(
'lockall ensures reauthentication is required',
async () => {
const password = agentPassword;
Expand Down Expand Up @@ -96,44 +95,43 @@ describe('lockall', () => {
mockedPrompts.mockClear();
},
);
runTestIfPlatforms('docker')(
'lockall causes old session tokens to fail',
async () => {
await execUtils.pkStdio(
['agent', 'unlock'],
{
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
agentDir,
);
const session = await Session.createSession({
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
fs,
logger,
});
const token = await session.readToken();
await session.stop();
await execUtils.pkStdio(
['agent', 'lockall'],
{
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
agentDir,
);
// Old token is invalid
const { exitCode, stderr } = await execUtils.pkStdio(
['agent', 'status', '--format', 'json'],
{
PK_NODE_PATH: agentDir,
PK_TOKEN: token,
},
agentDir,
);
execUtils.expectProcessError(exitCode, stderr, [
new errors.ErrorClientAuthDenied(),
]);
},
);
testUtils.testIf(
testUtils.isTestPlatformEmpty || testUtils.isTestPlatformDocker,
)('lockall causes old session tokens to fail', async () => {
await execUtils.pkStdio(
['agent', 'unlock'],
{
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
agentDir,
);
const session = await Session.createSession({
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
fs,
logger,
});
const token = await session.readToken();
await session.stop();
await execUtils.pkStdio(
['agent', 'lockall'],
{
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
agentDir,
);
// Old token is invalid
const { exitCode, stderr } = await execUtils.pkStdio(
['agent', 'status', '--format', 'json'],
{
PK_NODE_PATH: agentDir,
PK_TOKEN: token,
},
agentDir,
);
execUtils.expectProcessError(exitCode, stderr, [
new errors.ErrorClientAuthDenied(),
]);
});
});
Loading

0 comments on commit 94ec1d2

Please sign in to comment.