From 4949e7093e05019841914394f6b414ebf61189d4 Mon Sep 17 00:00:00 2001 From: Tim Sullivan Date: Thu, 22 Aug 2024 11:03:03 -0700 Subject: [PATCH 1/2] [Screenshotting] Server package for stateless code (#188390) ## Summary This PR moves code that is usually impacted by a Puppeteer/Chromium upgrade to a package. The same work is happening to a lesser degree in the 7.17 branch. Together, these changes will ease the manual labor of backporting the upgrades from main to 7.17. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit bf673d9c565c288223483c4c622f37f745ce70e6) # Conflicts: # .github/CODEOWNERS --- package.json | 1 + packages/kbn-screenshotting-server/README.md | 3 +++ packages/kbn-screenshotting-server/index.ts | 13 +++++++++++ .../kbn-screenshotting-server/jest.config.js | 13 +++++++++++ .../kbn-screenshotting-server/kibana.jsonc | 5 ++++ .../kbn-screenshotting-server/package.json | 6 +++++ .../src}/args.test.ts | 5 ++-- .../kbn-screenshotting-server/src}/args.ts | 7 +++--- .../src}/config/create_config.test.ts | 5 ++-- .../src}/config/create_config.ts | 5 ++-- .../default_chromium_sandbox_disabled.test.ts | 5 ++-- .../default_chromium_sandbox_disabled.ts | 5 ++-- .../src}/config/index.ts | 5 ++-- .../src}/config/schema.ts | 5 ++-- .../src/get_chromium_package.ts | 23 +++++++++++++++++++ .../kbn-screenshotting-server/src}/paths.ts | 5 ++-- .../kbn-screenshotting-server/tsconfig.json | 21 +++++++++++++++++ tsconfig.base.json | 2 ++ .../server/browsers/chromium/driver.test.ts | 2 +- .../server/browsers/chromium/driver.ts | 4 ++-- .../chromium/driver_factory/index.test.ts | 2 +- .../browsers/chromium/driver_factory/index.ts | 9 ++++---- .../server/browsers/chromium/index.ts | 2 -- .../integration_tests/downloads.test.ts | 2 +- .../server/browsers/download/index.test.ts | 10 ++++---- .../server/browsers/download/index.ts | 6 ++--- .../screenshotting/server/browsers/index.ts | 1 - .../screenshotting/server/browsers/install.ts | 4 ++-- .../server/config/schema.test.ts | 2 +- x-pack/plugins/screenshotting/server/index.ts | 2 +- .../plugins/screenshotting/server/plugin.ts | 15 +++++++----- .../screenshots/event_logger/index.test.ts | 4 ++-- .../server/screenshots/event_logger/index.ts | 2 +- .../get_element_position_data.test.ts | 2 +- .../screenshots/get_number_of_items.test.ts | 2 +- .../screenshots/get_render_errors.test.ts | 2 +- .../screenshots/get_screenshots.test.ts | 2 +- .../server/screenshots/get_time_range.test.ts | 2 +- .../server/screenshots/index.test.ts | 2 +- .../server/screenshots/observable.test.ts | 5 ++-- .../server/screenshots/observable.ts | 14 ++++++++--- .../server/screenshots/screenshots.test.ts | 2 +- .../server/screenshots/screenshots.ts | 21 +++++++++++++---- x-pack/plugins/screenshotting/server/utils.ts | 15 ++---------- x-pack/plugins/screenshotting/tsconfig.json | 3 +-- yarn.lock | 4 ++++ 46 files changed, 192 insertions(+), 85 deletions(-) create mode 100644 packages/kbn-screenshotting-server/README.md create mode 100644 packages/kbn-screenshotting-server/index.ts create mode 100644 packages/kbn-screenshotting-server/jest.config.js create mode 100644 packages/kbn-screenshotting-server/kibana.jsonc create mode 100644 packages/kbn-screenshotting-server/package.json rename {x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory => packages/kbn-screenshotting-server/src}/args.test.ts (91%) rename {x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory => packages/kbn-screenshotting-server/src}/args.ts (92%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/create_config.test.ts (86%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/create_config.ts (89%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/default_chromium_sandbox_disabled.test.ts (92%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/default_chromium_sandbox_disabled.ts (90%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/index.ts (93%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/schema.ts (94%) create mode 100644 packages/kbn-screenshotting-server/src/get_chromium_package.ts rename {x-pack/plugins/screenshotting/server/browsers/chromium => packages/kbn-screenshotting-server/src}/paths.ts (96%) create mode 100644 packages/kbn-screenshotting-server/tsconfig.json diff --git a/package.json b/package.json index dccacd230f4a68..90559de254a617 100644 --- a/package.json +++ b/package.json @@ -693,6 +693,7 @@ "@kbn/screenshot-mode-plugin": "link:src/plugins/screenshot_mode", "@kbn/screenshotting-example-plugin": "link:x-pack/examples/screenshotting_example", "@kbn/screenshotting-plugin": "link:x-pack/plugins/screenshotting", + "@kbn/screenshotting-server": "link:packages/kbn-screenshotting-server", "@kbn/search-api-panels": "link:packages/kbn-search-api-panels", "@kbn/search-connectors": "link:packages/kbn-search-connectors", "@kbn/search-connectors-plugin": "link:x-pack/plugins/search_connectors", diff --git a/packages/kbn-screenshotting-server/README.md b/packages/kbn-screenshotting-server/README.md new file mode 100644 index 00000000000000..5dbac6d0ea00f8 --- /dev/null +++ b/packages/kbn-screenshotting-server/README.md @@ -0,0 +1,3 @@ +# @kbn/screenshotting-server + +Stateless code pertaining to the capture of screenshots for Kibana Reporting diff --git a/packages/kbn-screenshotting-server/index.ts b/packages/kbn-screenshotting-server/index.ts new file mode 100644 index 00000000000000..8ba3e368f46293 --- /dev/null +++ b/packages/kbn-screenshotting-server/index.ts @@ -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. + */ + +export { args } from './src/args'; +export { ChromiumArchivePaths, type PackageInfo } from './src/paths'; +export { getChromiumPackage } from './src/get_chromium_package'; +export { type ConfigType, createConfig, config, durationToNumber } from './src/config'; +export { ConfigSchema } from './src/config/schema'; diff --git a/packages/kbn-screenshotting-server/jest.config.js b/packages/kbn-screenshotting-server/jest.config.js new file mode 100644 index 00000000000000..7436a349ebfc76 --- /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/jest_node', + rootDir: '../..', + roots: ['/packages/kbn-screenshotting-server'], +}; diff --git a/packages/kbn-screenshotting-server/kibana.jsonc b/packages/kbn-screenshotting-server/kibana.jsonc new file mode 100644 index 00000000000000..1f2aa1c0f57945 --- /dev/null +++ b/packages/kbn-screenshotting-server/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-server", + "id": "@kbn/screenshotting-server", + "owner": "@elastic/appex-sharedux" +} diff --git a/packages/kbn-screenshotting-server/package.json b/packages/kbn-screenshotting-server/package.json new file mode 100644 index 00000000000000..11f02c6cb5c305 --- /dev/null +++ b/packages/kbn-screenshotting-server/package.json @@ -0,0 +1,6 @@ +{ + "name": "@kbn/screenshotting-server", + "private": true, + "version": "1.0.0", + "license": "SSPL-1.0 OR Elastic License 2.0" +} \ No newline at end of file diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.test.ts b/packages/kbn-screenshotting-server/src/args.test.ts similarity index 91% rename from x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.test.ts rename to packages/kbn-screenshotting-server/src/args.test.ts index 6e955fa3928aad..a7ae1f2f8d0802 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.test.ts +++ b/packages/kbn-screenshotting-server/src/args.test.ts @@ -1,8 +1,9 @@ /* * 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. + * 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 os from 'os'; diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.ts b/packages/kbn-screenshotting-server/src/args.ts similarity index 92% rename from x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.ts rename to packages/kbn-screenshotting-server/src/args.ts index fc1bf51d774932..df1d4a60ec9458 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.ts +++ b/packages/kbn-screenshotting-server/src/args.ts @@ -1,12 +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; you may not use this file except in compliance with the Elastic License - * 2.0. + * 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 os from 'os'; -import type { ConfigType } from '../../../config'; +import type { ConfigType } from './config'; interface WindowSize { height: number; diff --git a/x-pack/plugins/screenshotting/server/config/create_config.test.ts b/packages/kbn-screenshotting-server/src/config/create_config.test.ts similarity index 86% rename from x-pack/plugins/screenshotting/server/config/create_config.test.ts rename to packages/kbn-screenshotting-server/src/config/create_config.test.ts index 4bc5ff65727d02..9a6a7e1cdd579b 100644 --- a/x-pack/plugins/screenshotting/server/config/create_config.test.ts +++ b/packages/kbn-screenshotting-server/src/config/create_config.test.ts @@ -1,8 +1,9 @@ /* * 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. + * 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 type { Logger } from '@kbn/core/server'; diff --git a/x-pack/plugins/screenshotting/server/config/create_config.ts b/packages/kbn-screenshotting-server/src/config/create_config.ts similarity index 89% rename from x-pack/plugins/screenshotting/server/config/create_config.ts rename to packages/kbn-screenshotting-server/src/config/create_config.ts index c2ab86b5de76ef..099dc0b8cb9e68 100644 --- a/x-pack/plugins/screenshotting/server/config/create_config.ts +++ b/packages/kbn-screenshotting-server/src/config/create_config.ts @@ -1,8 +1,9 @@ /* * 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. + * 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 { set } from '@kbn/safer-lodash-set'; diff --git a/x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.test.ts b/packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.test.ts similarity index 92% rename from x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.test.ts rename to packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.test.ts index 0b5f503e869216..01e863556691dd 100644 --- a/x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.test.ts +++ b/packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.test.ts @@ -1,8 +1,9 @@ /* * 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. + * 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. */ jest.mock('getos', () => jest.fn()); diff --git a/x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.ts b/packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.ts similarity index 90% rename from x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.ts rename to packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.ts index 34986e804f45a2..19b268f20439c5 100644 --- a/x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.ts +++ b/packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.ts @@ -1,8 +1,9 @@ /* * 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. + * 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 getOsSync from 'getos'; diff --git a/x-pack/plugins/screenshotting/server/config/index.ts b/packages/kbn-screenshotting-server/src/config/index.ts similarity index 93% rename from x-pack/plugins/screenshotting/server/config/index.ts rename to packages/kbn-screenshotting-server/src/config/index.ts index 468f0927801124..583952da6cba6a 100644 --- a/x-pack/plugins/screenshotting/server/config/index.ts +++ b/packages/kbn-screenshotting-server/src/config/index.ts @@ -1,8 +1,9 @@ /* * 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. + * 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 type { PluginConfigDescriptor } from '@kbn/core/server'; diff --git a/x-pack/plugins/screenshotting/server/config/schema.ts b/packages/kbn-screenshotting-server/src/config/schema.ts similarity index 94% rename from x-pack/plugins/screenshotting/server/config/schema.ts rename to packages/kbn-screenshotting-server/src/config/schema.ts index 0dda1e3ae99814..ce542f2a849f4f 100644 --- a/x-pack/plugins/screenshotting/server/config/schema.ts +++ b/packages/kbn-screenshotting-server/src/config/schema.ts @@ -1,8 +1,9 @@ /* * 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. + * 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 { schema, TypeOf, offeringBasedSchema } from '@kbn/config-schema'; diff --git a/packages/kbn-screenshotting-server/src/get_chromium_package.ts b/packages/kbn-screenshotting-server/src/get_chromium_package.ts new file mode 100644 index 00000000000000..af79341d0046a6 --- /dev/null +++ b/packages/kbn-screenshotting-server/src/get_chromium_package.ts @@ -0,0 +1,23 @@ +/* + * 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 os from 'os'; +import { ChromiumArchivePaths } from './paths'; + +const paths = new ChromiumArchivePaths(); + +export const getChromiumPackage = () => { + const platform = process.platform; + const architecture = os.arch(); + + const chromiumPackageInfo = paths.find(process.platform, architecture); + if (!chromiumPackageInfo) { + throw new Error(`Unsupported platform: ${platform}-${architecture}`); + } + return chromiumPackageInfo; +}; diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/paths.ts b/packages/kbn-screenshotting-server/src/paths.ts similarity index 96% rename from x-pack/plugins/screenshotting/server/browsers/chromium/paths.ts rename to packages/kbn-screenshotting-server/src/paths.ts index 21dde6af6b7de6..9196a96ab3bcb0 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/paths.ts +++ b/packages/kbn-screenshotting-server/src/paths.ts @@ -1,8 +1,9 @@ /* * 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. + * 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 path from 'path'; diff --git a/packages/kbn-screenshotting-server/tsconfig.json b/packages/kbn-screenshotting-server/tsconfig.json new file mode 100644 index 00000000000000..1ca4b9da2b0f6e --- /dev/null +++ b/packages/kbn-screenshotting-server/tsconfig.json @@ -0,0 +1,21 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node" + ] + }, + "include": [ + "**/*.ts" + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [ + "@kbn/core", + "@kbn/safer-lodash-set", + "@kbn/config-schema" + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index e7ece2e877697d..53226888098539 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1372,6 +1372,8 @@ "@kbn/screenshotting-example-plugin/*": ["x-pack/examples/screenshotting_example/*"], "@kbn/screenshotting-plugin": ["x-pack/plugins/screenshotting"], "@kbn/screenshotting-plugin/*": ["x-pack/plugins/screenshotting/*"], + "@kbn/screenshotting-server": ["packages/kbn-screenshotting-server"], + "@kbn/screenshotting-server/*": ["packages/kbn-screenshotting-server/*"], "@kbn/search-api-panels": ["packages/kbn-search-api-panels"], "@kbn/search-api-panels/*": ["packages/kbn-search-api-panels/*"], "@kbn/search-connectors": ["packages/kbn-search-connectors"], diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.test.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.test.ts index c9b9bbc9f8b038..e63d6690c72f14 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.test.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.test.ts @@ -7,9 +7,9 @@ import type { Logger } from '@kbn/logging'; import { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; +import { ConfigType } from '@kbn/screenshotting-server'; import * as puppeteer from 'puppeteer'; import { Size } from '../../../common/layout'; -import { ConfigType } from '../../config'; import { PreserveLayout } from '../../layouts/preserve_layout'; import { HeadlessChromiumDriver } from './driver'; diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts index 5727a854ac3cae..64176b2d0c83c3 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts @@ -10,13 +10,13 @@ import { KBN_SCREENSHOT_MODE_HEADER, ScreenshotModePluginSetup, } from '@kbn/screenshot-mode-plugin/server'; +import { ConfigType } from '@kbn/screenshotting-server'; import { truncate } from 'lodash'; import open from 'opn'; -import { ElementHandle, Page, EvaluateFunc, HTTPResponse } from 'puppeteer'; +import { ElementHandle, EvaluateFunc, HTTPResponse, Page } from 'puppeteer'; import { Subject } from 'rxjs'; import { parse as parseUrl } from 'url'; import { getDisallowedOutgoingUrlError } from '.'; -import { ConfigType } from '../../config'; import { Layout } from '../../layouts'; import { getPrintLayoutSelectors } from '../../layouts/print_layout'; import { allowRequest } from '../network_policy'; diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.test.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.test.ts index 317614e7733d1f..1e8c238355668d 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.test.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.test.ts @@ -8,11 +8,11 @@ import type { Logger } from '@kbn/core/server'; import { loggerMock } from '@kbn/logging-mocks'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; +import { ConfigType } from '@kbn/screenshotting-server'; import * as puppeteer from 'puppeteer'; import * as Rx from 'rxjs'; import { mergeMap, take } from 'rxjs'; import { DEFAULT_VIEWPORT, HeadlessChromiumDriverFactory } from '.'; -import { ConfigType } from '../../../config'; jest.mock('puppeteer'); diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts index 1c562a481790e5..840de6542535b0 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts @@ -7,23 +7,22 @@ import type { Logger } from '@kbn/core/server'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; +import { ConfigType, args } from '@kbn/screenshotting-server'; import { getDataPath } from '@kbn/utils'; import { spawn } from 'child_process'; import del from 'del'; import fs from 'fs'; import { uniq } from 'lodash'; import path from 'path'; -import puppeteer, { Browser, ConsoleMessage, Page, Viewport, PageEvents } from 'puppeteer'; +import puppeteer, { Browser, ConsoleMessage, Page, PageEvents, Viewport } from 'puppeteer'; import { createInterface } from 'readline'; import * as Rx from 'rxjs'; -import { catchError, concatMap, ignoreElements, mergeMap, map, reduce, takeUntil, tap } from 'rxjs'; -import { PerformanceMetrics } from '../../../../common/types'; +import { catchError, concatMap, ignoreElements, map, mergeMap, reduce, takeUntil, tap } from 'rxjs'; import { getChromiumDisconnectedError } from '..'; import { errors } from '../../../../common'; -import { ConfigType } from '../../../config'; +import { PerformanceMetrics } from '../../../../common/types'; import { safeChildProcess } from '../../safe_child_process'; import { HeadlessChromiumDriver } from '../driver'; -import { args } from './args'; import { getMetrics } from './metrics'; interface CreatePageOptions { diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/index.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/index.ts index e3f96f3a7445b0..78b66601663d50 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/index.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/index.ts @@ -20,5 +20,3 @@ export const getDisallowedOutgoingUrlError = (interceptedUrl: string) => export { HeadlessChromiumDriver } from './driver'; export type { Context } from './driver'; export { DEFAULT_VIEWPORT, HeadlessChromiumDriverFactory } from './driver_factory'; -export { ChromiumArchivePaths } from './paths'; -export type { PackageInfo } from './paths'; diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/integration_tests/downloads.test.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/integration_tests/downloads.test.ts index a2c331e039389d..ecf36171c3cf04 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/integration_tests/downloads.test.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/integration_tests/downloads.test.ts @@ -6,10 +6,10 @@ */ import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; +import { PackageInfo } from '@kbn/screenshotting-server'; import assert from 'assert'; import axios from 'axios'; import path from 'path'; -import { PackageInfo } from '..'; import { paths as chromiumArchivePaths } from '../../../utils'; import { download } from '../../download'; import { install } from '../../install'; diff --git a/x-pack/plugins/screenshotting/server/browsers/download/index.test.ts b/x-pack/plugins/screenshotting/server/browsers/download/index.test.ts index 96d9bd02993270..24725c811f5d10 100644 --- a/x-pack/plugins/screenshotting/server/browsers/download/index.test.ts +++ b/x-pack/plugins/screenshotting/server/browsers/download/index.test.ts @@ -5,13 +5,13 @@ * 2.0. */ -import path from 'path'; -import mockFs from 'mock-fs'; +import { ChromiumArchivePaths, PackageInfo } from '@kbn/screenshotting-server'; import { access, readdir } from 'fs/promises'; -import { ChromiumArchivePaths, PackageInfo } from '../chromium'; -import { fetch } from './fetch'; -import { sha256 } from './checksum'; +import mockFs from 'mock-fs'; +import path from 'path'; import { download } from '.'; +import { sha256 } from './checksum'; +import { fetch } from './fetch'; jest.mock('./checksum'); jest.mock('./fetch'); diff --git a/x-pack/plugins/screenshotting/server/browsers/download/index.ts b/x-pack/plugins/screenshotting/server/browsers/download/index.ts index bef22c7c2196a5..03c3ecda02eb4d 100644 --- a/x-pack/plugins/screenshotting/server/browsers/download/index.ts +++ b/x-pack/plugins/screenshotting/server/browsers/download/index.ts @@ -5,10 +5,10 @@ * 2.0. */ -import { access } from 'fs/promises'; -import del from 'del'; import type { Logger } from '@kbn/core/server'; -import type { ChromiumArchivePaths, PackageInfo } from '../chromium'; +import type { ChromiumArchivePaths, PackageInfo } from '@kbn/screenshotting-server'; +import del from 'del'; +import { access } from 'fs/promises'; import { sha256 } from './checksum'; import { fetch } from './fetch'; diff --git a/x-pack/plugins/screenshotting/server/browsers/index.ts b/x-pack/plugins/screenshotting/server/browsers/index.ts index 0b6402a0bd6fb3..3c3a1a21716862 100644 --- a/x-pack/plugins/screenshotting/server/browsers/index.ts +++ b/x-pack/plugins/screenshotting/server/browsers/index.ts @@ -10,7 +10,6 @@ export { install } from './install'; export type { Context } from './chromium'; export { getChromiumDisconnectedError, - ChromiumArchivePaths, DEFAULT_VIEWPORT, HeadlessChromiumDriver, HeadlessChromiumDriverFactory, diff --git a/x-pack/plugins/screenshotting/server/browsers/install.ts b/x-pack/plugins/screenshotting/server/browsers/install.ts index 84b9ddc85923b4..2a7e79e7fe1509 100644 --- a/x-pack/plugins/screenshotting/server/browsers/install.ts +++ b/x-pack/plugins/screenshotting/server/browsers/install.ts @@ -5,10 +5,10 @@ * 2.0. */ +import type { Logger } from '@kbn/core/server'; +import { ChromiumArchivePaths, PackageInfo } from '@kbn/screenshotting-server'; import del from 'del'; import path from 'path'; -import type { Logger } from '@kbn/core/server'; -import { ChromiumArchivePaths, PackageInfo } from './chromium'; import { download } from './download'; import { sha256 } from './download/checksum'; import { extract } from './extract'; diff --git a/x-pack/plugins/screenshotting/server/config/schema.test.ts b/x-pack/plugins/screenshotting/server/config/schema.test.ts index a3a141429b4db3..18ef1aa41415cc 100644 --- a/x-pack/plugins/screenshotting/server/config/schema.test.ts +++ b/x-pack/plugins/screenshotting/server/config/schema.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { ConfigSchema } from './schema'; +import { ConfigSchema } from '@kbn/screenshotting-server'; describe('ConfigSchema', () => { it(`should produce correct config for context {"dev": false,"dist": false}`, () => { diff --git a/x-pack/plugins/screenshotting/server/index.ts b/x-pack/plugins/screenshotting/server/index.ts index 414fde21c85a9c..f8d448aba412d3 100755 --- a/x-pack/plugins/screenshotting/server/index.ts +++ b/x-pack/plugins/screenshotting/server/index.ts @@ -15,7 +15,7 @@ export async function plugin(pluginInitializerContext: PluginInitializerContext) return new ScreenshottingPlugin(pluginInitializerContext); } -export { config } from './config'; +export { config } from '@kbn/screenshotting-server'; export type { PdfScreenshotOptions, PdfScreenshotResult, diff --git a/x-pack/plugins/screenshotting/server/plugin.ts b/x-pack/plugins/screenshotting/server/plugin.ts index 7cfb5d3982eb8a..30ca101b8b4220 100755 --- a/x-pack/plugins/screenshotting/server/plugin.ts +++ b/x-pack/plugins/screenshotting/server/plugin.ts @@ -5,8 +5,7 @@ * 2.0. */ -import { from } from 'rxjs'; -import { switchMap } from 'rxjs'; +import type { CloudSetup } from '@kbn/cloud-plugin/server'; import type { CoreSetup, CoreStart, @@ -16,11 +15,15 @@ import type { PluginInitializerContext, } from '@kbn/core/server'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; -import type { CloudSetup } from '@kbn/cloud-plugin/server'; -import { ChromiumArchivePaths, HeadlessChromiumDriverFactory, install } from './browsers'; -import { ConfigType, createConfig } from './config'; +import { + ChromiumArchivePaths, + ConfigType, + createConfig, + getChromiumPackage, +} from '@kbn/screenshotting-server'; +import { from, switchMap } from 'rxjs'; +import { HeadlessChromiumDriverFactory, install } from './browsers'; import { Screenshots } from './screenshots'; -import { getChromiumPackage } from './utils'; interface SetupDeps { screenshotMode: ScreenshotModePluginSetup; diff --git a/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.test.ts b/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.test.ts index 3a20c404ff4979..5a4236704e2325 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.test.ts @@ -5,11 +5,11 @@ * 2.0. */ -import moment from 'moment'; import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; +import moment from 'moment'; import { Actions, EventLogger, ScreenshottingAction, Transactions } from '.'; import { ElementPosition } from '../get_element_position_data'; -import { ConfigType } from '../../config'; jest.mock('uuid', () => ({ v4: () => 'NEW_UUID', diff --git a/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.ts b/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.ts index d067b99750d191..c31e1870615b6a 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.ts @@ -6,11 +6,11 @@ */ import { Logger, LogMeta } from '@kbn/core/server'; +import { ConfigType } from '@kbn/screenshotting-server'; import apm from 'elastic-apm-node'; import { v4 as uuidv4 } from 'uuid'; import { CaptureResult } from '..'; import { PLUGIN_ID } from '../../../common'; -import { ConfigType } from '../../config'; import { ElementPosition } from '../get_element_position_data'; import type { Screenshot } from '../types'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/get_element_position_data.test.ts b/x-pack/plugins/screenshotting/server/screenshots/get_element_position_data.test.ts index c32135f530bf34..cb88b9369a5c09 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/get_element_position_data.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/get_element_position_data.test.ts @@ -6,8 +6,8 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; import { createMockBrowserDriver } from '../browsers/mock'; -import { ConfigType } from '../config'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; import { getElementPositionAndAttributes } from './get_element_position_data'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/get_number_of_items.test.ts b/x-pack/plugins/screenshotting/server/screenshots/get_number_of_items.test.ts index a7c4f27065bcfa..a968ff458804da 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/get_number_of_items.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/get_number_of_items.test.ts @@ -6,8 +6,8 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; import { createMockBrowserDriver } from '../browsers/mock'; -import { ConfigType } from '../config'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; import { getNumberOfItems } from './get_number_of_items'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/get_render_errors.test.ts b/x-pack/plugins/screenshotting/server/screenshots/get_render_errors.test.ts index ece25b37725c8c..70a914f4aa4d5a 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/get_render_errors.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/get_render_errors.test.ts @@ -6,8 +6,8 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; import { createMockBrowserDriver } from '../browsers/mock'; -import { ConfigType } from '../config'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; import { getRenderErrors } from './get_render_errors'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/get_screenshots.test.ts b/x-pack/plugins/screenshotting/server/screenshots/get_screenshots.test.ts index 52298b5966f251..cc1235a852b877 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/get_screenshots.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/get_screenshots.test.ts @@ -6,8 +6,8 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; import { createMockBrowserDriver } from '../browsers/mock'; -import { ConfigType } from '../config'; import { Layout } from '../layouts'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/get_time_range.test.ts b/x-pack/plugins/screenshotting/server/screenshots/get_time_range.test.ts index a7a7b9295068e8..a3b4677ef7357f 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/get_time_range.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/get_time_range.test.ts @@ -6,8 +6,8 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; import { createMockBrowserDriver } from '../browsers/mock'; -import { ConfigType } from '../config'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; import { getTimeRange } from './get_time_range'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/index.test.ts b/x-pack/plugins/screenshotting/server/screenshots/index.test.ts index 3c6540f2877068..6ecaa0916b0f3f 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/index.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/index.test.ts @@ -8,6 +8,7 @@ import type { CloudSetup } from '@kbn/cloud-plugin/server'; import type { Logger, PackageInfo } from '@kbn/core/server'; import { httpServiceMock, loggingSystemMock } from '@kbn/core/server/mocks'; +import type { ConfigType } from '@kbn/screenshotting-server'; import { lastValueFrom, of, throwError } from 'rxjs'; import { ScreenshotOptions, Screenshots } from '.'; import { @@ -18,7 +19,6 @@ import { import * as errors from '../../common/errors'; import type { HeadlessChromiumDriverFactory } from '../browsers'; import { createMockBrowserDriver, createMockBrowserDriverFactory } from '../browsers/mock'; -import type { ConfigType } from '../config'; import type { PngScreenshotOptions } from '../formats'; import * as Layouts from '../layouts/create_layout'; import { createMockLayout } from '../layouts/mock'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/observable.test.ts b/x-pack/plugins/screenshotting/server/screenshots/observable.test.ts index 9ebbead104cc68..82f1467ffa5d11 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/observable.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/observable.test.ts @@ -6,10 +6,9 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; -import { interval, lastValueFrom, of, throwError } from 'rxjs'; -import { map } from 'rxjs'; +import type { ConfigType } from '@kbn/screenshotting-server'; +import { interval, lastValueFrom, map, of, throwError } from 'rxjs'; import { createMockBrowserDriver } from '../browsers/mock'; -import type { ConfigType } from '../config'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; import { ScreenshotObservableHandler, ScreenshotObservableOptions } from './observable'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/observable.ts b/x-pack/plugins/screenshotting/server/screenshots/observable.ts index 8c9854f376706f..0b7382a5770b5c 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/observable.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/observable.ts @@ -6,8 +6,17 @@ */ import type { Headers } from '@kbn/core/server'; -import { defer, forkJoin, Observable, throwError } from 'rxjs'; -import { catchError, mergeMap, switchMapTo, timeoutWith } from 'rxjs'; +import { ConfigType, durationToNumber as toNumber } from '@kbn/screenshotting-server'; +import { + catchError, + defer, + forkJoin, + mergeMap, + Observable, + switchMapTo, + throwError, + timeoutWith, +} from 'rxjs'; import { errors } from '../../common'; import { Context, @@ -15,7 +24,6 @@ import { getChromiumDisconnectedError, HeadlessChromiumDriver, } from '../browsers'; -import { ConfigType, durationToNumber as toNumber } from '../config'; import type { PdfScreenshotOptions } from '../formats'; import { Layout } from '../layouts'; import { Actions, EventLogger } from './event_logger'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/screenshots.test.ts b/x-pack/plugins/screenshotting/server/screenshots/screenshots.test.ts index 9ba12f2211cfa3..4f217ef96c611b 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/screenshots.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/screenshots.test.ts @@ -11,12 +11,12 @@ import type { PackageInfo } from '@kbn/core/server'; import type { Logger } from '@kbn/logging'; import { loggerMock } from '@kbn/logging-mocks'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; +import type { ConfigType } from '@kbn/screenshotting-server'; import puppeteer from 'puppeteer'; import * as Rx from 'rxjs'; import { firstValueFrom } from 'rxjs'; import type { PngScreenshotOptions } from '..'; import { HeadlessChromiumDriverFactory } from '../browsers'; -import type { ConfigType } from '../config'; import { Screenshots } from './screenshots'; jest.mock('puppeteer'); diff --git a/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts b/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts index 24a00ed00108ae..abc731b4fbcfeb 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts @@ -8,13 +8,28 @@ import ipaddr from 'ipaddr.js'; import { defaultsDeep, sum } from 'lodash'; import moment from 'moment'; -import { Observable, from, of, throwError } from 'rxjs'; -import { catchError, concatMap, first, map, mergeMap, take, takeUntil, tap, toArray } from 'rxjs'; +import { + Observable, + catchError, + concatMap, + first, + from, + map, + mergeMap, + of, + take, + takeUntil, + tap, + throwError, + toArray, +} from 'rxjs'; import type { CloudSetup } from '@kbn/cloud-plugin/server'; import type { HttpServiceSetup, Logger, PackageInfo } from '@kbn/core/server'; import { Semaphore } from '@kbn/std'; +import type { ConfigType } from '@kbn/screenshotting-server'; +import { durationToNumber } from '@kbn/screenshotting-server'; import { CaptureResult, ScreenshotOptions, ScreenshotResult } from '.'; import { SCREENSHOTTING_APP_ID, @@ -24,8 +39,6 @@ import { } from '../../common'; import { HeadlessChromiumDriverFactory } from '../browsers'; import { systemHasInsufficientMemory } from '../cloud'; -import type { ConfigType } from '../config'; -import { durationToNumber } from '../config'; import { PdfScreenshotOptions, PdfScreenshotResult, diff --git a/x-pack/plugins/screenshotting/server/utils.ts b/x-pack/plugins/screenshotting/server/utils.ts index cee0837e067a1e..40262b1e65e7b8 100644 --- a/x-pack/plugins/screenshotting/server/utils.ts +++ b/x-pack/plugins/screenshotting/server/utils.ts @@ -5,22 +5,11 @@ * 2.0. */ -import os from 'os'; -import { ChromiumArchivePaths, download as baseDownload, install as baseInstall } from './browsers'; +import { ChromiumArchivePaths } from '@kbn/screenshotting-server'; +import { download as baseDownload, install as baseInstall } from './browsers'; const paths = new ChromiumArchivePaths(); -export const getChromiumPackage = () => { - const platform = process.platform; - const architecture = os.arch(); - - const chromiumPackageInfo = paths.find(process.platform, architecture); - if (!chromiumPackageInfo) { - throw new Error(`Unsupported platform: ${platform}-${architecture}`); - } - return chromiumPackageInfo; -}; - export const download = baseDownload.bind(undefined, paths); export const install = baseInstall.bind(undefined, paths); diff --git a/x-pack/plugins/screenshotting/tsconfig.json b/x-pack/plugins/screenshotting/tsconfig.json index 8421b0c9fdd7de..5e37b84bbf2e9c 100644 --- a/x-pack/plugins/screenshotting/tsconfig.json +++ b/x-pack/plugins/screenshotting/tsconfig.json @@ -16,17 +16,16 @@ "@kbn/screenshot-mode-plugin", "@kbn/cloud-plugin", "@kbn/utility-types", - "@kbn/config-schema", "@kbn/logging", "@kbn/std", "@kbn/i18n", "@kbn/utils", - "@kbn/safer-lodash-set", "@kbn/core-logging-server-mocks", "@kbn/logging-mocks", "@kbn/core-http-server", "@kbn/core-plugins-server", "@kbn/task-manager-plugin", + "@kbn/screenshotting-server", ], "exclude": [ "target/**/*", diff --git a/yarn.lock b/yarn.lock index da1d525422cb00..8bf7eaf0152a06 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5768,6 +5768,10 @@ version "0.0.0" uid "" +"@kbn/screenshotting-server@link:packages/kbn-screenshotting-server": + version "0.0.0" + uid "" + "@kbn/search-api-panels@link:packages/kbn-search-api-panels": version "0.0.0" uid "" From dcf2ae893a6578cbc330dcbd269f4abbbea5c9c2 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 2/2] 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. --- .../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 9196a96ab3bcb0..136899e1a5c516 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);