From 7003b769fc81d0450306056514f7a39cdaadce05 Mon Sep 17 00:00:00 2001 From: "Eyo O. Eyo" <7893459+eokoneyo@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:51:51 +0200 Subject: [PATCH] fix archive path for chromium download (#191953) ## Summary This PR is a follow up to the work that's been done to make it relatively straight forward to backport puppeteer updates to the 7.17 branch in https://github.com/elastic/kibana/pull/188390. This change ensures the archive path for chromium doesn't get installed outside of the kibana directory, the previous expression resulted in an archive path outside of the kibana directory which unfortunately could result in a resolution of a path that kibana has no permissions to write to, depending on where kibana is being executed from. ## How to test - Pull this PR and delete the `.chromium` directory, for whatever platform this PR is is been tested on we should get no errors about installing the chromium and we should see the appropriate chromium archive for the os platform available in the `.chromium` that would get created. (cherry picked from commit 4bf2f97451315b49cf9b73abf5c0e111581cd711) --- .../src/paths.test.ts | 18 ++++++++++++++++++ .../kbn-screenshotting-server/src/paths.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 packages/kbn-screenshotting-server/src/paths.test.ts diff --git a/packages/kbn-screenshotting-server/src/paths.test.ts b/packages/kbn-screenshotting-server/src/paths.test.ts new file mode 100644 index 00000000000000..8460f5e7f72a72 --- /dev/null +++ b/packages/kbn-screenshotting-server/src/paths.test.ts @@ -0,0 +1,18 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ChromiumArchivePaths } from './paths'; + +describe('ChromiumArchivePaths', () => { + it('should download chromium archive to a specific path', () => { + const ChromiumArchivePathsInstance = new ChromiumArchivePaths(); + expect(ChromiumArchivePathsInstance.archivesPath).toEqual( + expect.stringContaining('kibana/.chromium') + ); + }); +}); diff --git a/packages/kbn-screenshotting-server/src/paths.ts b/packages/kbn-screenshotting-server/src/paths.ts index f3c339988567ff..e5b958ddc1fc06 100644 --- a/packages/kbn-screenshotting-server/src/paths.ts +++ b/packages/kbn-screenshotting-server/src/paths.ts @@ -102,7 +102,7 @@ export class ChromiumArchivePaths { ]; // zip files get downloaded to a .chromium directory in the kibana root - public readonly archivesPath = path.resolve(__dirname, '../../../../../../.chromium'); + public readonly archivesPath = path.resolve(__dirname, '../../../.chromium'); public find(platform: string, architecture: string, packages: PackageInfo[] = this.packages) { return packages.find((p) => p.platform === platform && p.architecture === architecture);