-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Case] ServiceNow SIR Connector (#88655)
Co-authored-by: Xavier Mouligneau <189600+XavierM@users.noreply.github.com>
- Loading branch information
Showing
174 changed files
with
4,847 additions
and
2,824 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
x-pack/plugins/actions/server/builtin_action_types/servicenow/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { actionsMock } from '../../mocks'; | ||
import { createActionTypeRegistry } from '../index.test'; | ||
import { | ||
ServiceNowPublicConfigurationType, | ||
ServiceNowSecretConfigurationType, | ||
ExecutorParams, | ||
PushToServiceResponse, | ||
} from './types'; | ||
import { | ||
ServiceNowActionType, | ||
ServiceNowITSMActionTypeId, | ||
ServiceNowSIRActionTypeId, | ||
ServiceNowActionTypeExecutorOptions, | ||
} from '.'; | ||
import { api } from './api'; | ||
|
||
jest.mock('./api', () => ({ | ||
api: { | ||
getChoices: jest.fn(), | ||
getFields: jest.fn(), | ||
getIncident: jest.fn(), | ||
handshake: jest.fn(), | ||
pushToService: jest.fn(), | ||
}, | ||
})); | ||
|
||
const services = actionsMock.createServices(); | ||
|
||
describe('ServiceNow', () => { | ||
const config = { apiUrl: 'https://instance.com' }; | ||
const secrets = { username: 'username', password: 'password' }; | ||
const params = { | ||
subAction: 'pushToService', | ||
subActionParams: { | ||
incident: { | ||
short_description: 'An incident', | ||
description: 'This is serious', | ||
}, | ||
}, | ||
}; | ||
|
||
beforeEach(() => { | ||
(api.pushToService as jest.Mock).mockResolvedValue({ id: 'some-id' }); | ||
}); | ||
|
||
describe('ServiceNow ITSM', () => { | ||
let actionType: ServiceNowActionType; | ||
|
||
beforeAll(() => { | ||
const { actionTypeRegistry } = createActionTypeRegistry(); | ||
actionType = actionTypeRegistry.get< | ||
ServiceNowPublicConfigurationType, | ||
ServiceNowSecretConfigurationType, | ||
ExecutorParams, | ||
PushToServiceResponse | {} | ||
>(ServiceNowITSMActionTypeId); | ||
}); | ||
|
||
describe('execute()', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('it pass the correct comment field key', async () => { | ||
const actionId = 'some-action-id'; | ||
const executorOptions = ({ | ||
actionId, | ||
config, | ||
secrets, | ||
params, | ||
services, | ||
} as unknown) as ServiceNowActionTypeExecutorOptions; | ||
await actionType.executor(executorOptions); | ||
expect((api.pushToService as jest.Mock).mock.calls[0][0].commentFieldKey).toBe('comments'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('ServiceNow SIR', () => { | ||
let actionType: ServiceNowActionType; | ||
|
||
beforeAll(() => { | ||
const { actionTypeRegistry } = createActionTypeRegistry(); | ||
actionType = actionTypeRegistry.get< | ||
ServiceNowPublicConfigurationType, | ||
ServiceNowSecretConfigurationType, | ||
ExecutorParams, | ||
PushToServiceResponse | {} | ||
>(ServiceNowSIRActionTypeId); | ||
}); | ||
|
||
describe('execute()', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('it pass the correct comment field key', async () => { | ||
const actionId = 'some-action-id'; | ||
const executorOptions = ({ | ||
actionId, | ||
config, | ||
secrets, | ||
params, | ||
services, | ||
} as unknown) as ServiceNowActionTypeExecutorOptions; | ||
await actionType.executor(executorOptions); | ||
expect((api.pushToService as jest.Mock).mock.calls[0][0].commentFieldKey).toBe( | ||
'work_notes' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.