Skip to content

Commit dff722e

Browse files
authored
Merge pull request #1810 from 0x5457/fix-exec-auth-error
fix: if spawnSync has an error should throw it
2 parents 7a41de9 + 68cfcf2 commit dff722e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/exec_auth.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ export class ExecAuth implements Authenticator {
100100
opts = { ...opts, env };
101101
}
102102
const result = this.execFn(exec.command, exec.args, opts);
103+
if (result.error) {
104+
throw result.error;
105+
}
103106
if (result.status === 0) {
104107
const obj = JSON.parse(result.stdout.toString('utf8')) as Credential;
105108
this.tokenCache[user.name] = obj;

src/exec_auth_test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,39 @@ describe('ExecAuth', () => {
192192
expect(opts.headers.Authorization).to.be.undefined;
193193
});
194194

195+
it('should throw on spawnSync errors', () => {
196+
// TODO: fix this test for Windows
197+
if (process.platform === 'win32') {
198+
return;
199+
}
200+
const auth = new ExecAuth();
201+
(auth as any).execFn = (
202+
command: string,
203+
args: string[],
204+
opts: child_process.SpawnOptions,
205+
): child_process.SpawnSyncReturns<Buffer> => {
206+
return {
207+
error: new Error('Error: spawnSync /path/to/bin ENOENT'),
208+
} as child_process.SpawnSyncReturns<Buffer>;
209+
};
210+
211+
const user = {
212+
name: 'user',
213+
authProvider: {
214+
config: {
215+
exec: {
216+
command: '/path/to/bin',
217+
},
218+
},
219+
},
220+
};
221+
const opts = {} as https.RequestOptions;
222+
opts.headers = {} as OutgoingHttpHeaders;
223+
224+
const promise = auth.applyAuthentication(user, opts);
225+
return expect(promise).to.eventually.be.rejected.and.not.instanceOf(TypeError);
226+
});
227+
195228
it('should throw on exec errors', () => {
196229
// TODO: fix this test for Windows
197230
if (process.platform === 'win32') {

0 commit comments

Comments
 (0)