[8.x] [ResponseOps][Connectors] throw error for empty correlationId or incidentId (#217639) (#218295)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps][Connectors] throw error for empty correlationId or
incidentId (#217639)](https://github.com/elastic/kibana/pull/217639)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Janki
Salvi","email":"117571355+js-jankisalvi@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-04-15T15:10:16Z","message":"[ResponseOps][Connectors]
throw error for empty correlationId or incidentId (#217639)\n\n##
Summary\n\nResolves
https://github.com/elastic/kibana/issues/217004\n\n\n### Checklist\n\n-
[x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios","sha":"0aeadb80cae3b64b8044d0a3f5da916d849cc8a6","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","Feature:Actions/ConnectorTypes","backport:version","v9.1.0","v8.19.0"],"title":"[ResponseOps][Connectors]
throw error for empty correlationId or
incidentId","number":217639,"url":"https://github.com/elastic/kibana/pull/217639","mergeCommit":{"message":"[ResponseOps][Connectors]
throw error for empty correlationId or incidentId (#217639)\n\n##
Summary\n\nResolves
https://github.com/elastic/kibana/issues/217004\n\n\n### Checklist\n\n-
[x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios","sha":"0aeadb80cae3b64b8044d0a3f5da916d849cc8a6"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217639","number":217639,"mergeCommit":{"message":"[ResponseOps][Connectors]
throw error for empty correlationId or incidentId (#217639)\n\n##
Summary\n\nResolves
https://github.com/elastic/kibana/issues/217004\n\n\n### Checklist\n\n-
[x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios","sha":"0aeadb80cae3b64b8044d0a3f5da916d849cc8a6"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2025-04-15 18:56:12 +02:00 committed by GitHub
parent 0e10b2ea53
commit a7c7522b6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 63 additions and 2 deletions

View file

@ -530,6 +530,12 @@ describe('ServiceNow service', () => {
'There is an issue with your Service Now Instance. Please check Developer instance.'
);
});
test('it should throw an error when incident id is empty', async () => {
await expect(service.getIncident('')).rejects.toThrow(
'[Action][ServiceNow]: Unable to get incident with id . Error: Incident id is empty. Reason: unknown: errorResponse was null'
);
});
});
describe('getIncidentByCorrelationId', () => {
@ -605,13 +611,19 @@ describe('ServiceNow service', () => {
);
});
test('it should throw an error when correlation id is empty', async () => {
await expect(service.getIncidentByCorrelationId('')).rejects.toThrow(
'[Action][ServiceNow]: Unable to get incident by correlation ID . Error: Correlation ID is empty. Reason: unknown: errorResponse was null'
);
});
test('it should throw an error when instance is not alive', async () => {
requestMock.mockImplementationOnce(() => ({
status: 200,
data: {},
request: { connection: { servername: 'Developer instance' } },
}));
await expect(service.getIncident('1')).rejects.toThrow(
await expect(service.getIncidentByCorrelationId('custom_correlation_id')).rejects.toThrow(
'There is an issue with your Service Now Instance. Please check Developer instance.'
);
});
@ -715,7 +727,10 @@ describe('ServiceNow service', () => {
requestMock.mockImplementation(() => ({ data: getImportSetAPIError() }));
await expect(
service.createIncident({
incident: { short_description: 'title', description: 'desc' } as ServiceNowITSMIncident,
incident: {
short_description: 'title',
description: 'desc',
} as ServiceNowITSMIncident,
})
).rejects.toThrow(
'[Action][ServiceNow]: Unable to create incident. Error: An error has occurred while importing the incident Reason: unknown'
@ -1187,6 +1202,22 @@ describe('ServiceNow service', () => {
);
});
test('it should throw an error when correlationId is empty', async () => {
await expect(
service.closeIncident({ incidentId: null, correlationId: ' ' })
).rejects.toThrow(
'[Action][ServiceNow]: Unable to close incident. Error: [Action][ServiceNow]: Unable to get incident by correlation ID . Error: Correlation ID is empty. Reason: unknown: errorResponse was null Reason: unknown: errorResponse was null'
);
});
test('it should throw an error when incidentId is empty', async () => {
await expect(
service.closeIncident({ incidentId: ' ', correlationId: null })
).rejects.toThrow(
'[Action][ServiceNow]: Unable to close incident. Error: [Action][ServiceNow]: Unable to get incident with id . Error: Incident id is empty. Reason: unknown: errorResponse was null Reason: unknown: errorResponse was null'
);
});
test('it should throw an error when the no incidents found with given incidentId ', async () => {
const axiosError = {
message: 'Request failed with status code 404',
@ -1379,6 +1410,30 @@ describe('ServiceNow service', () => {
expect(res?.url).toEqual('https://example.com/nav_to.do?uri=sn_si_incident.do?sys_id=1');
});
test('it should throw an error when the incidentId and correlationId are null', async () => {
await expect(
service.closeIncident({ incidentId: null, correlationId: null })
).rejects.toThrow(
'[Action][ServiceNow]: Unable to close incident. Error: No correlationId or incidentId found. Reason: unknown: errorResponse was null'
);
});
test('it should throw an error when correlationId is empty', async () => {
await expect(
service.closeIncident({ incidentId: null, correlationId: ' ' })
).rejects.toThrow(
'[Action][ServiceNow]: Unable to close incident. Error: [Action][ServiceNow]: Unable to get incident by correlation ID . Error: Correlation ID is empty. Reason: unknown: errorResponse was null Reason: unknown: errorResponse was null'
);
});
test('it should throw an error when incidentId is empty', async () => {
await expect(
service.closeIncident({ incidentId: ' ', correlationId: null })
).rejects.toThrow(
'[Action][ServiceNow]: Unable to close incident. Error: [Action][ServiceNow]: Unable to get incident with id . Error: Incident id is empty. Reason: unknown: errorResponse was null Reason: unknown: errorResponse was null'
);
});
});
});

View file

@ -157,6 +157,9 @@ export const createExternalService: ServiceFactory = ({
const getIncident = async (id: string): Promise<ServiceNowIncident> => {
try {
if (id?.trim() === '') {
throw new Error('Incident id is empty.');
}
const res = await request({
axios: axiosInstance,
url: `${tableApiIncidentUrl}/${id}`,
@ -273,6 +276,9 @@ export const createExternalService: ServiceFactory = ({
correlationId: string
): Promise<ServiceNowIncident | null> => {
try {
if (correlationId?.trim() === '') {
throw new Error('Correlation ID is empty.');
}
const res = await request({
axios: axiosInstance,
url: getIncidentByCorrelationIdUrl(correlationId),