From f66cb9a7a5856a22a66f11f3118297143b232096 Mon Sep 17 00:00:00 2001 From: Jordan Webb Date: Sat, 5 Nov 2022 16:02:51 -0500 Subject: [PATCH] Domain matching should be case insensitive (#2) * Domain matching should be case insensitive * s/ValidateEmail/ValidateUser/ Co-authored-by: Mal Curtis --- internal/auth.go | 3 ++- internal/auth_test.go | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/auth.go b/internal/auth.go index 5906c594..99a17d33 100644 --- a/internal/auth.go +++ b/internal/auth.go @@ -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 } } diff --git a/internal/auth_test.go b/internal/auth_test.go index dd2ea305..f0e5fe6a 100644 --- a/internal/auth_test.go +++ b/internal/auth_test.go @@ -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"}