[Fleet] Avoid getting package info from archive when no pkgVersion supplied (#137561) (#137574)

(cherry picked from commit 0600c30be4)

Co-authored-by: Mark Hopkin <mark.hopkin@elastic.co>
This commit is contained in:
Kibana Machine 2022-07-29 08:33:42 -04:00 committed by GitHub
parent 3d0a7cacf0
commit d5f112c325
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -372,6 +372,32 @@ describe('When using EPM `get` services', () => {
expect(MockRegistry.getRegistryPackage).not.toHaveBeenCalled();
});
// when calling the get package endpoint without a package version we
// were previously incorrectly getting the info from archive
it('avoids loading archive when skipArchive = true and no version supplied', async () => {
const soClient = savedObjectsClientMock.create();
soClient.get.mockRejectedValue(SavedObjectsErrorHelpers.createGenericNotFoundError());
MockRegistry.fetchInfo.mockResolvedValue({
name: 'my-package',
version: '1.0.0',
assets: [],
} as unknown as RegistryPackage);
await expect(
getPackageInfo({
savedObjectsClient: soClient,
pkgName: 'my-package',
pkgVersion: '',
skipArchive: true,
})
).resolves.toMatchObject({
latestVersion: '1.0.0',
status: 'not_installed',
});
expect(MockRegistry.getRegistryPackage).not.toHaveBeenCalled();
});
});
});
});

View file

@ -155,7 +155,7 @@ export async function getPackageInfo({
// otherwise build it from the archive
let paths: string[];
let packageInfo: RegistryPackage | ArchivePackage | undefined = skipArchive
? await Registry.fetchInfo(pkgName, pkgVersion).catch(() => undefined)
? await Registry.fetchInfo(pkgName, resolvedPkgVersion).catch(() => undefined)
: undefined;
if (packageInfo) {