mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[SIEM][Detection Engine] Fixes return codes where some were rule_id instead of id (#58192)
## Summary Fixes some return error codes where they were `rule_id` when they should have been `id` - [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios
This commit is contained in:
parent
d18b21be48
commit
5646412c53
8 changed files with 72 additions and 26 deletions
|
@ -168,7 +168,7 @@ describe('import_rules_route', () => {
|
|||
message: 'Unexpected token : in JSON at position 8',
|
||||
status_code: 400,
|
||||
},
|
||||
rule_id: '(unknown)',
|
||||
rule_id: '(unknown id)',
|
||||
},
|
||||
],
|
||||
success: false,
|
||||
|
@ -287,7 +287,7 @@ describe('import_rules_route', () => {
|
|||
message: 'Unexpected token : in JSON at position 8',
|
||||
status_code: 400,
|
||||
},
|
||||
rule_id: '(unknown)',
|
||||
rule_id: '(unknown id)',
|
||||
},
|
||||
],
|
||||
success: false,
|
||||
|
|
|
@ -93,7 +93,6 @@ export const createImportRulesRoute = (server: ServerFacade): Hapi.ServerRoute =
|
|||
// early with the error and an (unknown) for the ruleId
|
||||
resolve(
|
||||
createBulkErrorObject({
|
||||
ruleId: '(unknown)',
|
||||
statusCode: 400,
|
||||
message: parsedRule.message,
|
||||
})
|
||||
|
|
|
@ -794,10 +794,20 @@ describe('utils', () => {
|
|||
});
|
||||
|
||||
describe('getIdBulkError', () => {
|
||||
test('outputs message about id and rule_id not being found if both are not null', () => {
|
||||
const error = getIdBulkError({ id: '123', ruleId: '456' });
|
||||
const expected: BulkError = {
|
||||
id: '123',
|
||||
rule_id: '456',
|
||||
error: { message: 'id: "123" and rule_id: "456" not found', status_code: 404 },
|
||||
};
|
||||
expect(error).toEqual(expected);
|
||||
});
|
||||
|
||||
test('outputs message about id not being found if only id is defined and ruleId is undefined', () => {
|
||||
const error = getIdBulkError({ id: '123', ruleId: undefined });
|
||||
const expected: BulkError = {
|
||||
rule_id: '123',
|
||||
id: '123',
|
||||
error: { message: 'id: "123" not found', status_code: 404 },
|
||||
};
|
||||
expect(error).toEqual(expected);
|
||||
|
@ -806,7 +816,7 @@ describe('utils', () => {
|
|||
test('outputs message about id not being found if only id is defined and ruleId is null', () => {
|
||||
const error = getIdBulkError({ id: '123', ruleId: null });
|
||||
const expected: BulkError = {
|
||||
rule_id: '123',
|
||||
id: '123',
|
||||
error: { message: 'id: "123" not found', status_code: 404 },
|
||||
};
|
||||
expect(error).toEqual(expected);
|
||||
|
|
|
@ -62,9 +62,16 @@ export const getIdBulkError = ({
|
|||
id: string | undefined | null;
|
||||
ruleId: string | undefined | null;
|
||||
}): BulkError => {
|
||||
if (id != null) {
|
||||
if (id != null && ruleId != null) {
|
||||
return createBulkErrorObject({
|
||||
ruleId: id,
|
||||
id,
|
||||
ruleId,
|
||||
statusCode: 404,
|
||||
message: `id: "${id}" and rule_id: "${ruleId}" not found`,
|
||||
});
|
||||
} else if (id != null) {
|
||||
return createBulkErrorObject({
|
||||
id,
|
||||
statusCode: 404,
|
||||
message: `id: "${id}" not found`,
|
||||
});
|
||||
|
@ -76,7 +83,6 @@ export const getIdBulkError = ({
|
|||
});
|
||||
} else {
|
||||
return createBulkErrorObject({
|
||||
ruleId: '(unknown id)',
|
||||
statusCode: 404,
|
||||
message: `id or rule_id should have been defined`,
|
||||
});
|
||||
|
|
|
@ -44,7 +44,8 @@ export const transformError = (err: Error & { statusCode?: number }): OutputErro
|
|||
};
|
||||
|
||||
export interface BulkError {
|
||||
rule_id: string;
|
||||
id?: string;
|
||||
rule_id?: string;
|
||||
error: {
|
||||
status_code: number;
|
||||
message: string;
|
||||
|
@ -53,24 +54,54 @@ export interface BulkError {
|
|||
|
||||
export const createBulkErrorObject = ({
|
||||
ruleId,
|
||||
id,
|
||||
statusCode,
|
||||
message,
|
||||
}: {
|
||||
ruleId: string;
|
||||
ruleId?: string;
|
||||
id?: string;
|
||||
statusCode: number;
|
||||
message: string;
|
||||
}): BulkError => {
|
||||
return {
|
||||
rule_id: ruleId,
|
||||
error: {
|
||||
status_code: statusCode,
|
||||
message,
|
||||
},
|
||||
};
|
||||
if (id != null && ruleId != null) {
|
||||
return {
|
||||
id,
|
||||
rule_id: ruleId,
|
||||
error: {
|
||||
status_code: statusCode,
|
||||
message,
|
||||
},
|
||||
};
|
||||
} else if (id != null) {
|
||||
return {
|
||||
id,
|
||||
error: {
|
||||
status_code: statusCode,
|
||||
message,
|
||||
},
|
||||
};
|
||||
} else if (ruleId != null) {
|
||||
return {
|
||||
rule_id: ruleId,
|
||||
error: {
|
||||
status_code: statusCode,
|
||||
message,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
rule_id: '(unknown id)',
|
||||
error: {
|
||||
status_code: statusCode,
|
||||
message,
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export interface ImportRuleResponse {
|
||||
rule_id: string;
|
||||
rule_id?: string;
|
||||
id?: string;
|
||||
status_code?: number;
|
||||
message?: string;
|
||||
error?: {
|
||||
|
|
|
@ -129,7 +129,7 @@ export default ({ getService }: FtrProviderContext): void => {
|
|||
message: 'id: "fake_id" not found',
|
||||
status_code: 404,
|
||||
},
|
||||
rule_id: 'fake_id', // TODO This is a known issue where it should be id and not rule_id
|
||||
id: 'fake_id',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
@ -152,7 +152,7 @@ export default ({ getService }: FtrProviderContext): void => {
|
|||
const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
|
||||
expect([bodyToCompare, body[1]]).to.eql([
|
||||
getSimpleRuleOutputWithoutRuleId(),
|
||||
{ rule_id: 'fake_id', error: { status_code: 404, message: 'id: "fake_id" not found' } },
|
||||
{ id: 'fake_id', error: { status_code: 404, message: 'id: "fake_id" not found' } },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
@ -262,7 +262,7 @@ export default ({ getService }: FtrProviderContext): void => {
|
|||
message: 'id: "fake_id" not found',
|
||||
status_code: 404,
|
||||
},
|
||||
rule_id: 'fake_id', // TODO This is a known issue where it should be id and not rule_id
|
||||
id: 'fake_id',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
@ -285,7 +285,7 @@ export default ({ getService }: FtrProviderContext): void => {
|
|||
const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
|
||||
expect([bodyToCompare, body[1]]).to.eql([
|
||||
getSimpleRuleOutputWithoutRuleId(),
|
||||
{ rule_id: 'fake_id', error: { status_code: 404, message: 'id: "fake_id" not found' } },
|
||||
{ id: 'fake_id', error: { status_code: 404, message: 'id: "fake_id" not found' } },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -263,7 +263,7 @@ export default ({ getService }: FtrProviderContext) => {
|
|||
.expect(200);
|
||||
|
||||
expect(body).to.eql([
|
||||
{ rule_id: 'fake_id', error: { status_code: 404, message: 'id: "fake_id" not found' } },
|
||||
{ id: 'fake_id', error: { status_code: 404, message: 'id: "fake_id" not found' } },
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -347,7 +347,7 @@ export default ({ getService }: FtrProviderContext) => {
|
|||
message: 'id: "fake_id" not found',
|
||||
status_code: 404,
|
||||
},
|
||||
rule_id: 'fake_id', // TODO: This should be id and not rule_id in the codebase
|
||||
id: 'fake_id',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
|
|
@ -277,7 +277,7 @@ export default ({ getService }: FtrProviderContext) => {
|
|||
.expect(200);
|
||||
|
||||
expect(body).to.eql([
|
||||
{ rule_id: 'fake_id', error: { status_code: 404, message: 'id: "fake_id" not found' } },
|
||||
{ id: 'fake_id', error: { status_code: 404, message: 'id: "fake_id" not found' } },
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -377,7 +377,7 @@ export default ({ getService }: FtrProviderContext) => {
|
|||
message: 'id: "fake_id" not found',
|
||||
status_code: 404,
|
||||
},
|
||||
rule_id: 'fake_id', // TODO: This should be id and not rule_id in the codebase
|
||||
id: 'fake_id',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue