forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Resolver] Resolver query panel load more (elastic…
- Loading branch information
1 parent
52379a0
commit 32d45b6
Showing
12 changed files
with
545 additions
and
50 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
110 changes: 110 additions & 0 deletions
110
...olution/public/resolver/data_access_layer/mocks/one_node_with_paginated_related_events.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,110 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { DataAccessLayer } from '../../types'; | ||
import { mockTreeWithOneNodeAndTwoPagesOfRelatedEvents } from '../../mocks/resolver_tree'; | ||
import { | ||
ResolverRelatedEvents, | ||
ResolverTree, | ||
ResolverEntityIndex, | ||
SafeResolverEvent, | ||
} from '../../../../common/endpoint/types'; | ||
import * as eventModel from '../../../../common/endpoint/models/event'; | ||
|
||
interface Metadata { | ||
/** | ||
* The `_id` of the document being analyzed. | ||
*/ | ||
databaseDocumentID: string; | ||
/** | ||
* A record of entityIDs to be used in tests assertions. | ||
*/ | ||
entityIDs: { | ||
/** | ||
* The entityID of the node related to the document being analyzed. | ||
*/ | ||
origin: 'origin'; | ||
}; | ||
} | ||
export function oneNodeWithPaginatedEvents(): { | ||
dataAccessLayer: DataAccessLayer; | ||
metadata: Metadata; | ||
} { | ||
const metadata: Metadata = { | ||
databaseDocumentID: '_id', | ||
entityIDs: { origin: 'origin' }, | ||
}; | ||
const tree = mockTreeWithOneNodeAndTwoPagesOfRelatedEvents({ | ||
originID: metadata.entityIDs.origin, | ||
}); | ||
|
||
return { | ||
metadata, | ||
dataAccessLayer: { | ||
/** | ||
* Fetch related events for an entity ID | ||
*/ | ||
async relatedEvents(entityID: string): Promise<ResolverRelatedEvents> { | ||
/** | ||
* Respond with the mocked related events when the origin's related events are fetched. | ||
**/ | ||
const events = entityID === metadata.entityIDs.origin ? tree.relatedEvents.events : []; | ||
|
||
return { | ||
entityID, | ||
events, | ||
nextEvent: null, | ||
}; | ||
}, | ||
|
||
/** | ||
* If called with an "after" cursor, return the 2nd page, else return the first. | ||
*/ | ||
async eventsWithEntityIDAndCategory( | ||
entityID: string, | ||
category: string, | ||
after?: string | ||
): Promise<{ events: SafeResolverEvent[]; nextEvent: string | null }> { | ||
let events: SafeResolverEvent[] = []; | ||
const eventsOfCategory = tree.relatedEvents.events.filter( | ||
(event) => event.event?.category === category | ||
); | ||
if (after === undefined) { | ||
events = eventsOfCategory.slice(0, 25); | ||
} else { | ||
events = eventsOfCategory.slice(25); | ||
} | ||
return { | ||
events, | ||
nextEvent: typeof after === 'undefined' ? 'firstEventPage2' : null, | ||
}; | ||
}, | ||
|
||
/** | ||
* Any of the origin's related events by event.id | ||
*/ | ||
async event(eventID: string): Promise<SafeResolverEvent | null> { | ||
return ( | ||
tree.relatedEvents.events.find((event) => eventModel.eventID(event) === eventID) ?? null | ||
); | ||
}, | ||
|
||
/** | ||
* Fetch a ResolverTree for a entityID | ||
*/ | ||
async resolverTree(): Promise<ResolverTree> { | ||
return tree; | ||
}, | ||
|
||
/** | ||
* Get entities matching a document. | ||
*/ | ||
async entities(): Promise<ResolverEntityIndex> { | ||
return [{ entity_id: metadata.entityIDs.origin }]; | ||
}, | ||
}, | ||
}; | ||
} |
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
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.