From 7fe2c094a9012851f3dccd11763e570e38722583 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Thu, 13 Oct 2022 11:02:43 +0200 Subject: [PATCH] Other: Match any case in IMAP/SMTP auth, with test --- internal/user/user.go | 2 +- tests/bdd_test.go | 1 + tests/features/imap/auth.feature | 10 +++++++++- tests/imap_test.go | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/user/user.go b/internal/user/user.go index 83dc1ecc..615fa7b8 100644 --- a/internal/user/user.go +++ b/internal/user/user.go @@ -375,7 +375,7 @@ func (user *User) checkAuth(email string, password []byte) (string, error) { return safe.MapValuesRetErr(user.apiAddrs, func(apiAddrs []liteapi.Address) (string, error) { for _, addr := range apiAddrs { - if addr.Email == strings.ToLower(email) { + if strings.EqualFold(addr.Email, strings.ToLower(email)) { return addr.ID, nil } } diff --git a/tests/bdd_test.go b/tests/bdd_test.go index c20a8731..376d93c8 100644 --- a/tests/bdd_test.go +++ b/tests/bdd_test.go @@ -140,6 +140,7 @@ func TestFeatures(testingT *testing.T) { ctx.Step(`^user "([^"]*)" connects and authenticates IMAP client "([^"]*)"$`, s.userConnectsAndAuthenticatesIMAPClient) ctx.Step(`^user "([^"]*)" connects and authenticates IMAP client "([^"]*)" with address "([^"]*)"$`, s.userConnectsAndAuthenticatesIMAPClientWithAddress) ctx.Step(`^IMAP client "([^"]*)" can authenticate$`, s.imapClientCanAuthenticate) + ctx.Step(`^IMAP client "([^"]*)" can authenticate with address "([^"]*)"$`, s.imapClientCanAuthenticateWithAddress) ctx.Step(`^IMAP client "([^"]*)" cannot authenticate$`, s.imapClientCannotAuthenticate) ctx.Step(`^IMAP client "([^"]*)" cannot authenticate with address "([^"]*)"$`, s.imapClientCannotAuthenticateWithAddress) ctx.Step(`^IMAP client "([^"]*)" cannot authenticate with incorrect username$`, s.imapClientCannotAuthenticateWithIncorrectUsername) diff --git a/tests/features/imap/auth.feature b/tests/features/imap/auth.feature index 5e4386ff..fb2dc6a2 100644 --- a/tests/features/imap/auth.feature +++ b/tests/features/imap/auth.feature @@ -8,6 +8,14 @@ Feature: A user can authenticate an IMAP client When user "user@pm.me" connects IMAP client "1" Then IMAP client "1" can authenticate + Scenario: IMAP client can authenticate successfully with different case + When user "user@pm.me" connects IMAP client "1" + Then IMAP client "1" can authenticate with address "USER@PM.ME" + + Scenario: IMAP client can authenticate successfully + When user "user@pm.me" connects IMAP client "1" + Then IMAP client "1" can authenticate + Scenario: IMAP client cannot authenticate with bad username When user "user@pm.me" connects IMAP client "1" Then IMAP client "1" cannot authenticate with incorrect username @@ -19,4 +27,4 @@ Feature: A user can authenticate an IMAP client Scenario: IMAP client cannot authenticate for disconnected user When user "user@pm.me" logs out And user "user@pm.me" connects IMAP client "1" - Then IMAP client "1" cannot authenticate \ No newline at end of file + Then IMAP client "1" cannot authenticate diff --git a/tests/imap_test.go b/tests/imap_test.go index 8edeafcc..90117bc7 100644 --- a/tests/imap_test.go +++ b/tests/imap_test.go @@ -45,6 +45,12 @@ func (s *scenario) imapClientCanAuthenticate(clientID string) error { return client.Login(s.t.getUserAddrs(userID)[0], s.t.getUserBridgePass(userID)) } +func (s *scenario) imapClientCanAuthenticateWithAddress(clientID string, address string) error { + userID, client := s.t.getIMAPClient(clientID) + + return client.Login(address, s.t.getUserBridgePass(userID)) +} + func (s *scenario) imapClientCannotAuthenticate(clientID string) error { userID, client := s.t.getIMAPClient(clientID)