diff --git a/src/exec_auth.ts b/src/exec_auth.ts index 468b0070fb..78df99439b 100644 --- a/src/exec_auth.ts +++ b/src/exec_auth.ts @@ -100,6 +100,9 @@ export class ExecAuth implements Authenticator { opts = { ...opts, env }; } const result = this.execFn(exec.command, exec.args, opts); + if (result.error) { + throw result.error; + } if (result.status === 0) { const obj = JSON.parse(result.stdout.toString('utf8')) as Credential; this.tokenCache[user.name] = obj; diff --git a/src/exec_auth_test.ts b/src/exec_auth_test.ts index 5417cbae57..fc4607be7b 100644 --- a/src/exec_auth_test.ts +++ b/src/exec_auth_test.ts @@ -192,6 +192,39 @@ describe('ExecAuth', () => { expect(opts.headers.Authorization).to.be.undefined; }); + it('should throw on spawnSync errors', () => { + // TODO: fix this test for Windows + if (process.platform === 'win32') { + return; + } + const auth = new ExecAuth(); + (auth as any).execFn = ( + command: string, + args: string[], + opts: child_process.SpawnOptions, + ): child_process.SpawnSyncReturns => { + return { + error: new Error('Error: spawnSync /path/to/bin ENOENT'), + } as child_process.SpawnSyncReturns; + }; + + const user = { + name: 'user', + authProvider: { + config: { + exec: { + command: '/path/to/bin', + }, + }, + }, + }; + const opts = {} as https.RequestOptions; + opts.headers = {} as OutgoingHttpHeaders; + + const promise = auth.applyAuthentication(user, opts); + return expect(promise).to.eventually.be.rejected.and.not.instanceOf(TypeError); + }); + it('should throw on exec errors', () => { // TODO: fix this test for Windows if (process.platform === 'win32') {