@@ -321,7 +321,7 @@ describe('ConfigLoader', () => {
321321 expect ( config ) . to . have . property ( 'cookieSecret' ) ;
322322 } ) ;
323323
324- it ( 'should throw error for invalid configuration file path' , async function ( ) {
324+ it ( 'should throw error for invalid configuration file path (git) ' , async function ( ) {
325325 const source = {
326326 type : 'git' ,
327327 repository : 'https://github.com/finos/git-proxy.git' ,
@@ -338,6 +338,21 @@ describe('ConfigLoader', () => {
338338 }
339339 } ) ;
340340
341+ it ( 'should throw error for invalid configuration file path (file)' , async function ( ) {
342+ const source = {
343+ type : 'file' ,
344+ path : '\0' , // Invalid path
345+ enabled : true ,
346+ } ;
347+
348+ try {
349+ await configLoader . loadFromSource ( source ) ;
350+ throw new Error ( 'Expected error was not thrown' ) ;
351+ } catch ( error ) {
352+ expect ( error . message ) . to . equal ( 'Invalid configuration file path' ) ;
353+ }
354+ } ) ;
355+
341356 it ( 'should load configuration from http' , async function ( ) {
342357 // eslint-disable-next-line no-invalid-this
343358 this . timeout ( 10000 ) ;
@@ -390,6 +405,90 @@ describe('ConfigLoader', () => {
390405 }
391406 } ) ;
392407
408+ it ( 'should throw error if configuration source is invalid' , async function ( ) {
409+ const source = {
410+ type : 'invalid' ,
411+ repository : 'https://github.com/finos/git-proxy.git' ,
412+ path : 'proxy.config.json' ,
413+ branch : 'main' ,
414+ enabled : true ,
415+ } ;
416+
417+ try {
418+ await configLoader . loadFromSource ( source ) ;
419+ throw new Error ( 'Expected error was not thrown' ) ;
420+ } catch ( error ) {
421+ expect ( error . message ) . to . contain ( 'Unsupported configuration source type' ) ;
422+ }
423+ } ) ;
424+
425+ it ( 'should throw error if repository is a valid URL but not a git repository' , async function ( ) {
426+ const source = {
427+ type : 'git' ,
428+ repository : 'https://github.com/test-org/test-repo.git' ,
429+ path : 'proxy.config.json' ,
430+ branch : 'main' ,
431+ enabled : true ,
432+ } ;
433+
434+ try {
435+ await configLoader . loadFromSource ( source ) ;
436+ throw new Error ( 'Expected error was not thrown' ) ;
437+ } catch ( error ) {
438+ expect ( error . message ) . to . contain ( 'Failed to clone repository' ) ;
439+ }
440+ } ) ;
441+
442+ it ( 'should throw error if repository is a valid git repo but the branch does not exist' , async function ( ) {
443+ const source = {
444+ type : 'git' ,
445+ repository : 'https://github.com/finos/git-proxy.git' ,
446+ path : 'proxy.config.json' ,
447+ branch : 'branch-does-not-exist' ,
448+ enabled : true ,
449+ } ;
450+
451+ try {
452+ await configLoader . loadFromSource ( source ) ;
453+ throw new Error ( 'Expected error was not thrown' ) ;
454+ } catch ( error ) {
455+ expect ( error . message ) . to . contain ( 'Failed to checkout branch' ) ;
456+ }
457+ } ) ;
458+
459+ it ( 'should throw error if config path was not found' , async function ( ) {
460+ const source = {
461+ type : 'git' ,
462+ repository : 'https://github.com/finos/git-proxy.git' ,
463+ path : 'path-not-found.json' ,
464+ branch : 'main' ,
465+ enabled : true ,
466+ } ;
467+
468+ try {
469+ await configLoader . loadFromSource ( source ) ;
470+ throw new Error ( 'Expected error was not thrown' ) ;
471+ } catch ( error ) {
472+ expect ( error . message ) . to . contain ( 'Configuration file not found at' ) ;
473+ }
474+ } ) ;
475+
476+ it ( 'should throw error if config file is not valid JSON' , async function ( ) {
477+ const source = {
478+ type : 'git' ,
479+ repository : 'https://github.com/finos/git-proxy.git' ,
480+ path : 'test/fixtures/baz.js' ,
481+ branch : 'main' ,
482+ enabled : true ,
483+ } ;
484+
485+ try {
486+ await configLoader . loadFromSource ( source ) ;
487+ throw new Error ( 'Expected error was not thrown' ) ;
488+ } catch ( error ) {
489+ expect ( error . message ) . to . contain ( 'Failed to read or parse configuration file' ) ;
490+ }
491+ } ) ;
393492 } ) ;
394493
395494 describe ( 'deepMerge' , ( ) => {
0 commit comments