From 4fb3ec3c959e4c569aca4674243a2ecba9d973a7 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 4 Sep 2024 06:08:05 +1000 Subject: [PATCH] [7.17] fix archive path for chromium download (#191953) (#192001) # Backport This will backport the following commits from `main` to `7.17`: - [fix archive path for chromium download (#191953)](https://github.com/elastic/kibana/pull/191953) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) ","sha":"4bf2f97451315b49cf9b73abf5c0e111581cd711","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:SharedUX","backport:prev-major","v8.16.0","Feature:Reporting:Framework"],"title":"fix archive path for chromium download","number":191953,"url":"https://github.com/elastic/kibana/pull/191953","mergeCommit":{"message":"fix archive path for chromium download (#191953)\n\n## Summary\r\n\r\nThis PR is a follow up to the work that's been done to make it\r\nrelatively straight forward to backport puppeteer updates to the 7.17\r\nbranch in https://github.com/elastic/kibana/pull/188390.\r\n\r\nThis change ensures the archive path for chromium doesn't get installed\r\noutside of the kibana directory, the previous expression resulted in an\r\narchive path outside of the kibana directory which unfortunately could\r\nresult in a resolution of a path that kibana has no permissions to write\r\nto, depending on where kibana is being executed from.\r\n\r\n## How to test\r\n \r\n- Pull this PR and delete the `.chromium` directory, for whatever\r\nplatform this PR is is been tested on we should get no errors about\r\ninstalling the chromium and we should see the appropriate chromium\r\narchive for the os platform available in the `.chromium` that would get\r\ncreated.\r\n\r\n\r\n","sha":"4bf2f97451315b49cf9b73abf5c0e111581cd711"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/191953","number":191953,"mergeCommit":{"message":"fix archive path for chromium download (#191953)\n\n## Summary\r\n\r\nThis PR is a follow up to the work that's been done to make it\r\nrelatively straight forward to backport puppeteer updates to the 7.17\r\nbranch in https://github.com/elastic/kibana/pull/188390.\r\n\r\nThis change ensures the archive path for chromium doesn't get installed\r\noutside of the kibana directory, the previous expression resulted in an\r\narchive path outside of the kibana directory which unfortunately could\r\nresult in a resolution of a path that kibana has no permissions to write\r\nto, depending on where kibana is being executed from.\r\n\r\n## How to test\r\n \r\n- Pull this PR and delete the `.chromium` directory, for whatever\r\nplatform this PR is is been tested on we should get no errors about\r\ninstalling the chromium and we should see the appropriate chromium\r\narchive for the os platform available in the `.chromium` that would get\r\ncreated.\r\n\r\n\r\n","sha":"4bf2f97451315b49cf9b73abf5c0e111581cd711"}}]}] BACKPORT--> --------- Co-authored-by: Eyo O. Eyo <7893459+eokoneyo@users.noreply.github.com> Co-authored-by: Timothy Sullivan --- packages/kbn-screenshotting-server/BUILD.bazel | 1 + .../kbn-screenshotting-server/jest.config.js | 13 +++++++++++++ .../src/paths.test.ts | 18 ++++++++++++++++++ .../kbn-screenshotting-server/src/paths.ts | 2 +- .../kbn-screenshotting-server/tsconfig.json | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 packages/kbn-screenshotting-server/jest.config.js create mode 100644 packages/kbn-screenshotting-server/src/paths.test.ts diff --git a/packages/kbn-screenshotting-server/BUILD.bazel b/packages/kbn-screenshotting-server/BUILD.bazel index 61afd822488b55..34bd92f6891a9f 100644 --- a/packages/kbn-screenshotting-server/BUILD.bazel +++ b/packages/kbn-screenshotting-server/BUILD.bazel @@ -24,6 +24,7 @@ NPM_MODULE_EXTRA_FILES = [ RUNTIME_DEPS = [] TYPES_DEPS = [ + "@npm//@types/jest", "@npm//@types/node", ] diff --git a/packages/kbn-screenshotting-server/jest.config.js b/packages/kbn-screenshotting-server/jest.config.js new file mode 100644 index 00000000000000..9bda912b7247df --- /dev/null +++ b/packages/kbn-screenshotting-server/jest.config.js @@ -0,0 +1,13 @@ +/* + * 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. + */ + +module.exports = { + preset: '@kbn/test', + rootDir: '../..', + roots: ['/packages/kbn-screenshotting-server'], +}; 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); diff --git a/packages/kbn-screenshotting-server/tsconfig.json b/packages/kbn-screenshotting-server/tsconfig.json index 4e8f4b62663afe..0122607e10793c 100644 --- a/packages/kbn-screenshotting-server/tsconfig.json +++ b/packages/kbn-screenshotting-server/tsconfig.json @@ -10,6 +10,7 @@ "sourceRoot": "../../../../packages/kbn-screenshotting-server/src", "stripInternal": false, "types": [ + "jest", "node" ] },