Skip to content

Commit

Permalink
feat: pass query parameters to the hydrators (#479)
Browse files Browse the repository at this point in the history
Co-authored-by: Krystian Cieslik <[email protected]>
  • Loading branch information
crabtree and crabtree authored Jul 10, 2020
1 parent e2baa9c commit 48603a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pipeline/mutate/mutator_hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ func (a *MutatorHydrator) Mutate(r *http.Request, session *authn.AuthenticationS
if err != nil {
return errors.WithStack(err)
}

if r.URL != nil {
q := r.URL.Query()
req.URL.RawQuery = q.Encode()
}

for key, values := range r.Header {
for _, value := range values {
req.Header.Add(key, value)
Expand Down
22 changes: 22 additions & 0 deletions pipeline/mutate/mutator_hydrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"testing"

"github.com/julienschmidt/httprouter"
Expand Down Expand Up @@ -324,6 +325,27 @@ func TestMutatorHydrator(t *testing.T) {
Match: newAuthenticationSession(setExtra(sampleKey, sampleValue)),
Err: nil,
},
"Pass Query Parameters": {
Setup: func(t *testing.T) http.Handler {
router := httprouter.New()
router.POST("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
q := r.URL.Query()
assert.Equal(t, len(q), 2)
assert.Equal(t, q["a"], []string{"b"})
assert.Equal(t, q["c"], []string{"&12"})

_, err = w.Write([]byte(`{}`))
require.NoError(t, err)
})
return router
},
Session: newAuthenticationSession(),
Rule: &rule.Rule{ID: "test-rule"},
Config: defaultConfigForMutator(),
Request: &http.Request{URL: &url.URL{RawQuery: "a=b&c=%2612"}},
Match: newAuthenticationSession(),
Err: nil,
},
}

for testName, specs := range testMap {
Expand Down

0 comments on commit 48603a1

Please sign in to comment.