1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-01-22 05:19:26 +02:00

Merge pull request #1882 from babs/atrocious-fix-for-test-race-condition-on-htpasswd

Fix for test race condition on htpasswd file
This commit is contained in:
Joel Speed 2022-11-03 14:46:20 +00:00 committed by GitHub
commit 9484a67afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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]

View File

@ -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() {