Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: noop mutator don't overwrite session headers #1091

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}

davidspek marked this conversation as resolved.
Show resolved Hide resolved
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
Loading