@@ -569,10 +569,28 @@ describe('validateUrlWithDNS', () => {
569569 expect ( result . error ) . toContain ( 'https://' )
570570 } )
571571
572- it ( 'should reject localhost URLs' , async ( ) => {
572+ it ( 'should accept https localhost URLs' , async ( ) => {
573573 const result = await validateUrlWithDNS ( 'https://localhost/api' )
574- expect ( result . isValid ) . toBe ( false )
575- expect ( result . error ) . toContain ( 'localhost' )
574+ expect ( result . isValid ) . toBe ( true )
575+ expect ( result . resolvedIP ) . toBeDefined ( )
576+ } )
577+
578+ it ( 'should accept http localhost URLs' , async ( ) => {
579+ const result = await validateUrlWithDNS ( 'http://localhost/api' )
580+ expect ( result . isValid ) . toBe ( true )
581+ expect ( result . resolvedIP ) . toBeDefined ( )
582+ } )
583+
584+ it ( 'should accept IPv4 loopback URLs' , async ( ) => {
585+ const result = await validateUrlWithDNS ( 'http://127.0.0.1/api' )
586+ expect ( result . isValid ) . toBe ( true )
587+ expect ( result . resolvedIP ) . toBeDefined ( )
588+ } )
589+
590+ it ( 'should accept IPv6 loopback URLs' , async ( ) => {
591+ const result = await validateUrlWithDNS ( 'http://[::1]/api' )
592+ expect ( result . isValid ) . toBe ( true )
593+ expect ( result . resolvedIP ) . toBeDefined ( )
576594 } )
577595
578596 it ( 'should reject private IP URLs' , async ( ) => {
@@ -899,16 +917,37 @@ describe('validateExternalUrl', () => {
899917 expect ( result . error ) . toContain ( 'valid URL' )
900918 } )
901919
902- it . concurrent ( 'should reject localhost' , ( ) => {
920+ } )
921+
922+ describe ( 'localhost and loopback addresses' , ( ) => {
923+ it . concurrent ( 'should accept https localhost' , ( ) => {
903924 const result = validateExternalUrl ( 'https://localhost/api' )
904- expect ( result . isValid ) . toBe ( false )
905- expect ( result . error ) . toContain ( 'localhost' )
925+ expect ( result . isValid ) . toBe ( true )
906926 } )
907927
908- it . concurrent ( 'should reject 127.0.0.1' , ( ) => {
928+ it . concurrent ( 'should accept http localhost' , ( ) => {
929+ const result = validateExternalUrl ( 'http://localhost/api' )
930+ expect ( result . isValid ) . toBe ( true )
931+ } )
932+
933+ it . concurrent ( 'should accept https 127.0.0.1' , ( ) => {
909934 const result = validateExternalUrl ( 'https://127.0.0.1/api' )
910- expect ( result . isValid ) . toBe ( false )
911- expect ( result . error ) . toContain ( 'private IP' )
935+ expect ( result . isValid ) . toBe ( true )
936+ } )
937+
938+ it . concurrent ( 'should accept http 127.0.0.1' , ( ) => {
939+ const result = validateExternalUrl ( 'http://127.0.0.1/api' )
940+ expect ( result . isValid ) . toBe ( true )
941+ } )
942+
943+ it . concurrent ( 'should accept https IPv6 loopback' , ( ) => {
944+ const result = validateExternalUrl ( 'https://[::1]/api' )
945+ expect ( result . isValid ) . toBe ( true )
946+ } )
947+
948+ it . concurrent ( 'should accept http IPv6 loopback' , ( ) => {
949+ const result = validateExternalUrl ( 'http://[::1]/api' )
950+ expect ( result . isValid ) . toBe ( true )
912951 } )
913952
914953 it . concurrent ( 'should reject 0.0.0.0' , ( ) => {
@@ -989,9 +1028,9 @@ describe('validateImageUrl', () => {
9891028 expect ( result . isValid ) . toBe ( true )
9901029 } )
9911030
992- it . concurrent ( 'should reject localhost URLs' , ( ) => {
1031+ it . concurrent ( 'should accept localhost URLs' , ( ) => {
9931032 const result = validateImageUrl ( 'https://localhost/image.png' )
994- expect ( result . isValid ) . toBe ( false )
1033+ expect ( result . isValid ) . toBe ( true )
9951034 } )
9961035
9971036 it . concurrent ( 'should use imageUrl as default param name' , ( ) => {
0 commit comments