git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #1882 from babs/atrocious-fix-for-test-race-condition-on-htpasswd
9484a67Joel Speed
CHANGELOG.md+2
@@ -8,6 +8,8 @@
8
8
9## Changes since v7.4.0
9## Changes since v7.4.0
10
10
11+- [#1882](https://github.com/oauth2-proxy/oauth2-proxy/pull/1882) Make `htpasswd.GetUsers` racecondition safe
12+
11# V7.4.0
13# V7.4.0
12
14
13## Release Highlights
15## Release Highlights
pkg/authentication/basic/htpasswd.go+11
@@ -139,6 +139,17 @@ func passShaOrBcrypt(h *htpasswdMap, user, password string) (invalidEntries []st
139 return invalidEntries
139 return invalidEntries
140}
140}
141
141
142+// GetUsers return a "thread safe" copy of the internal user list
143+func (h *htpasswdMap) GetUsers() map[string]interface{} {
144+ newUserList := make(map[string]interface{})
145+ h.rwm.Lock()
146+ for key, value := range h.users {
147+ newUserList[key] = value
148+ }
149+ h.rwm.Unlock()
150+ return newUserList
151+}
152+
142// Validate checks a users password against the htpasswd entries
153// Validate checks a users password against the htpasswd entries
143func (h *htpasswdMap) Validate(user string, password string) bool {
154func (h *htpasswdMap) Validate(user string, password string) bool {
144 realPassword, exists := h.users[user]
155 realPassword, exists := h.users[user]
pkg/authentication/basic/htpasswd_test.go+1−1
@@ -149,7 +149,7 @@ var _ = Describe("HTPasswd Suite", func() {
149 fileNames = append(fileNames, file.Name())
149 fileNames = append(fileNames, file.Name())
150
150
151 It("has the correct number of users", func() {
151 It("has the correct number of users", func() {
152− Expect(len(htpasswd.users)).To(Equal(hu.expectedLen))
152+ Expect(len(htpasswd.GetUsers())).To(Equal(hu.expectedLen))
153 })
153 })
154
154
155 It(hu.testText, func() {
155 It(hu.testText, func() {