Skip to content

Commit

Permalink
better backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
gen1us2k authored and aeneasr committed May 26, 2022
1 parent 81c0fae commit aeba3ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions pipeline/authn/authenticator_bearer_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func (a *AuthenticatorBearerToken) Config(config json.RawMessage) (*Authenticato
if len(c.SubjectFrom) == 0 {
c.SubjectFrom = "sub"
}
if len(c.ForwardHTTPHeaders) == 0 {
c.ForwardHTTPHeaders = []string{header.Authorization, header.Cookie}
}

// Add Authorization and Cookie headers for backward compatibility
c.ForwardHTTPHeaders = append(c.ForwardHTTPHeaders, []string{header.Authorization, header.Cookie}...)
c.ForwardHTTPHeadersMap = make(map[string]string)

for _, h := range c.ForwardHTTPHeaders {
Expand Down
14 changes: 7 additions & 7 deletions pipeline/authn/authenticator_bearer_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestAuthenticatorBearerToken(t *testing.T) {
w.WriteHeader(200)
w.Write([]byte(`{"sub": "123"}`))
},
config: []byte(`{"preserve_query": true, "forward_http_headers": ["Authorization"]}`),
config: []byte(`{"preserve_query": true}`),
expectErr: false,
expectSess: &AuthenticationSession{
Subject: "123",
Expand All @@ -113,7 +113,7 @@ func TestAuthenticatorBearerToken(t *testing.T) {
w.WriteHeader(200)
w.Write([]byte(`{"sub": "123"}`))
},
config: []byte(`{"preserve_path": true, "preserve_query": false, "forward_http_headers": ["Authorization"]}`),
config: []byte(`{"preserve_path": true, "preserve_query": false}`),
expectErr: false,
expectSess: &AuthenticationSession{
Subject: "123",
Expand All @@ -128,7 +128,7 @@ func TestAuthenticatorBearerToken(t *testing.T) {
w.WriteHeader(200)
w.Write([]byte(`{"sub": "123"}`))
},
config: []byte(`{"preserve_path": true, "force_method": "GET", "forward_http_headers": ["Authorization"]}`),
config: []byte(`{"preserve_path": true, "force_method": "GET"}`),
expectErr: false,
expectSess: &AuthenticationSession{
Subject: "123",
Expand All @@ -145,7 +145,7 @@ func TestAuthenticatorBearerToken(t *testing.T) {
w.WriteHeader(200)
w.Write([]byte(`{"sub": "123"}`))
},
config: []byte(`{"preserve_path": false, "preserve_query": true, "forward_http_headers": ["Authorization"]}`),
config: []byte(`{"preserve_path": false, "preserve_query": true}`),
expectErr: false,
expectSess: &AuthenticationSession{
Subject: "123",
Expand All @@ -160,7 +160,7 @@ func TestAuthenticatorBearerToken(t *testing.T) {
w.WriteHeader(200)
w.Write([]byte(`{"sub": "123"}`))
},
config: []byte(`{"preserve_path": true, "preserve_query": true, "check_session_url": "http://origin-replaced-in-test/configured/path?q=configured-query", "forward_http_headers": ["Authorization", "X-Forwared-Host"]}`),
config: []byte(`{"preserve_path": true, "preserve_query": true, "check_session_url": "http://origin-replaced-in-test/configured/path?q=configured-query", "forward_http_headers": ["X-Forwared-Host"]}`),
expectErr: false,
expectSess: &AuthenticationSession{
Subject: "123",
Expand All @@ -176,7 +176,7 @@ func TestAuthenticatorBearerToken(t *testing.T) {
w.WriteHeader(200)
w.Write([]byte(`{"sub": "123"}`))
},
config: []byte(`{"preserve_host": true, "forward_http_headers": ["Authorization"]}`),
config: []byte(`{"preserve_host": true}`),
expectErr: false,
expectSess: &AuthenticationSession{
Subject: "123",
Expand All @@ -193,7 +193,7 @@ func TestAuthenticatorBearerToken(t *testing.T) {
w.WriteHeader(200)
w.Write([]byte(`{"sub": "123"}`))
},
config: []byte(`{"preserve_host": true, "additional_headers": {"X-Foo": "bar","X-Forwarded-For": "not-some-host"}, "forward_http_headers":["Authorization"]}`),
config: []byte(`{"preserve_host": true, "additional_headers": {"X-Foo": "bar","X-Forwarded-For": "not-some-host"}}`),
expectErr: false,
expectSess: &AuthenticationSession{
Subject: "123",
Expand Down
6 changes: 3 additions & 3 deletions pipeline/authn/authenticator_cookie_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func (a *AuthenticatorCookieSession) Config(config json.RawMessage) (*Authentica
if len(c.SubjectFrom) == 0 {
c.SubjectFrom = "subject"
}
if len(c.ForwardHTTPHeaders) == 0 {
c.ForwardHTTPHeaders = []string{header.Authorization, header.Cookie}
}

// Add Authorization and Cookie headers for backward compatibility
c.ForwardHTTPHeaders = append(c.ForwardHTTPHeaders, []string{header.Authorization, header.Cookie}...)

c.ForwardHTTPHeadersMap = make(map[string]string)
for _, h := range c.ForwardHTTPHeaders {
Expand Down

0 comments on commit aeba3ce

Please sign in to comment.