-
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.
- Loading branch information
Showing
4 changed files
with
76 additions
and
61 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
41 changes: 41 additions & 0 deletions
41
x-pack/plugins/fleet/server/services/epm/kibana/assets/saved_object.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,41 @@ | ||
/* | ||
* 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 { savedObjectsClientMock, savedObjectsServiceMock } from '@kbn/core/server/mocks'; | ||
|
||
import { appContextService } from '../../../app_context'; | ||
|
||
import { getSpaceAwareSaveobjectsClients } from './saved_objects'; | ||
|
||
jest.mock('../../../app_context'); | ||
|
||
describe('getSpaceAwareSaveobjectsClients', () => { | ||
it('return space scopped clients', () => { | ||
const soStartMock = savedObjectsServiceMock.createStartContract(); | ||
const mockedSavedObjectTagging = { | ||
createInternalAssignmentService: jest.fn(), | ||
createTagClient: jest.fn(), | ||
}; | ||
|
||
const scoppedSoClient = savedObjectsClientMock.create(); | ||
jest | ||
.mocked(appContextService.getInternalUserSOClientForSpaceId) | ||
.mockReturnValue(scoppedSoClient); | ||
|
||
jest.mocked(appContextService.getSavedObjects).mockReturnValue(soStartMock); | ||
jest.mocked(appContextService.getSavedObjectsTagging).mockReturnValue(mockedSavedObjectTagging); | ||
|
||
getSpaceAwareSaveobjectsClients('test1'); | ||
|
||
expect(appContextService.getInternalUserSOClientForSpaceId).toBeCalledWith('test1'); | ||
expect(soStartMock.createImporter).toBeCalledWith(scoppedSoClient, expect.anything()); | ||
expect(mockedSavedObjectTagging.createInternalAssignmentService).toBeCalledWith({ | ||
client: scoppedSoClient, | ||
}); | ||
expect(mockedSavedObjectTagging.createTagClient).toBeCalledWith({ client: scoppedSoClient }); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/fleet/server/services/epm/kibana/assets/saved_objects.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,32 @@ | ||
/* | ||
* 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 { appContextService } from '../../../app_context'; | ||
|
||
export function getSpaceAwareSaveobjectsClients(spaceId?: string) { | ||
// Saved object client need to be scopped with the package space for saved object tagging | ||
const savedObjectClientWithSpace = appContextService.getInternalUserSOClientForSpaceId(spaceId); | ||
|
||
const savedObjectsImporter = appContextService | ||
.getSavedObjects() | ||
.createImporter(savedObjectClientWithSpace, { importSizeLimit: 15_000 }); | ||
|
||
const savedObjectTagAssignmentService = appContextService | ||
.getSavedObjectsTagging() | ||
.createInternalAssignmentService({ client: savedObjectClientWithSpace }); | ||
|
||
const savedObjectTagClient = appContextService | ||
.getSavedObjectsTagging() | ||
.createTagClient({ client: savedObjectClientWithSpace }); | ||
|
||
return { | ||
savedObjectClientWithSpace, | ||
savedObjectsImporter, | ||
savedObjectTagAssignmentService, | ||
savedObjectTagClient, | ||
}; | ||
} |