@@ -7,12 +7,8 @@ import Session from '@/sessions/Session';
77import config from '@/config' ;
88import * as errors from '@/errors' ;
99import * as execUtils from '../../utils/exec' ;
10- import { testIf } from '../../utils' ;
10+ import * as testUtils from '../../utils' ;
1111import { 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