Skip to content

Commit

Permalink
fixin: unlock.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Jul 26, 2022
1 parent e78a1d2 commit fd6cea2
Showing 1 changed file with 44 additions and 41 deletions.
85 changes: 44 additions & 41 deletions tests/bin/agent/unlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,48 @@ describe('unlock', () => {
afterAll(async () => {
await globalAgentClose();
});
runTestIfPlatforms('linux', 'docker')('unlock acquires session token', async () => {
// Fresh session, to delete the token
const session = await Session.createSession({
sessionTokenPath: path.join(globalAgentDir, config.defaults.tokenBase),
fs,
logger,
fresh: true,
});
let exitCode, stdout;
({ exitCode } = await testBinUtils.pkStdioSwitch(global.testCmd)(
['agent', 'unlock'],
{
PK_NODE_PATH: globalAgentDir,
PK_PASSWORD: globalAgentPassword,
},
globalAgentDir,
));
expect(exitCode).toBe(0);
// Run command without password
({ exitCode, stdout } = await testBinUtils.pkStdioSwitch(global.testCmd)(
['agent', 'status', '--format', 'json'],
{
PK_NODE_PATH: globalAgentDir,
},
globalAgentDir,
));
expect(exitCode).toBe(0);
expect(JSON.parse(stdout)).toMatchObject({ status: 'LIVE' });
// Run command with PK_TOKEN
({ exitCode, stdout } = await testBinUtils.pkStdioSwitch(global.testCmd)(
['agent', 'status', '--format', 'json'],
{
PK_NODE_PATH: globalAgentDir,
PK_TOKEN: await session.readToken(),
},
globalAgentDir,
));
expect(exitCode).toBe(0);
expect(JSON.parse(stdout)).toMatchObject({ status: 'LIVE' });
await session.stop();
});
runTestIfPlatforms('linux', 'docker')(
'unlock acquires session token',
async () => {
// Fresh session, to delete the token
const session = await Session.createSession({
sessionTokenPath: path.join(globalAgentDir, config.defaults.tokenBase),
fs,
logger,
fresh: true,
});
let exitCode, stdout;
({ exitCode } = await testBinUtils.pkStdioSwitch(global.testCmd)(
['agent', 'unlock'],
{
PK_NODE_PATH: globalAgentDir,
PK_PASSWORD: globalAgentPassword,
},
globalAgentDir,
));
expect(exitCode).toBe(0);
// Run command without password
({ exitCode, stdout } = await testBinUtils.pkStdioSwitch(global.testCmd)(
['agent', 'status', '--format', 'json'],
{
PK_NODE_PATH: globalAgentDir,
},
globalAgentDir,
));
expect(exitCode).toBe(0);
expect(JSON.parse(stdout)).toMatchObject({ status: 'LIVE' });
// Run command with PK_TOKEN
({ exitCode, stdout } = await testBinUtils.pkStdioSwitch(global.testCmd)(
['agent', 'status', '--format', 'json'],
{
PK_NODE_PATH: globalAgentDir,
PK_TOKEN: await session.readToken(),
},
globalAgentDir,
));
expect(exitCode).toBe(0);
expect(JSON.parse(stdout)).toMatchObject({ status: 'LIVE' });
await session.stop();
},
);
});

0 comments on commit fd6cea2

Please sign in to comment.