nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: oauth2-proxy/oauth2-proxy
Pull request #1020 (2021-02-04 00:46:40)

Flatten array-based response headers
https://github.com/oauth2-proxy/oauth2-proxy/issues/1017

## Description

Array response headers weren't flattened, the `flattenHeaders` help was called on `req.Header`

## How Has This Been Tested?

Unit Tests

## Checklist:

- [x] My change requires a change to the documentation or CHANGELOG.
- [x] I have updated the documentation/CHANGELOG accordingly.
- [x] I have created a feature (non-master) branch for my PR.



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c5a9b09..8498a792 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,8 @@
 
 ## Changes since v7.0.0
 
+- [#1020](https://github.com/oauth2-proxy/oauth2-proxy/pull/1020) Flatten array-based response headers (@NickMeves)
+
 # V7.0.0
 
 ## Release Highlights
diff --git a/pkg/middleware/headers.go b/pkg/middleware/headers.go
index 0e47085a..cb032bfb 100644
--- a/pkg/middleware/headers.go
+++ b/pkg/middleware/headers.go
@@ -108,7 +108,7 @@ func injectResponseHeaders(injector header.Injector, next http.Handler) http.Han
 		// If scope is nil, this will panic.
 		// A scope should always be injected before this handler is called.
 		injector.Inject(rw.Header(), scope.Session)
-		flattenHeaders(req.Header)
+		flattenHeaders(rw.Header())
 		next.ServeHTTP(rw, req)
 	})
 }


Test patch:
diff --git a/pkg/middleware/headers_test.go b/pkg/middleware/headers_test.go
index 4cfd0c1b..fb99938c 100644
--- a/pkg/middleware/headers_test.go
+++ b/pkg/middleware/headers_test.go
@@ -249,7 +249,7 @@ var _ = Describe("Headers Suite", func() {
 			},
 			session: &sessionsapi.SessionState{},
 			expectedHeaders: http.Header{
-				"Foo": []string{"bar", "baz"},
+				"Foo": []string{"bar,baz"},
 			},
 			expectedErr: "",
 		}),
@@ -273,7 +273,7 @@ var _ = Describe("Headers Suite", func() {
 				IDToken: "IDToken-1234",
 			},
 			expectedHeaders: http.Header{
-				"Foo":   []string{"bar", "baz"},
+				"Foo":   []string{"bar,baz"},
 				"Claim": []string{"IDToken-1234"},
 			},
 			expectedErr: "",
@@ -298,7 +298,7 @@ var _ = Describe("Headers Suite", func() {
 				IDToken: "IDToken-1234",
 			},
 			expectedHeaders: http.Header{
-				"Claim": []string{"bar", "baz", "IDToken-1234"},
+				"Claim": []string{"bar,baz,IDToken-1234"},
 			},
 			expectedErr: "",
 		}),
@@ -323,7 +323,7 @@ var _ = Describe("Headers Suite", func() {
 				IDToken: "IDToken-1234",
 			},
 			expectedHeaders: http.Header{
-				"Claim": []string{"bar", "baz", "IDToken-1234"},
+				"Claim": []string{"bar,baz,IDToken-1234"},
 			},
 			expectedErr: "",
 		}),
@@ -345,7 +345,7 @@ var _ = Describe("Headers Suite", func() {
 			},
 			session: nil,
 			expectedHeaders: http.Header{
-				"Claim": []string{"bar", "baz"},
+				"Claim": []string{"bar,baz"},
 			},
 			expectedErr: "",
 		}),
@@ -368,7 +368,7 @@ var _ = Describe("Headers Suite", func() {
 			},
 			session: nil,
 			expectedHeaders: http.Header{
-				"Claim": []string{"bar", "baz"},
+				"Claim": []string{"bar,baz"},
 			},
 			expectedErr: "",
 		}),
Repository: oauth2-proxy/oauth2-proxy
Pull request #1882 (2022-11-03 13:10:19)

Fix for test race condition on htpasswd file
## Description

Make `htpasswd.GetUsers` racecondition safe



babs: After further reading, it seems that `len` is not atomic/thread safe so I suspect a resource sharing somewhere but I couldn't figure  out what exactly.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 16f0dfee..eee4ac9e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,8 @@
 
 ## Changes since v7.4.0
 
+- [#1882](https://github.com/oauth2-proxy/oauth2-proxy/pull/1882) Make `htpasswd.GetUsers` racecondition safe
+
 # V7.4.0
 
 ## Release Highlights
diff --git a/pkg/authentication/basic/htpasswd.go b/pkg/authentication/basic/htpasswd.go
index 8a4ac210..1bf187d5 100644
--- a/pkg/authentication/basic/htpasswd.go
+++ b/pkg/authentication/basic/htpasswd.go
@@ -139,6 +139,17 @@ func passShaOrBcrypt(h *htpasswdMap, user, password string) (invalidEntries []st
 	return invalidEntries
 }
 
+// GetUsers return a "thread safe" copy of the internal user list
+func (h *htpasswdMap) GetUsers() map[string]interface{} {
+	newUserList := make(map[string]interface{})
+	h.rwm.Lock()
+	for key, value := range h.users {
+		newUserList[key] = value
+	}
+	h.rwm.Unlock()
+	return newUserList
+}
+
 // Validate checks a users password against the htpasswd entries
 func (h *htpasswdMap) Validate(user string, password string) bool {
 	realPassword, exists := h.users[user]


Test patch:
diff --git a/pkg/authentication/basic/htpasswd_test.go b/pkg/authentication/basic/htpasswd_test.go
index 7e81f528..1a5d446c 100644
--- a/pkg/authentication/basic/htpasswd_test.go
+++ b/pkg/authentication/basic/htpasswd_test.go
@@ -149,7 +149,7 @@ var _ = Describe("HTPasswd Suite", func() {
 					fileNames = append(fileNames, file.Name())
 
 					It("has the correct number of users", func() {
-						Expect(len(htpasswd.users)).To(Equal(hu.expectedLen))
+						Expect(len(htpasswd.GetUsers())).To(Equal(hu.expectedLen))
 					})
 
 					It(hu.testText, func() {