From df291aa89d283a9b3172409263dcb8cbe2c5836f Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 10:49:45 +0200 Subject: [PATCH 01/13] Try sharing build settings Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- binding.gyp | 62 +++++++++++------------------------------------------ 1 file changed, 12 insertions(+), 50 deletions(-) diff --git a/binding.gyp b/binding.gyp index 47d762f..298cf03 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,15 +1,9 @@ { - 'targets': [ - { - 'target_name': 'desktop-trampoline', + 'target_defaults': { 'defines': [ "NAPI_VERSION=<(napi_build_version)", ], 'type': 'executable', - 'sources': [ - 'src/desktop-trampoline.c', - 'src/socket.c' - ], 'include_dirs': [ ' Date: Mon, 3 Jun 2024 10:53:20 +0200 Subject: [PATCH 02/13] Can't share type? Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- binding.gyp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index 298cf03..017b61e 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,7 +3,6 @@ 'defines': [ "NAPI_VERSION=<(napi_build_version)", ], - 'type': 'executable', 'include_dirs': [ ' Date: Mon, 3 Jun 2024 10:58:10 +0200 Subject: [PATCH 03/13] Rename trampoline to desktop-askpass-trampoline Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- README.md | 2 +- binding.gyp | 2 +- index.d.ts | 4 ++-- index.js | 14 +++++++------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f01f067..e084154 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ The equivalent Bash shell code looks like this: ```sh # environment variable - GIT_ASKPASS="C:/some/path/to/desktop-trampoline.exe" \ + GIT_ASKPASS="C:/some/path/to/desktop-askpass-trampoline.exe" \ # ensure Git doesn't block the process waiting for the user to provide input GIT_TERMINAL_PROMPT=0 \ git \ diff --git a/binding.gyp b/binding.gyp index 017b61e..a398627 100644 --- a/binding.gyp +++ b/binding.gyp @@ -41,7 +41,7 @@ }, 'targets': [ { - 'target_name': 'desktop-trampoline', + 'target_name': 'desktop-askpass-trampoline', 'type': 'executable', 'sources': [ 'src/desktop-trampoline.c', diff --git a/index.d.ts b/index.d.ts index e68c0de..1368680 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,5 @@ -export function getDesktopTrampolinePath(): string -export function getDesktopTrampolineFilename(): string +export function getDesktopAskpassTrampolinePath(): string +export function getDesktopAskpassTrampolineFilename(): string export function getSSHWrapperPath(): string export function getSSHWrapperFilename(): string diff --git a/index.js b/index.js index 0891bae..71351e0 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,18 @@ const Path = require('path') -function getDesktopTrampolinePath() { +function getDesktopAskpassTrampolinePath() { return Path.join( __dirname, 'build', 'Release', - getDesktopTrampolineFilename() + getDesktopAskpassTrampolineFilename() ) } -function getDesktopTrampolineFilename() { +function getDesktopAskpassTrampolineFilename() { return process.platform === 'win32' - ? 'desktop-trampoline.exe' - : 'desktop-trampoline' + ? 'desktop-askpass-trampoline.exe' + : 'desktop-askpass-trampoline' } function getSSHWrapperPath() { @@ -24,8 +24,8 @@ function getSSHWrapperFilename() { } module.exports = { - getDesktopTrampolinePath, - getDesktopTrampolineFilename, + getDesktopAskpassTrampolinePath, + getDesktopAskpassTrampolineFilename, getSSHWrapperPath, getSSHWrapperFilename, } From f807bd740f9ea2f046b29613857f19d52e863217 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 11:09:36 +0200 Subject: [PATCH 04/13] Fix import Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- test/desktop-trampoline.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/desktop-trampoline.test.js b/test/desktop-trampoline.test.js index 2e07f6a..514ac1a 100644 --- a/test/desktop-trampoline.test.js +++ b/test/desktop-trampoline.test.js @@ -2,11 +2,11 @@ const { stat, access } = require('fs').promises const { constants } = require('fs') const { execFile } = require('child_process') const { promisify } = require('util') -const { getDesktopTrampolinePath } = require('../index') +const { getDesktopAskpassTrampolinePath } = require('../index') const split2 = require('split2') const { createServer } = require('net') -const trampolinePath = getDesktopTrampolinePath() +const trampolinePath = getDesktopAskpassTrampolinePath() const run = promisify(execFile) describe('desktop-trampoline', () => { From 4d5efafe2bff26f79d25673292299b7b543a9220 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 11:20:19 +0200 Subject: [PATCH 05/13] Create credential helper trampoline, send stdin Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- binding.gyp | 18 ++++++++++++++++++ src/desktop-trampoline.c | 17 ++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index a398627..94e7cb4 100644 --- a/binding.gyp +++ b/binding.gyp @@ -55,6 +55,24 @@ }] ] }, + { + 'target_name': 'desktop-credential-helper-trampoline', + 'type': 'executable', + 'defines': [ + 'CREDENTIAL_HELPER' + ], + 'sources': [ + 'src/desktop-trampoline.c', + 'src/socket.c' + ], + 'conditions': [ + ['OS=="win"', { + 'link_settings': { + 'libraries': [ 'Ws2_32.lib' ] + } + }] + ] + }, { 'target_name': 'ssh-wrapper', 'type': 'executable', diff --git a/src/desktop-trampoline.c b/src/desktop-trampoline.c index 735e057..b0bb7c3 100644 --- a/src/desktop-trampoline.c +++ b/src/desktop-trampoline.c @@ -102,7 +102,15 @@ int runTrampolineClient(SOCKET *outSocket, int argc, char **argv, char **envp) { WRITE_STRING_OR_EXIT("environment variable", validEnvVars[idx]); } - // TODO: send stdin stuff? + char stdinBuffer[BUFFER_LENGTH + 1]; + int stdinBytes = 0; + + #ifdef CREDENTIAL_HELPER + stdinBytes = fread(stdinBuffer, sizeof(char), BUFFER_LENGTH, stdin); + #endif + + stdinBuffer[stdinBytes] = '\0'; + WRITE_STRING_OR_EXIT("stdin", stdinBuffer); char buffer[BUFFER_LENGTH + 1]; size_t totalBytesRead = 0; @@ -129,6 +137,13 @@ int runTrampolineClient(SOCKET *outSocket, int argc, char **argv, char **envp) { } int main(int argc, char **argv, char **envp) { + + #ifdef CREDENTIAL_HELPER + setenv("DESKTOP_TRAMPOLINE_IDENTIFIER", "CREDENTIALHELPER"); + #elif + setenv("DESKTOP_TRAMPOLINE_IDENTIFIER", "ASKPASS"); + #endif + if (initializeNetwork() != 0) { return 1; } From 00b634d7c630c72127a29c99c529767c093f1aa2 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 11:23:27 +0200 Subject: [PATCH 06/13] Pardon my c Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- src/desktop-trampoline.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/desktop-trampoline.c b/src/desktop-trampoline.c index 1507105..039d67f 100644 --- a/src/desktop-trampoline.c +++ b/src/desktop-trampoline.c @@ -137,9 +137,9 @@ int runTrampolineClient(SOCKET *outSocket, int argc, char **argv, char **envp) { int main(int argc, char **argv, char **envp) { #ifdef CREDENTIAL_HELPER - setenv("DESKTOP_TRAMPOLINE_IDENTIFIER", "CREDENTIALHELPER"); - #elif - setenv("DESKTOP_TRAMPOLINE_IDENTIFIER", "ASKPASS"); + setenv("DESKTOP_TRAMPOLINE_IDENTIFIER", "CREDENTIALHELPER", 1); + #else + setenv("DESKTOP_TRAMPOLINE_IDENTIFIER", "ASKPASS", 1); #endif if (initializeNetwork() != 0) { From e17797f96b860d139f0b5c58f3a45b3864d58840 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 11:23:47 +0200 Subject: [PATCH 07/13] We're not proxying identifier any more Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- test/desktop-trampoline.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/desktop-trampoline.test.js b/test/desktop-trampoline.test.js index 081f83d..bdd2901 100644 --- a/test/desktop-trampoline.test.js +++ b/test/desktop-trampoline.test.js @@ -43,7 +43,7 @@ describe('desktop-trampoline', () => { const port = await startTrampolineServer() const env = { - DESKTOP_TRAMPOLINE_IDENTIFIER: '123456', + DESKTOP_TRAMPOLINE_TOKEN: '123456', DESKTOP_PORT: port, INVALID_VARIABLE: 'foo bar', } @@ -56,7 +56,7 @@ describe('desktop-trampoline', () => { // output[2] is the number of env variables const outputEnv = output.slice(3) expect(outputEnv).toHaveLength(1) - expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_IDENTIFIER=123456') + expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_TOKEN=123456') server.close() }) From f99853f6f516749dd320b083fa8947fdd5fa505d Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 11:25:59 +0200 Subject: [PATCH 08/13] Fix test Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- test/desktop-trampoline.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/desktop-trampoline.test.js b/test/desktop-trampoline.test.js index bdd2901..fc258a1 100644 --- a/test/desktop-trampoline.test.js +++ b/test/desktop-trampoline.test.js @@ -54,7 +54,8 @@ describe('desktop-trampoline', () => { const outputArguments = output.slice(1, 2) expect(outputArguments).toStrictEqual(['baz']) // output[2] is the number of env variables - const outputEnv = output.slice(3) + const envc = parseInt(output[2]) + const outputEnv = output.slice(3, 3 + envc) expect(outputEnv).toHaveLength(1) expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_TOKEN=123456') From 6052251d3266c9bc7a25e39d2b1aa4066bb50c8e Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 11:47:33 +0200 Subject: [PATCH 09/13] Test that stdin gets forwarded correctly Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- index.d.ts | 3 ++ index.js | 17 ++++++ test/desktop-trampoline.test.js | 92 +++++++++++++++++++++++++-------- 3 files changed, 90 insertions(+), 22 deletions(-) diff --git a/index.d.ts b/index.d.ts index 1368680..6ce6768 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,8 @@ export function getDesktopAskpassTrampolinePath(): string export function getDesktopAskpassTrampolineFilename(): string +export function getDesktopCredentialHelperTrampolinePath(): string +export function getDesktopCredentialHelperTrampolineFilename(): string + export function getSSHWrapperPath(): string export function getSSHWrapperFilename(): string diff --git a/index.js b/index.js index 71351e0..be164b0 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,21 @@ function getDesktopAskpassTrampolineFilename() { : 'desktop-askpass-trampoline' } +function getDesktopCredentialHelperTrampolinePath() { + return Path.join( + __dirname, + 'build', + 'Release', + getDesktopCredentialHelperTrampolineFilename() + ) +} + +function getDesktopCredentialHelperTrampolineFilename() { + return process.platform === 'win32' + ? 'desktop-credential-helper-trampoline.exe' + : 'desktop-credential-helper-trampoline' +} + function getSSHWrapperPath() { return Path.join(__dirname, 'build', 'Release', getSSHWrapperFilename()) } @@ -26,6 +41,8 @@ function getSSHWrapperFilename() { module.exports = { getDesktopAskpassTrampolinePath, getDesktopAskpassTrampolineFilename, + getDesktopCredentialHelperTrampolinePath, + getDesktopCredentialHelperTrampolineFilename, getSSHWrapperPath, getSSHWrapperFilename, } diff --git a/test/desktop-trampoline.test.js b/test/desktop-trampoline.test.js index fc258a1..0f455e4 100644 --- a/test/desktop-trampoline.test.js +++ b/test/desktop-trampoline.test.js @@ -2,46 +2,67 @@ const { stat, access } = require('fs').promises const { constants } = require('fs') const { execFile } = require('child_process') const { promisify } = require('util') -const { getDesktopAskpassTrampolinePath } = require('../index') +const { getDesktopAskpassTrampolinePath, getDesktopCredentialHelperTrampolinePath } = require('../index') const split2 = require('split2') const { createServer } = require('net') -const trampolinePath = getDesktopAskpassTrampolinePath() +const askPassTrampolinePath = getDesktopAskpassTrampolinePath() +const helperTrampolinePath = getDesktopCredentialHelperTrampolinePath() const run = promisify(execFile) describe('desktop-trampoline', () => { it('exists and is a regular file', async () => - expect((await stat(trampolinePath)).isFile()).toBe(true)) + expect((await stat(askPassTrampolinePath)).isFile()).toBe(true)) it('can be executed by current process', () => - access(trampolinePath, constants.X_OK)) + access(askPassTrampolinePath, constants.X_OK)) it('fails when required environment variables are missing', () => - expect(run(trampolinePath, ['Username'])).rejects.toThrow()) + expect(run(askPassTrampolinePath, ['Username'])).rejects.toThrow()) - it('forwards arguments and valid environment variables correctly', async () => { + const captureSession = () => { const output = [] + let resolveOutput = null + + const outputPromise = new Promise(resolve => { + resolveOutput = resolve + }) + const server = createServer(socket => { + let timeoutId = null socket.pipe(split2(/\0/)).on('data', data => { output.push(data.toString('utf8')) - }) - // Don't send anything and just close the socket after the trampoline is - // done forwarding data. - socket.end() + // Hack: consider the session finished after 100ms of inactivity. + // In a real-world scenario, you'd have to parse the data to know when + // the session is finished. + if (timeoutId !== null) { + clearTimeout(timeoutId) + timeoutId = null + } + timeoutId = setTimeout(() => { + resolveOutput(output) + socket.end() + server.close() + }, 100) + }) }) - server.unref() - - const startTrampolineServer = async () => { - return new Promise((resolve, reject) => { - server.on('error', e => reject(e)) - server.listen(0, '127.0.0.1', () => { - resolve(server.address().port) - }) + + const serverPortPromise = new Promise((resolve, reject) => { + server.on('error', e => reject(e)) + server.listen(0, '127.0.0.1', () => { + resolve(server.address().port) }) - } + }) + + return [serverPortPromise, outputPromise] + } + + it('forwards arguments and valid environment variables correctly', async () => { + + const [portPromise, outputPromise] = captureSession() + const port = await portPromise - const port = await startTrampolineServer() const env = { DESKTOP_TRAMPOLINE_TOKEN: '123456', DESKTOP_PORT: port, @@ -49,8 +70,9 @@ describe('desktop-trampoline', () => { } const opts = { env } - await run(trampolinePath, ['baz'], opts) + await run(askPassTrampolinePath, ['baz'], opts) + const output = await outputPromise const outputArguments = output.slice(1, 2) expect(outputArguments).toStrictEqual(['baz']) // output[2] is the number of env variables @@ -58,7 +80,33 @@ describe('desktop-trampoline', () => { const outputEnv = output.slice(3, 3 + envc) expect(outputEnv).toHaveLength(1) expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_TOKEN=123456') + }) + + it('forwards stdin when running in credential-helper mode', async () => { + + const [portPromise, outputPromise] = captureSession() + const port = await portPromise + + const cp = run(helperTrampolinePath, ['get'], { env: { DESKTOP_PORT: port } }) + cp.child.stdin.end('oh hai\n') + + await cp + + const output = await outputPromise + expect(output.at(-1)).toBe('oh hai\n') + }) + + it('doesn\'t forward stdin when running in askpass mode', async () => { + + const [portPromise, outputPromise] = captureSession() + const port = await portPromise + + const cp = run(askPassTrampolinePath, ['get'], { env: { DESKTOP_PORT: port } }) + cp.child.stdin.end('oh hai\n') + + await cp - server.close() + const output = await outputPromise + expect(output.at(-1)).toBe('') }) }) From eb43b574cb605d90d9e350a119fb8171c83ce7ae Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 11:48:38 +0200 Subject: [PATCH 10/13] Liiiiiiint Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- test/desktop-trampoline.test.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/desktop-trampoline.test.js b/test/desktop-trampoline.test.js index 0f455e4..2dbe5b7 100644 --- a/test/desktop-trampoline.test.js +++ b/test/desktop-trampoline.test.js @@ -2,7 +2,10 @@ const { stat, access } = require('fs').promises const { constants } = require('fs') const { execFile } = require('child_process') const { promisify } = require('util') -const { getDesktopAskpassTrampolinePath, getDesktopCredentialHelperTrampolinePath } = require('../index') +const { + getDesktopAskpassTrampolinePath, + getDesktopCredentialHelperTrampolinePath, +} = require('../index') const split2 = require('split2') const { createServer } = require('net') @@ -59,7 +62,6 @@ describe('desktop-trampoline', () => { } it('forwards arguments and valid environment variables correctly', async () => { - const [portPromise, outputPromise] = captureSession() const port = await portPromise @@ -83,11 +85,12 @@ describe('desktop-trampoline', () => { }) it('forwards stdin when running in credential-helper mode', async () => { - const [portPromise, outputPromise] = captureSession() const port = await portPromise - const cp = run(helperTrampolinePath, ['get'], { env: { DESKTOP_PORT: port } }) + const cp = run(helperTrampolinePath, ['get'], { + env: { DESKTOP_PORT: port }, + }) cp.child.stdin.end('oh hai\n') await cp @@ -96,12 +99,13 @@ describe('desktop-trampoline', () => { expect(output.at(-1)).toBe('oh hai\n') }) - it('doesn\'t forward stdin when running in askpass mode', async () => { - + it("doesn't forward stdin when running in askpass mode", async () => { const [portPromise, outputPromise] = captureSession() const port = await portPromise - const cp = run(askPassTrampolinePath, ['get'], { env: { DESKTOP_PORT: port } }) + const cp = run(askPassTrampolinePath, ['get'], { + env: { DESKTOP_PORT: port }, + }) cp.child.stdin.end('oh hai\n') await cp From 70c6ea44ca533f2ef2f46361f03cc985e107de04 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 11:58:08 +0200 Subject: [PATCH 11/13] Use SetEnvironmentVariable on Windows Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- src/desktop-trampoline.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/desktop-trampoline.c b/src/desktop-trampoline.c index 039d67f..5267f28 100644 --- a/src/desktop-trampoline.c +++ b/src/desktop-trampoline.c @@ -6,9 +6,20 @@ #include "socket.h" +#ifdef WINDOWS +#include +#endif + #define BUFFER_LENGTH 4096 #define MAXIMUM_NUMBER_LENGTH 33 +#ifdef CREDENTIAL_HELPER + #define DESKTOP_TRAMPOLINE_IDENTIFIER "CREDENTIALHELPER" +#else + #define DESKTOP_TRAMPOLINE_IDENTIFIER "ASKPASS" +#endif + + #define WRITE_STRING_OR_EXIT(dataName, dataString) \ if (writeSocket(socket, dataString, strlen(dataString) + 1) != 0) { \ printSocketError("ERROR: Couldn't send " dataName); \ @@ -136,10 +147,10 @@ int runTrampolineClient(SOCKET *outSocket, int argc, char **argv, char **envp) { int main(int argc, char **argv, char **envp) { - #ifdef CREDENTIAL_HELPER - setenv("DESKTOP_TRAMPOLINE_IDENTIFIER", "CREDENTIALHELPER", 1); + #ifdef WINDOWS + SetEnvironmentVariable("DESKTOP_TRAMPOLINE_IDENTIFIER", DESKTOP_TRAMPOLINE_IDENTIFIER); #else - setenv("DESKTOP_TRAMPOLINE_IDENTIFIER", "ASKPASS", 1); + setenv("DESKTOP_TRAMPOLINE_IDENTIFIER", DESKTOP_TRAMPOLINE_IDENTIFIER, 1); #endif if (initializeNetwork() != 0) { From 458f595f7c6a14a395f1a41a31f2244912cacd59 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 12:16:25 +0200 Subject: [PATCH 12/13] Include DESKTOP_TRAMPOLINE_IDENTIFIER alongside environment Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- src/desktop-trampoline.c | 19 ++++------------- test/desktop-trampoline.test.js | 37 ++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/desktop-trampoline.c b/src/desktop-trampoline.c index 5267f28..0c59c00 100644 --- a/src/desktop-trampoline.c +++ b/src/desktop-trampoline.c @@ -6,10 +6,6 @@ #include "socket.h" -#ifdef WINDOWS -#include -#endif - #define BUFFER_LENGTH 4096 #define MAXIMUM_NUMBER_LENGTH 33 @@ -28,9 +24,8 @@ if (writeSocket(socket, dataString, strlen(dataString) + 1) != 0) { \ // This is a list of valid environment variables that GitHub Desktop might // send or expect to receive. -#define NUMBER_OF_VALID_ENV_VARS 2 +#define NUMBER_OF_VALID_ENV_VARS 1 static const char *sValidEnvVars[NUMBER_OF_VALID_ENV_VARS] = { - "DESKTOP_TRAMPOLINE_IDENTIFIER", "DESKTOP_TRAMPOLINE_TOKEN", }; @@ -92,8 +87,9 @@ int runTrampolineClient(SOCKET *outSocket, int argc, char **argv, char **envp) { } // Get the number of environment variables - char *validEnvVars[NUMBER_OF_VALID_ENV_VARS]; - int envc = 0; + char *validEnvVars[NUMBER_OF_VALID_ENV_VARS + 1]; + validEnvVars[0] = "DESKTOP_TRAMPOLINE_IDENTIFIER=" DESKTOP_TRAMPOLINE_IDENTIFIER; + int envc = 1; for (char **env = envp; *env != 0; env++) { if (isValidEnvVar(*env)) { validEnvVars[envc] = *env; @@ -146,13 +142,6 @@ int runTrampolineClient(SOCKET *outSocket, int argc, char **argv, char **envp) { } int main(int argc, char **argv, char **envp) { - - #ifdef WINDOWS - SetEnvironmentVariable("DESKTOP_TRAMPOLINE_IDENTIFIER", DESKTOP_TRAMPOLINE_IDENTIFIER); - #else - setenv("DESKTOP_TRAMPOLINE_IDENTIFIER", DESKTOP_TRAMPOLINE_IDENTIFIER, 1); - #endif - if (initializeNetwork() != 0) { return 1; } diff --git a/test/desktop-trampoline.test.js b/test/desktop-trampoline.test.js index 2dbe5b7..dadd427 100644 --- a/test/desktop-trampoline.test.js +++ b/test/desktop-trampoline.test.js @@ -80,8 +80,9 @@ describe('desktop-trampoline', () => { // output[2] is the number of env variables const envc = parseInt(output[2]) const outputEnv = output.slice(3, 3 + envc) - expect(outputEnv).toHaveLength(1) + expect(outputEnv).toHaveLength(2) expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_TOKEN=123456') + expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_IDENTIFIER=ASKPASS') }) it('forwards stdin when running in credential-helper mode', async () => { @@ -113,4 +114,38 @@ describe('desktop-trampoline', () => { const output = await outputPromise expect(output.at(-1)).toBe('') }) + + it("askpass handler ignores the DESKTOP_TRAMPOLINE_IDENTIFIER env var", async () => { + const [portPromise, outputPromise] = captureSession() + const port = await portPromise + + const cp = run(askPassTrampolinePath, ['get'], { + env: { DESKTOP_PORT: port, DESKTOP_TRAMPOLINE_IDENTIFIER: 'foo' }, + }) + cp.child.stdin.end('oh hai\n') + + await cp + + const output = await outputPromise + const envc = parseInt(output[2]) + const outputEnv = output.slice(3, 3 + envc) + expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_IDENTIFIER=ASKPASS') + }) + + it("credential handler ignores the DESKTOP_TRAMPOLINE_IDENTIFIER env var", async () => { + const [portPromise, outputPromise] = captureSession() + const port = await portPromise + + const cp = run(helperTrampolinePath, ['get'], { + env: { DESKTOP_PORT: port, DESKTOP_TRAMPOLINE_IDENTIFIER: 'foo' }, + }) + cp.child.stdin.end('oh hai\n') + + await cp + + const output = await outputPromise + const envc = parseInt(output[2]) + const outputEnv = output.slice(3, 3 + envc) + expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_IDENTIFIER=CREDENTIALHELPER') + }) }) From fd06e4cb74d61be78f6c8dec8bf9517bcbc3f20f Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 3 Jun 2024 12:17:18 +0200 Subject: [PATCH 13/13] Liiint Co-Authored-By: Sergio Padrino <1083228+sergiou87@users.noreply.github.com> --- test/desktop-trampoline.test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/desktop-trampoline.test.js b/test/desktop-trampoline.test.js index dadd427..db362cd 100644 --- a/test/desktop-trampoline.test.js +++ b/test/desktop-trampoline.test.js @@ -115,7 +115,7 @@ describe('desktop-trampoline', () => { expect(output.at(-1)).toBe('') }) - it("askpass handler ignores the DESKTOP_TRAMPOLINE_IDENTIFIER env var", async () => { + it('askpass handler ignores the DESKTOP_TRAMPOLINE_IDENTIFIER env var', async () => { const [portPromise, outputPromise] = captureSession() const port = await portPromise @@ -132,7 +132,7 @@ describe('desktop-trampoline', () => { expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_IDENTIFIER=ASKPASS') }) - it("credential handler ignores the DESKTOP_TRAMPOLINE_IDENTIFIER env var", async () => { + it('credential handler ignores the DESKTOP_TRAMPOLINE_IDENTIFIER env var', async () => { const [portPromise, outputPromise] = captureSession() const port = await portPromise @@ -146,6 +146,8 @@ describe('desktop-trampoline', () => { const output = await outputPromise const envc = parseInt(output[2]) const outputEnv = output.slice(3, 3 + envc) - expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_IDENTIFIER=CREDENTIALHELPER') + expect(outputEnv).toContain( + 'DESKTOP_TRAMPOLINE_IDENTIFIER=CREDENTIALHELPER' + ) }) })