Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/exec_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class ExecAuth implements Authenticator {
}
let opts = {};
if (exec.env) {
const env = process.env;
const env = { ...process.env };
exec.env.forEach((elt) => (env[elt.name] = elt.value));
opts = { ...opts, env };
}
Expand Down
59 changes: 59 additions & 0 deletions src/exec_auth_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,63 @@ describe('ExecAuth', () => {
const promise = auth.applyAuthentication(user, opts);
await rejects(promise, { name: 'SyntaxError' });
});

it('should not overwrite environment variables in process.env', async () => {
// TODO: fix this test for Windows
if (process.platform === 'win32') {
return;
}
const auth = new ExecAuth();
let optsOut: child_process.SpawnOptions | undefined = {};
(auth as any).execFn = (
command: string,
args?: readonly string[],
options?: child_process.SpawnOptionsWithoutStdio,
): child_process.ChildProcessWithoutNullStreams => {
optsOut = options;
return {
stdout: {
setEncoding: () => {},
on: (_data: string, f: (data: Buffer | string) => void) => {
f(Buffer.from(JSON.stringify({ status: { token: 'foo' } })));
},
},
stderr: {
setEncoding: () => {},
on: () => {},
},
on: (op: string, f: any) => {
if (op === 'close') {
f(0);
}
},
} as unknown as child_process.ChildProcessWithoutNullStreams;
};

process.env.DO_NO_OVERWRITE_ME = 'important';
const opts = {} as https.RequestOptions;
opts.headers = {} as OutgoingHttpHeaders;

await auth.applyAuthentication(
{
name: 'user',
authProvider: {
config: {
exec: {
command: 'echo',
env: [
{
name: 'DO_NO_OVERWRITE_ME',
value: 'in exec',
},
],
},
},
},
},
opts,
);
strictEqual(optsOut.env!.DO_NO_OVERWRITE_ME, 'in exec');
strictEqual(process.env.DO_NO_OVERWRITE_ME, 'important');
});
});