Skip to content

Commit

Permalink
fix: cira disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
madhavilosetty-intel committed Dec 5, 2024
1 parent 4fe1451 commit 41de36e
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 38 deletions.
57 changes: 44 additions & 13 deletions src/stateMachines/ciraConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ jest.unstable_mockModule('./common.js', () => ({

const { CIRAConfiguration, MPSType } = await import('./ciraConfiguration.js')

const pullRemoteAccessPolicyAppliesToMPSResponse = {
Envelope: {
Body: {
PullResponse: {
Items: {
AMT_RemoteAccessPolicyAppliesToMPS: [
{
PolicySet: {
ReferenceParameters: {
SelectorSet: { Selector: [{ $: { Name: 'PolicyRuleName' }, _: 'TestPolicy1' }] }
}
}
},
{
PolicySet: {
ReferenceParameters: {
SelectorSet: { Selector: [{ $: { Name: 'PolicyRuleName' }, _: 'TestPolicy2' }] }
}
}
}
]
}
}
}
}
}

describe('CIRA Configuration State Machine', () => {
const clientId = randomUUID()
const httpHandler = new HttpHandler()
Expand Down Expand Up @@ -83,7 +110,8 @@ describe('CIRA Configuration State Machine', () => {
message: null,
ciraConfig: null,
statusMessage: '',
privateCerts: []
privateCerts: [],
remoteAccessPolicies: [],
}
machineConfig = {
actors: {
Expand All @@ -101,7 +129,7 @@ describe('CIRA Configuration State Machine', () => {
enumerateRemoteAccessPolicyAppliesToMPS: fromPromise(
async ({ input }) => await Promise.resolve(wsmanEnumerationResponse)
),
pullRemoteAccessPolicyAppliesToMPS: fromPromise(async ({ input }) => await Promise.resolve({})),
pullRemoteAccessPolicyAppliesToMPS: fromPromise(async ({ input }) => await Promise.resolve(pullRemoteAccessPolicyAppliesToMPSResponse)),
putRemoteAccessPolicyAppliesToMPS: fromPromise(async ({ input }) => await Promise.resolve({})),
userInitiatedConnectionService: fromPromise(
async ({ input }) =>
Expand Down Expand Up @@ -129,9 +157,11 @@ describe('CIRA Configuration State Machine', () => {
'ENUMERATE_MANAGEMENT_PRESENCE_REMOTE_SAP',
'PULL_MANAGEMENT_PRESENCE_REMOTE_SAP',
'ADD_REMOTE_ACCESS_POLICY_RULE',
'ADD_USER_INITIATED_REMOTE_ACCESS_POLICY_RULE',
'ENUMERATE_REMOTE_ACCESS_POLICY_APPLIESTOMPS',
'PULL_REMOTE_ACCESS_POLICY_APPLIESTOMPS',
'PUT_REMOTE_ACCESS_POLICY_APPLIESTOMPS',
'CHECK_REMOTE_ACCESS_POLICY_APPLIESTOMPS',
'USER_INITIATED_CONNECTION_SERVICE',
'GET_ENVIRONMENT_DETECTION_SETTINGS',
'PUT_ENVIRONMENT_DETECTION_SETTINGS',
Expand All @@ -144,13 +174,15 @@ describe('CIRA Configuration State Machine', () => {
}
const ciraConfigurationService = createActor(mockCiraConfigurationMachine, { input: machineContext })
ciraConfigurationService.subscribe((state) => {
const expected = flowStates[currentStateIndex++]
const actual = state.value as string
expect(actual).toEqual(expected)
if (state.matches('SUCCESS') || state.matches('FAILURE') || currentStateIndex === flowStates.length) {
const status = devices[clientId].status.CIRAConnection
expect(status).toEqual('Configured')
done()
if (state.value) {
const expected = flowStates[currentStateIndex++]
const actual = state.value as string
expect(actual).toEqual(expected)
if (state.matches('SUCCESS') || state.matches('FAILURE') || currentStateIndex === flowStates.length) {
const status = devices[clientId].status.CIRAConnection
expect(status).toEqual('Configured')
done()
}
}
})
ciraConfigurationService.start()
Expand Down Expand Up @@ -274,9 +306,9 @@ describe('CIRA Configuration State Machine', () => {
expect(loggerSpy).toHaveBeenCalled()
})
it('should send wsman on call to putRemoteAccessPolicyAppliesToMPS', async () => {
machineContext.message = {
Envelope: { Body: { PullResponse: { Items: { AMT_RemoteAccessPolicyAppliesToMPS: MPSType } } } }
}
machineContext.message = pullRemoteAccessPolicyAppliesToMPSResponse
machineContext.remoteAccessPolicies =
machineContext.message.Envelope.Body.PullResponse.Items.AMT_RemoteAccessPolicyAppliesToMPS
await ciraStateMachineImpl.putRemoteAccessPolicyAppliesToMPS({ input: machineContext })
expect(invokeWsmanCallSpy).toHaveBeenCalled()
})
Expand All @@ -296,7 +328,6 @@ describe('CIRA Configuration State Machine', () => {

describe('send wsman message to add MPS server and certificate', () => {
beforeEach(() => {
// spoof getCiraConfiguration
machineContext.ciraConfig = ciraConfig
})
it('should send wsman message to add Trusted Root Certificate', async () => {
Expand Down
Loading

0 comments on commit 41de36e

Please # to comment.