From d919c0accf7d223dc64ad0b149d292ae40b2266b Mon Sep 17 00:00:00 2001 From: Gjorgji Slamkov Date: Thu, 18 Jan 2024 08:36:16 +0100 Subject: [PATCH] test(GODT-3220): Add step definition for logging in with alias address GODT-3220 --- tests/steps_test.go | 1 + tests/user_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tests/steps_test.go b/tests/steps_test.go index e066aaee..1dd39ea6 100644 --- a/tests/steps_test.go +++ b/tests/steps_test.go @@ -101,6 +101,7 @@ func (s *scenario) steps(ctx *godog.ScenarioContext) { // ==== USER ==== ctx.Step(`^the user logs in with username "([^"]*)" and password "([^"]*)"$`, s.userLogsInWithUsernameAndPassword) + ctx.Step(`^the user logs in with alias address "([^"]*)" and password "([^"]*)"$`, s.userLogsInWithAliasAddressAndPassword) ctx.Step(`^user "([^"]*)" logs out$`, s.userLogsOut) ctx.Step(`^user "([^"]*)" is deleted$`, s.userIsDeleted) ctx.Step(`^the auth of user "([^"]*)" is revoked$`, s.theAuthOfUserIsRevoked) diff --git a/tests/user_test.go b/tests/user_test.go index ffbcd2e3..787886cf 100644 --- a/tests/user_test.go +++ b/tests/user_test.go @@ -367,6 +367,42 @@ func (s *scenario) userLogsInWithUsernameAndPassword(username, password string) return nil } +func (s *scenario) userLogsInWithAliasAddressAndPassword(alias, password string) error { + smtpEvtCh, cancelSMTP := s.t.bridge.GetEvents(events.SMTPServerReady{}) + defer cancelSMTP() + imapEvtCh, cancelIMAP := s.t.bridge.GetEvents(events.IMAPServerReady{}) + defer cancelIMAP() + + userID, err := s.t.bridge.LoginFull(context.Background(), s.t.getUserByAddress(alias).getName(), []byte(password), nil, nil) + if err != nil { + s.t.pushError(err) + } else { + // We need to wait for server to be up or we won't be able to connect. It should only happen once to avoid + // blocking on multiple Logins. + if !s.t.imapServerStarted { + <-imapEvtCh + s.t.imapServerStarted = true + } + if !s.t.smtpServerStarted { + <-smtpEvtCh + s.t.smtpServerStarted = true + } + + if userID != s.t.getUserByAddress(alias).getUserID() { + return errors.New("user ID mismatch") + } + + info, err := s.t.bridge.GetUserInfo(userID) + if err != nil { + return err + } + + s.t.getUserByID(userID).setBridgePass(string(info.BridgePass)) + } + + return nil +} + func (s *scenario) userLogsOut(username string) error { return s.t.bridge.LogoutUser(context.Background(), s.t.getUserByName(username).getUserID()) }