Skip to content

Commit

Permalink
lowercase email addresses before authing to ES
Browse files Browse the repository at this point in the history
  • Loading branch information
jertel committed Sep 25, 2024
1 parent 8a57c7b commit 25116a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion server/modules/elastic/elastictransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"crypto/tls"
"net"
"net/http"
"strings"
"time"

"github.com/apex/log"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (transport *ElasticTransport) RoundTrip(req *http.Request) (*http.Response,
"searchUsername": user.SearchUsername,
"requestId": req.Context().Value(web.ContextKeyRequestId),
}).Debug("Executing Elastic request on behalf of user")
username := user.Email
username := strings.ToLower(user.Email)
if user.SearchUsername != "" {
username = user.SearchUsername
}
Expand Down
8 changes: 4 additions & 4 deletions server/modules/elastic/elastictransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestRoundTrip(tester *testing.T) {
transport.internal = dummy

user := model.NewUser()
user.Email = "test"
user.Email = "Test"
request, _ := http.NewRequest("GET", "", nil)
request = request.WithContext(context.WithValue(context.Background(), web.ContextKeyRequestor, user))
transport.RoundTrip(request)
Expand All @@ -44,10 +44,10 @@ func TestRoundTripSearchUsername(tester *testing.T) {
transport.internal = dummy

user := model.NewUser()
user.Email = "test"
user.SearchUsername = "mysearchuser"
user.Email = "Test"
user.SearchUsername = "Mysearchuser"
request, _ := http.NewRequest("GET", "", nil)
request = request.WithContext(context.WithValue(context.Background(), web.ContextKeyRequestor, user))
transport.RoundTrip(request)
assert.Equal(tester, "mysearchuser", dummy.username)
assert.Equal(tester, "Mysearchuser", dummy.username)
}

0 comments on commit 25116a1

Please sign in to comment.