Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 type { ISavedObjectTypeRegistry, SavedObjectsClientContract } from '@kbn/core/server';

import { KibanaSavedObjectType } from '../../../../common/types';

import { getBulkAssets } from './get_bulk_assets';

describe('getBulkAssets', () => {
it('uses attributes.name as the display title when attributes.title is unavailable', async () => {
const soClient = {
bulkResolve: jest.fn().mockResolvedValue({
resolved_objects: [
{
saved_object: {
id: 'sample_security_rule',
type: KibanaSavedObjectType.securityRule,
updated_at: '2026-05-28T00:00:00.000Z',
attributes: {
name: 'Svchost spawning Cmd',
description:
'Identifies a suspicious parent child process relationship with cmd.exe descending from svchost.exe',
},
},
},
],
}),
} as unknown as SavedObjectsClientContract;

const soTypeRegistry = {
getType: jest.fn().mockReturnValue({
management: {},
}),
} as unknown as ISavedObjectTypeRegistry;

const assets = await getBulkAssets(soClient, soTypeRegistry, [
{
id: 'sample_security_rule',
type: KibanaSavedObjectType.securityRule,
},
]);

expect(assets).toEqual([
{
id: 'sample_security_rule',
type: KibanaSavedObjectType.securityRule,
updatedAt: '2026-05-28T00:00:00.000Z',
attributes: {
title: 'Svchost spawning Cmd',
description:
'Identifies a suspicious parent child process relationship with cmd.exe descending from svchost.exe',
},
appLink: '',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import { displayedAssetTypesLookup } from '../../../../common/constants';

import type { SimpleSOAssetAttributes } from '../../../types';

type DisplayableSOAssetAttributes = SimpleSOAssetAttributes & {
name?: string;
};

const getKibanaLinkForESAsset = (type: ElasticsearchAssetType, id: string): string => {
switch (type) {
case 'index':
Expand Down Expand Up @@ -48,9 +52,8 @@ export async function getBulkAssets(
soTypeRegistry: ISavedObjectTypeRegistry,
assetIds: AssetSOObject[]
) {
const { resolved_objects: resolvedObjects } = await soClient.bulkResolve<SimpleSOAssetAttributes>(
assetIds
);
const { resolved_objects: resolvedObjects } =
await soClient.bulkResolve<DisplayableSOAssetAttributes>(assetIds);
const types: Record<string, SavedObjectsType | undefined> = {};

const res: SimpleSOAssetType[] = resolvedObjects
Expand Down Expand Up @@ -88,7 +91,10 @@ export async function getBulkAssets(
}
}

const title = types[obj.type]?.management?.getTitle?.(obj) ?? obj.attributes?.title;
const title =
types[obj.type]?.management?.getTitle?.(obj) ??
obj.attributes?.title ??
obj.attributes?.name;

return {
id: obj.id,
Expand Down
Loading