From 3b2d247c74edadc2d3b6f0d82d448078ab15649b Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 10 May 2023 12:13:04 +0000 Subject: [PATCH] fix: avoid using `os.userInfo()` (#22826) The `os.userInfo()` call might throw on POSIX if there is no user info for the current `uid`. This might happen, if the docker is launched like this: ``` docker run --rm -u 1234:1234 -it mcr.microsoft.com/playwright:v1.32.0 node -e 'console.log(os.userInfo().username)' ``` So instead of using `os.userInfo()`, rely on effective user id. Fixes https://github.com/microsoft/playwright/issues/22721 --- .../playwright-test/src/common/compilationCache.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/playwright-test/src/common/compilationCache.ts b/packages/playwright-test/src/common/compilationCache.ts index 9f32bba821..0e6e3cf6cc 100644 --- a/packages/playwright-test/src/common/compilationCache.ts +++ b/packages/playwright-test/src/common/compilationCache.ts @@ -19,7 +19,6 @@ import fs from 'fs'; import os from 'os'; import path from 'path'; import { sourceMapSupport } from '../utilsBundle'; -import { sanitizeForFilePath } from '../util'; export type MemoryCache = { codePath: string; @@ -29,10 +28,15 @@ export type MemoryCache = { const version = 13; -const DEFAULT_CACHE_DIR_WIN32 = path.join(os.tmpdir(), `playwright-transform-cache`); -const DEFAULT_CACHE_DIR_POSIX = path.join(os.tmpdir(), `playwright-transform-cache-` + sanitizeForFilePath(os.userInfo().username)); - -const cacheDir = process.env.PWTEST_CACHE_DIR || (process.platform === 'win32' ? DEFAULT_CACHE_DIR_WIN32 : DEFAULT_CACHE_DIR_POSIX); +const cacheDir = process.env.PWTEST_CACHE_DIR || (() => { + if (process.platform === 'win32') + return path.join(os.tmpdir(), `playwright-transform-cache`); + // Use `geteuid()` instead of more natural `os.userInfo().username` + // since `os.userInfo()` is not always available. + // Note: `process.geteuid()` is not available on windows. + // See https://github.com/microsoft/playwright/issues/22721 + return path.join(os.tmpdir(), `playwright-transform-cache-` + process.geteuid()); +})(); const sourceMaps: Map = new Map(); const memoryCache = new Map();