File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,9 @@ export class ExecAuth implements Authenticator {
100
100
opts = { ...opts , env } ;
101
101
}
102
102
const result = this . execFn ( exec . command , exec . args , opts ) ;
103
+ if ( result . error ) {
104
+ throw result . error ;
105
+ }
103
106
if ( result . status === 0 ) {
104
107
const obj = JSON . parse ( result . stdout . toString ( 'utf8' ) ) as Credential ;
105
108
this . tokenCache [ user . name ] = obj ;
Original file line number Diff line number Diff line change @@ -192,6 +192,39 @@ describe('ExecAuth', () => {
192
192
expect ( opts . headers . Authorization ) . to . be . undefined ;
193
193
} ) ;
194
194
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
+
195
228
it ( 'should throw on exec errors' , ( ) => {
196
229
// TODO: fix this test for Windows
197
230
if ( process . platform === 'win32' ) {
You can’t perform that action at this time.
0 commit comments