Skip to content

Commit

Permalink
Domain matching should be case insensitive (#2)
Browse files Browse the repository at this point in the history
* Domain matching should be case insensitive

* s/ValidateEmail/ValidateUser/

Co-authored-by: Mal Curtis <mal@mal.co.nz>
  • Loading branch information
jordemort and snikch authored Nov 5, 2022
1 parent 2425768 commit f66cb9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ func ValidateDomains(user string, domains CommaSeparatedList) bool {
if len(parts) < 2 {
return false
}
emailDomain := strings.ToLower(parts[1])
for _, domain := range domains {
if domain == parts[1] {
if domain == emailDomain {
return true
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func TestAuthValidateUser(t *testing.T) {
v = ValidateUser("test@test.com", "default")
assert.True(v, "should allow user from allowed domain")

// Should match regardless of domain case
config.Domains = []string{"test.com"}
v = ValidateUser("test@TeSt.com", "default")
assert.True(v, "should allow user from allowed domain, regardless of case")

// Should block non whitelisted email address
config.Domains = []string{}
config.Whitelist = []string{"test@test.com"}
Expand Down

0 comments on commit f66cb9a

Please sign in to comment.