From d5a74b81dedeb7be75d1f73051c052cdf882deca Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Wed, 23 Nov 2022 08:32:42 -0800 Subject: [PATCH 1/2] Fix spurious 'ignoring --preserve-environment' warning in app logs --- NEWS | 2 ++ lib/worker/app-worker.js | 2 +- lib/worker/app-worker.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index baa80932..821eccf4 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ shiny-server 1.5.20 then deploy the generated index.html, index_files directory, and the source index.qmd together to be served by Shiny Server. +* Fix spurious log warning about "--preserve-environment" in app logs. + shiny-server 1.5.19 -------------------------------------------------------------------------------- diff --git a/lib/worker/app-worker.js b/lib/worker/app-worker.js index 7e9cd447..91b66fc0 100644 --- a/lib/worker/app-worker.js +++ b/lib/worker/app-worker.js @@ -599,7 +599,6 @@ function createPyShinySpawnSpec(appSpec, endpoint, workerId, logFile, home) { function wrapWithUserSwitch(spec, user) { var command = "su"; var args = [ - "-p", "--", user, "-c", @@ -614,6 +613,7 @@ function wrapWithUserSwitch(spec, user) { } else { // Other platforms don't clear out env vars, so simulate user env + args.unshift("-p"); args.unshift("-"); } return { diff --git a/lib/worker/app-worker.ts b/lib/worker/app-worker.ts index 7f004ecd..08f93e35 100644 --- a/lib/worker/app-worker.ts +++ b/lib/worker/app-worker.ts @@ -649,7 +649,6 @@ async function createPyShinySpawnSpec( function wrapWithUserSwitch(spec: SpawnSpec, user: string): SpawnSpec { const command = "su"; let args = [ - "-p", "--", user, "-c", @@ -664,6 +663,7 @@ function wrapWithUserSwitch(spec: SpawnSpec, user: string): SpawnSpec { args = ["-s", "/bin/bash", "--login"].concat(args); } else { // Other platforms don't clear out env vars, so simulate user env + args.unshift("-p"); args.unshift("-"); } From db476aff5303179189ba2e06b51b9ad31256d970 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Tue, 29 Nov 2022 17:59:08 -0800 Subject: [PATCH 2/2] Fix unit test expectation --- test/app-worker.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/test/app-worker.js b/test/app-worker.js index 7e6e1f4f..7b0957fd 100644 --- a/test/app-worker.js +++ b/test/app-worker.js @@ -190,20 +190,22 @@ async function testLaunchWorker_p( // that there's a window of time where $proc isn't populated) await poll(() => !!worker.$proc); - // Ensure that calls to child_process.spawn() were exactly as expected - assert(mock_spawn.callCount == (appSpec.settings.logAsUser ? 2 : 1)); - if (appSpec.settings.logAsUser) { + try { + // Ensure that calls to child_process.spawn() were exactly as expected + assert(mock_spawn.callCount == (appSpec.settings.logAsUser ? 2 : 1)); + if (appSpec.settings.logAsUser) { + assert.deepStrictEqual( + mock_spawn.firstCall.args, + expectedSpawnLogParams(logFilePath, pw) + ); + } assert.deepStrictEqual( - mock_spawn.firstCall.args, - expectedSpawnLogParams(logFilePath, pw) + mock_spawn.lastCall.args, + expectedSpawnRParams(appSpec, pw) ); + } finally { + worker.$proc.kill(); } - assert.deepStrictEqual( - mock_spawn.lastCall.args, - expectedSpawnRParams(appSpec, pw) - ); - - worker.$proc.kill(); assert.deepEqual(await worker.getExit_p(), { code: null, @@ -299,7 +301,6 @@ function expectedSpawnRParams(appSpec, pw) { "su", [ ...startArgs, - "-p", "--", appSpec.runAs, "-c",