@@ -24,6 +24,7 @@ import (
2424 "testing"
2525 "time"
2626
27+ "github.com/agent-substrate/substrate/internal/atunnel"
2728 "github.com/agent-substrate/substrate/pkg/proto/ateapipb"
2829 corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
2930 extprocv3 "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
@@ -58,7 +59,7 @@ func TestHandleRequestHeadersDoesNotLogSensitiveData(t *testing.T) {
5859 resumeFn : func (ctx context.Context , in * ateapipb.ResumeActorRequest , opts ... grpc.CallOption ) (* ateapipb.ResumeActorResponse , error ) {
5960 return & ateapipb.ResumeActorResponse {Actor : & ateapipb.Actor {AteomPodIp : "10.0.0.52" }}, nil
6061 },
61- }, nil , ParkedRequestConfig {}, nil )
62+ }, nil , ParkedRequestConfig {}, nil , false )
6263
6364 reqHeaders := & extprocv3.HttpHeaders {
6465 Headers : & corev3.HeaderMap {
@@ -195,7 +196,7 @@ func TestExtProcHeadersEvaluation(t *testing.T) {
195196 // Parking disabled: these cases assert fail-fast mapping of resume
196197 // errors (e.g. FailedPrecondition -> immediate 503). Parking behavior
197198 // is covered separately in TestExtProc_ParkingLotFull and resumer_test.go.
198- s := NewExtProcServer (50051 , clientMock , nil , ParkedRequestConfig {}, nil )
199+ s := NewExtProcServer (50051 , clientMock , nil , ParkedRequestConfig {}, nil , false )
199200
200201 reqHeaders := & extprocv3.HttpHeaders {
201202 Headers : & corev3.HeaderMap {
@@ -236,17 +237,19 @@ func TestExtProcHeadersEvaluation(t *testing.T) {
236237 }
237238
238239 mutation := res .Response .GetHeaderMutation ()
239- if len (mutation .GetSetHeaders ()) != 1 {
240- t .Fatalf ("expected exactly one Header option set , found: %v" , mutation .GetSetHeaders ())
240+ if len (mutation .GetSetHeaders ()) != 2 {
241+ t .Fatalf ("expected exactly two header options , found: %v" , mutation .GetSetHeaders ())
241242 }
242243
243- headerOption := mutation . GetSetHeaders ()[ 0 ]
244- if strings . ToLower ( headerOption . Header . Key ) != OriginalDstHeader {
245- t . Errorf ( "invalid resulting dynamic parameter key: %s" , headerOption .Header .Key )
244+ gotMutations := map [ string ] string {}
245+ for _ , headerOption := range mutation . GetSetHeaders () {
246+ gotMutations [ strings . ToLower ( headerOption . Header . Key )] = string ( headerOption .Header .RawValue )
246247 }
247-
248- if string (headerOption .Header .RawValue ) != tc .expectedTarget {
249- t .Errorf ("invalid destination mapping found: %s, expected: %s" , headerOption .Header .RawValue , tc .expectedTarget )
248+ if got := gotMutations [OriginalDstHeader ]; got != tc .expectedTarget {
249+ t .Errorf ("destination mutation = %q, want %q" , got , tc .expectedTarget )
250+ }
251+ if got := gotMutations [strings .ToLower (atunnel .OriginalHostHeader )]; got != tc .authority {
252+ t .Errorf ("original host mutation = %q, want %q" , got , tc .authority )
250253 }
251254
252255 // Confirm that query logs recorded metric trace details
@@ -271,7 +274,7 @@ func TestAgentgatewayRoutingHeaders(t *testing.T) {
271274 t .Fatal (err )
272275 }
273276 headers := res .Response .GetHeaderMutation ().GetSetHeaders ()
274- if len (headers ) != 2 || headers [0 ].GetHeader ().GetKey () != ":authority" || string (headers [0 ].GetHeader ().GetRawValue ()) != "10.0.0.52:443" || headers [ 1 ]. GetHeader (). GetKey () != ActorHostHeader || string ( headers [ 1 ]. GetHeader (). GetRawValue ()) != host {
277+ if len (headers ) != 3 || headers [2 ].GetHeader ().GetKey () != authorityHeader || string (headers [2 ].GetHeader ().GetRawValue ()) != "10.0.0.52:443" {
275278 t .Fatalf ("Agentgateway mutations = %v" , headers )
276279 }
277280}
@@ -291,7 +294,7 @@ func TestExtProc_ParkingLotFull(t *testing.T) {
291294
292295 // A 1-slot lot with the slot already occupied deterministically simulates a
293296 // full lot without needing a concurrent in-flight request.
294- s := NewExtProcServer (50051 , clientMock , nil , ParkedRequestConfig {Budget : time .Second , Max : 1 }, nil )
297+ s := NewExtProcServer (50051 , clientMock , nil , ParkedRequestConfig {Budget : time .Second , Max : 1 }, nil , false )
295298 release , ok := s .parking .enter (context .Background ())
296299 if ! ok {
297300 t .Fatal ("priming enter should be admitted" )
@@ -410,7 +413,7 @@ func TestRecordRouteDuration_Attributes(t *testing.T) {
410413 t .Fatalf ("failed to create histogram: %v" , err )
411414 }
412415
413- s := NewExtProcServer (50051 , nil , h , ParkedRequestConfig {}, nil )
416+ s := NewExtProcServer (50051 , nil , h , ParkedRequestConfig {}, nil , false )
414417 s .recordRouteDuration (context .Background (), 10 * time .Millisecond , "team-a-ns" , "tmpl-a" , classifyOutcome (nil ), string (ResumeOutcomeTriggered ))
415418
416419 var rm metricdata.ResourceMetrics
@@ -435,3 +438,25 @@ func TestRecordRouteDuration_Attributes(t *testing.T) {
435438 }
436439 }
437440}
441+
442+ func TestAddRoutingMutationsViaAuthority (t * testing.T ) {
443+ mutation := & extprocv3.HeaderMutation {}
444+ addRoutingMutations ("10.0.0.52:443" , "actor-1.team-a.actors.resources.substrate.ate.dev" , true , mutation )
445+
446+ got := map [string ]string {}
447+ for _ , option := range mutation .GetSetHeaders () {
448+ if option .GetAppendAction () != corev3 .HeaderValueOption_OVERWRITE_IF_EXISTS_OR_ADD {
449+ t .Errorf ("mutation %q append action = %v, want overwrite" , option .GetHeader ().GetKey (), option .GetAppendAction ())
450+ }
451+ got [strings .ToLower (option .GetHeader ().GetKey ())] = string (option .GetHeader ().GetRawValue ())
452+ }
453+ if got [OriginalDstHeader ] != "10.0.0.52:443" {
454+ t .Errorf ("%s = %q" , OriginalDstHeader , got [OriginalDstHeader ])
455+ }
456+ if got [strings .ToLower (atunnel .OriginalHostHeader )] != "actor-1.team-a.actors.resources.substrate.ate.dev" {
457+ t .Errorf ("%s = %q" , atunnel .OriginalHostHeader , got [strings .ToLower (atunnel .OriginalHostHeader )])
458+ }
459+ if got [authorityHeader ] != "10.0.0.52:443" {
460+ t .Errorf ("%s = %q" , authorityHeader , got [authorityHeader ])
461+ }
462+ }
0 commit comments