Skip to content

Commit

Permalink
fix: noop mutator don't overwrite session headers (#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidspek authored Jul 5, 2023
1 parent 47e3d19 commit 3a716f2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pipeline/mutate/mutator_noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,22 @@ func (a *MutatorNoop) GetID() string {
}

func (a *MutatorNoop) Mutate(r *http.Request, session *authn.AuthenticationSession, config json.RawMessage, _ pipeline.Rule) error {
currentSessionHeaders := session.Header.Clone()
session.Header = r.Header
if session.Header == nil {
session.Header = make(map[string][]string)
}

for k, v := range currentSessionHeaders {
var val string
if len(v) == 0 {
val = ""
} else {
val = v[0]
}
session.SetHeader(k, val)
}

return nil
}

Expand Down
10 changes: 10 additions & 0 deletions pipeline/mutate/mutator_noop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ func TestMutatorNoop(t *testing.T) {
assert.EqualValues(t, r.Header, s.Header)
})

t.Run("method=mutate/case=ensure authentication session headers are kept", func(t *testing.T) {
r := &http.Request{Header: http.Header{"foo": {"foo"}}}
s := &authn.AuthenticationSession{Header: http.Header{"bar": {"bar"}}}
combinedHeaders := http.Header{"foo": {"foo"}}
combinedHeaders.Set("bar", "bar")
err := a.Mutate(r, s, nil, nil)
require.NoError(t, err)
assert.EqualValues(t, r.Header, combinedHeaders)
})

t.Run("method=validate", func(t *testing.T) {
conf.SetForTest(t, configuration.MutatorNoopIsEnabled, true)
require.NoError(t, a.Validate(nil))
Expand Down

0 comments on commit 3a716f2

Please sign in to comment.