@@ -17,6 +17,8 @@ import (
1717 "github.com/kuadrant/authorino/pkg/evaluators"
1818 "github.com/kuadrant/authorino/pkg/evaluators/authorization"
1919 "github.com/kuadrant/authorino/pkg/evaluators/identity"
20+ "github.com/kuadrant/authorino/pkg/evaluators/response"
21+ "github.com/kuadrant/authorino/pkg/json"
2022
2123 envoy_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
2224 envoy_auth "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
@@ -200,18 +202,6 @@ func TestAuthServiceRawHTTPAuthorization_WithQueryString(t *testing.T) {
200202 assert .Equal (t , response .Code , 200 )
201203}
202204
203- func TestAuthServiceRawHTTPAuthorization_UnsupportedContentType (t * testing.T ) {
204- mockController := gomock .NewController (t )
205- defer mockController .Finish ()
206- cacheMock := mock_cache .NewMockCache (mockController )
207- authService := & AuthService {Cache : cacheMock }
208- request , _ := http .NewRequest ("POST" , "http://myapp.io/check" , bytes .NewReader ([]byte (`{}` )))
209- request .Header = map [string ][]string {"Content-Type" : {"text/plain" }}
210- response := gohttptest .NewRecorder ()
211- authService .ServeHTTP (response , request )
212- assert .Equal (t , response .Code , 400 )
213- }
214-
215205type notReadable struct {}
216206
217207func (n * notReadable ) Read (_ []byte ) (int , error ) {
@@ -230,6 +220,30 @@ func TestAuthServiceRawHTTPAuthorization_UnreadableBody(t *testing.T) {
230220 assert .Equal (t , response .Code , 400 )
231221}
232222
223+ func TestAuthServiceRawHTTPAuthorization_WithHeaders (t * testing.T ) {
224+ mockController := gomock .NewController (t )
225+ defer mockController .Finish ()
226+
227+ authConfig := mockAnonymousAccessAuthConfig ()
228+ authConfig .ResponseConfigs = []auth.AuthConfigEvaluator {& evaluators.ResponseConfig {
229+ Name : "x-auth-data" ,
230+ Wrapper : "httpHeader" ,
231+ WrapperKey : "x-auth-data" ,
232+ DynamicJSON : & response.DynamicJSON {
233+ Properties : []json.JSONProperty {{Name : "headers" , Value : json.JSONValue {Pattern : "context.request.http.headers" }}},
234+ },
235+ }}
236+ cacheMock := mock_cache .NewMockCache (mockController )
237+ cacheMock .EXPECT ().Get ("myapp.io" ).Return (authConfig )
238+ authService := & AuthService {Cache : cacheMock }
239+ request , _ := http .NewRequest ("POST" , "http://myapp.io/check" , bytes .NewReader ([]byte (`{}` )))
240+ request .Header = map [string ][]string {"Content-Type" : {"application/json" }, "Authorization" : {"Bearer secret" }}
241+ response := gohttptest .NewRecorder ()
242+ authService .ServeHTTP (response , request )
243+ assert .Equal (t , response .Code , 200 )
244+ assert .Equal (t , response .Header ().Get ("X-Auth-Data" ), `{"headers":{"authorization":"Bearer secret","content-type":"application/json"}}` )
245+ }
246+
233247func TestAuthServiceRawHTTPAuthorization_K8sAdmissionReviewAuthorized (t * testing.T ) {
234248 mockController := gomock .NewController (t )
235249 defer mockController .Finish ()
0 commit comments