@@ -40,7 +40,7 @@ describe('getEndpoint', () => {
4040 } ) ;
4141
4242 it ( 'sets endpoint and logs on 200 with endpoint header' , async ( ) => {
43- const endpoint = 'http://endpoint ' ;
43+ const endpoint = '10.0.0.1:8080 ' ;
4444 globalThis . ngx = {
4545 fetch : vi . fn ( ) . mockResolvedValue ( {
4646 status : 200 ,
@@ -49,7 +49,11 @@ describe('getEndpoint', () => {
4949 } ) ,
5050 } ;
5151 const r = makeRequest ( {
52- variables : { epp_host : 'host' , epp_port : '1234' , epp_internal_path : '/foo' } ,
52+ variables : {
53+ epp_host : 'host' ,
54+ epp_port : '1234' ,
55+ epp_internal_path : '/foo' ,
56+ } ,
5357 } ) ;
5458 await epp . getEndpoint ( r ) ;
5559 expect ( r . variables . inference_workload_endpoint ) . toBe ( endpoint ) ;
@@ -66,7 +70,11 @@ describe('getEndpoint', () => {
6670 } ) ,
6771 } ;
6872 const r = makeRequest ( {
69- variables : { epp_host : 'host' , epp_port : '1234' , epp_internal_path : '/foo' } ,
73+ variables : {
74+ epp_host : 'host' ,
75+ epp_port : '1234' ,
76+ epp_internal_path : '/foo' ,
77+ } ,
7078 } ) ;
7179 await epp . getEndpoint ( r ) ;
7280 expect ( r . error ) . toHaveBeenCalledWith (
@@ -80,15 +88,19 @@ describe('getEndpoint', () => {
8088 fetch : vi . fn ( ) . mockRejectedValue ( new Error ( 'network fail' ) ) ,
8189 } ;
8290 const r = makeRequest ( {
83- variables : { epp_host : 'host' , epp_port : '1234' , epp_internal_path : '/foo' } ,
91+ variables : {
92+ epp_host : 'host' ,
93+ epp_port : '1234' ,
94+ epp_internal_path : '/foo' ,
95+ } ,
8496 } ) ;
8597 await epp . getEndpoint ( r ) ;
8698 expect ( r . error ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Error in ngx.fetch' ) ) ;
8799 expect ( r . internalRedirect ) . toHaveBeenCalledWith ( '/foo' ) ;
88100 } ) ;
89101
90102 it ( 'preserves args in internal redirect when args are present' , async ( ) => {
91- const endpoint = 'http://endpoint ' ;
103+ const endpoint = '10.0.0.1:8080 ' ;
92104 globalThis . ngx = {
93105 fetch : vi . fn ( ) . mockResolvedValue ( {
94106 status : 200 ,
@@ -97,21 +109,51 @@ describe('getEndpoint', () => {
97109 } ) ,
98110 } ;
99111 const r = makeRequest ( {
100- variables : { epp_host : 'host' , epp_port : '1234' , epp_internal_path : '/foo' } ,
112+ variables : {
113+ epp_host : 'host' ,
114+ epp_port : '1234' ,
115+ epp_internal_path : '/foo' ,
116+ } ,
101117 args : { a : '1' , b : '2' } ,
102118 } ) ;
103119 await epp . getEndpoint ( r ) ;
104120 expect ( r . internalRedirect ) . toHaveBeenCalledWith ( '/foo?a=1&b=2' ) ;
105121 } ) ;
106- it ( 'returns the header-specified endpoints if provided' , async ( ) => {
122+
123+ it ( 'forwards all headers including test headers to EPP' , async ( ) => {
124+ const endpoint = '10.0.0.1:8080' ;
125+ const fetchMock = vi . fn ( ) . mockResolvedValue ( {
126+ status : 200 ,
127+ headers : { get : ( ) => endpoint } ,
128+ text : vi . fn ( ) ,
129+ } ) ;
130+ globalThis . ngx = {
131+ fetch : fetchMock ,
132+ } ;
107133 const r = makeRequest ( {
108- variables : { } ,
109- headersIn : { 'X-Endpoint-Selector' : '10.1.2.3, 10.1.2.4' } ,
134+ variables : {
135+ epp_host : 'host' ,
136+ epp_port : '1234' ,
137+ epp_internal_path : '/foo' ,
138+ } ,
139+ headersIn : {
140+ 'test-epp-endpoint-selection' : '10.0.0.1:8080,10.0.0.2:8080' ,
141+ 'content-type' : 'application/json' ,
142+ } ,
110143 } ) ;
111144 await epp . getEndpoint ( r ) ;
112- expect ( r . variables . inference_workload_endpoint ) . toBe ( '10.1.2.3,10.1.2.4' ) ;
113- expect ( r . log ) . toHaveBeenCalledWith (
114- expect . stringContaining ( 'Using header-specified endpoints' ) ,
145+
146+ // Verify that all headers (including test header) were forwarded to EPP
147+ expect ( fetchMock ) . toHaveBeenCalledWith (
148+ 'http://127.0.0.1:54800' ,
149+ expect . objectContaining ( {
150+ headers : expect . objectContaining ( {
151+ 'test-epp-endpoint-selection' : '10.0.0.1:8080,10.0.0.2:8080' ,
152+ 'content-type' : 'application/json' ,
153+ 'X-EPP-Host' : 'host' ,
154+ 'X-EPP-Port' : '1234' ,
155+ } ) ,
156+ } ) ,
115157 ) ;
116158 } ) ;
117- } ) ;
159+ } ) ;
0 commit comments