[8.6] Properly re-expose close method from the createPointInTimeFinderDecryptedAsInternalUser API. (#147241) (#147258)

# Backport

This will backport the following commits from `main` to `8.6`:
- [Properly re-expose `close` method from the
`createPointInTimeFinderDecryptedAsInternalUser` API.
(#147241)](https://github.com/elastic/kibana/pull/147241)

<!--- Backport version: 8.9.7 -->

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

<!--BACKPORT [{"author":{"name":"Aleh
Zasypkin","email":"aleh.zasypkin@elastic.co"},"sourceCommit":{"committedDate":"2022-12-08T15:00:20Z","message":"Properly
re-expose `close` method from the
`createPointInTimeFinderDecryptedAsInternalUser` API.
(#147241)","sha":"12e9e35eb642b3c1ba4f9c45a08929fba763da9d","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:Security","release_note:skip","Feature:Security/Encrypted
Saved
Objects","backport:prev-minor","v8.7.0"],"number":147241,"url":"https://github.com/elastic/kibana/pull/147241","mergeCommit":{"message":"Properly
re-expose `close` method from the
`createPointInTimeFinderDecryptedAsInternalUser` API.
(#147241)","sha":"12e9e35eb642b3c1ba4f9c45a08929fba763da9d"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/147241","number":147241,"mergeCommit":{"message":"Properly
re-expose `close` method from the
`createPointInTimeFinderDecryptedAsInternalUser` API.
(#147241)","sha":"12e9e35eb642b3c1ba4f9c45a08929fba763da9d"}}]}]
BACKPORT-->

Co-authored-by: Aleh Zasypkin <aleh.zasypkin@elastic.co>
This commit is contained in:
Kibana Machine 2022-12-08 11:06:58 -05:00 committed by GitHub
parent 0c9e0801e7
commit 5e71a52c04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

View file

@ -332,5 +332,32 @@ describe('#setupSavedObjects', () => {
expect(res.saved_objects[0].error).toHaveProperty('message', 'Test failure');
}
});
it('properly re-exposes `close` method of the underlying point in time finder ', async () => {
// The finder that underlying repository returns is an instance of a `PointInTimeFinder` class that cannot, and
// unlike object literal it cannot be "copied" with the spread operator. We should make sure we properly re-expose
// `close` function.
const mockClose = jest.fn();
mockSavedObjectsRepository.createPointInTimeFinder = jest.fn().mockImplementation(() => {
class MockPointInTimeFinder {
async close() {
mockClose();
}
async *find() {}
}
return new MockPointInTimeFinder();
});
const finder = await setupContract().createPointInTimeFinderDecryptedAsInternalUser({
type: 'known-type',
});
expect(finder.find).toBeInstanceOf(Function);
expect(finder.close).toBeInstanceOf(Function);
await finder.close();
expect(mockClose).toHaveBeenCalledTimes(1);
});
});
});

View file

@ -184,7 +184,7 @@ export function setupSavedObjects({
}
}
return { ...finder, find: () => encryptedFinder() };
return { find: () => encryptedFinder(), close: finder.close.bind(finder) };
},
};
};

View file

@ -68,6 +68,8 @@ export function registerHiddenSORoutes(
savedObjects = [...savedObjects, ...result.saved_objects];
}
await finder.close();
try {
return response.ok({
body: { saved_objects: savedObjects },