File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -311,9 +311,15 @@ func setupUpstreamAuthRequest(upstreamHttpAuth *v1alpha1.UpstreamHttpAuthService
311311 if err != nil {
312312 return nil , err
313313 }
314+
315+ svcName := getServiceName ()
316+ if ctxServiceName := request .Context ["serviceName" ]; ctxServiceName != "" {
317+ svcName = ctxServiceName
318+ }
319+
314320 req .Header = http.Header {
315321 upstreamHttpAuth .WriteTokenTo : {token },
316- "X-Service-Name" : {getServiceName () },
322+ "X-Service-Name" : {svcName },
317323 "Content-Type" : {"application/json" },
318324 }
319325 return req , nil
Original file line number Diff line number Diff line change @@ -981,6 +981,30 @@ func TestSetupUpstreamAuthRequest(t *testing.T) {
981981 assert .Error (t , actualErr , "Error should occur when service is empty" )
982982}
983983
984+ func TestSetupUpstreamAuthRequest_ServiceName_Context (t * testing.T ) {
985+ upstreamAuth := & cerberusv1alpha1.UpstreamHttpAuthService {
986+ ReadTokenFrom : "X-Token-Read" ,
987+ WriteTokenTo : "X-Token-Write" ,
988+ Address : "http://example.com" ,
989+ Timeout : 1000 ,
990+ }
991+
992+ request := & Request {
993+ Context : map [string ]string {
994+ "serviceName" : "test-service" ,
995+ },
996+ Request : http.Request {
997+ Header : http.Header {
998+ "X-Token-Read" : {"value" },
999+ },
1000+ },
1001+ }
1002+
1003+ httpReq , err := setupUpstreamAuthRequest (upstreamAuth , request )
1004+ assert .NoError (t , err )
1005+ assert .Equal (t , "test-service" , httpReq .Header .Get ("X-Service-Name" ))
1006+ }
1007+
9841008func TestCheck_SuccessfulAuthentication (t * testing.T ) {
9851009 mockHTTPClient := & http.Client {
9861010 Transport : & MockTransport {
You can’t perform that action at this time.
0 commit comments