Skip to content

Commit

Permalink
Remove DESKTOP_PORT from the valid env vars
Browse files Browse the repository at this point in the history
DESKTOP_PORT is only for internal usage, no need to forward it.
  • Loading branch information
sergiou87 committed Feb 2, 2021
1 parent b111470 commit 8c44f4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/desktop-trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ 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 5
#define NUMBER_OF_VALID_ENV_VARS 4
static const char *sValidEnvVars[NUMBER_OF_VALID_ENV_VARS] = {
"DESKTOP_TRAMPOLINE_IDENTIFIER",
"DESKTOP_PORT",
"DESKTOP_TRAMPOLINE_TOKEN",
"DESKTOP_USERNAME",
"DESKTOP_ENDPOINT",
Expand All @@ -33,8 +32,8 @@ int isValidEnvVar(char *env) {

// Make sure that not only the passed env var string starts with the
// candidate contesnts, but also that there is a '=' character right after:
// Valid: "DESKTOP_PORT=50"
// Not valid: "DESKTOP_PORT_SOMETHING=50"
// Valid: "DESKTOP_USERNAME=sergiou87"
// Not valid: "DESKTOP_USERNAME_SOMETHING=sergiou87"
if (strncmp(env, candidate, strlen(candidate)) == 0
&& strlen(env) > strlen(candidate)
&& env[strlen(candidate)] == '=') {
Expand Down
6 changes: 4 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('desktop-trampoline', () => {
// done forwarding data.
socket.end()
})
server.unref()

const startTrampolineServer = async () => {
return new Promise((resolve, reject) => {
Expand All @@ -42,9 +43,10 @@ describe('desktop-trampoline', () => {

const port = await startTrampolineServer()
const env = {
DESKTOP_PORT_FAKE: 32123,
DESKTOP_TRAMPOLINE_IDENTIFIER: '123456',
DESKTOP_PORT: port,
DESKTOP_USERNAME: 'sergiou87',
DESKTOP_USERNAME_FAKE: 'fake-user',
INVALID_VARIABLE: 'foo bar',
}
const opts = { env }
Expand All @@ -57,7 +59,7 @@ describe('desktop-trampoline', () => {
const outputEnv = output.slice(3)
expect(outputEnv).toHaveLength(2)
expect(outputEnv).toContain('DESKTOP_TRAMPOLINE_IDENTIFIER=123456')
expect(outputEnv).toContain(`DESKTOP_PORT=${port}`)
expect(outputEnv).toContain(`DESKTOP_USERNAME=sergiou87`)

server.close()
})
Expand Down

0 comments on commit 8c44f4b

Please sign in to comment.