You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
4.3 KiB
114 lines
4.3 KiB
// Copyright (c) 2020 Proton Technologies AG |
|
// |
|
// This file is part of ProtonMail Bridge.Bridge. |
|
// |
|
// ProtonMail Bridge is free software: you can redistribute it and/or modify |
|
// it under the terms of the GNU General Public License as published by |
|
// the Free Software Foundation, either version 3 of the License, or |
|
// (at your option) any later version. |
|
// |
|
// ProtonMail Bridge is distributed in the hope that it will be useful, |
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
// GNU General Public License for more details. |
|
// |
|
// You should have received a copy of the GNU General Public License |
|
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>. |
|
|
|
package tests |
|
|
|
import ( |
|
"strings" |
|
|
|
"github.com/cucumber/godog" |
|
"github.com/cucumber/godog/gherkin" |
|
) |
|
|
|
func SMTPActionsAuthFeatureContext(s *godog.Suite) { |
|
s.Step(`^SMTP client authenticates "([^"]*)"$`, smtpClientAuthenticates) |
|
s.Step(`^SMTP client "([^"]*)" authenticates "([^"]*)"$`, smtpClientNamedAuthenticates) |
|
s.Step(`^SMTP client authenticates "([^"]*)" with address "([^"]*)"$`, smtpClientAuthenticatesWithAddress) |
|
s.Step(`^SMTP client "([^"]*)" authenticates "([^"]*)" with address "([^"]*)"$`, smtpClientNamedAuthenticatesWithAddress) |
|
s.Step(`^SMTP client authenticates "([^"]*)" with bad password$`, smtpClientAuthenticatesWithBadPassword) |
|
s.Step(`^SMTP client authenticates with username "([^"]*)" and password "([^"]*)"$`, smtpClientAuthenticatesWithUsernameAndPassword) |
|
s.Step(`^SMTP client logs out$`, smtpClientLogsOut) |
|
s.Step(`^SMTP client sends message$`, smtpClientSendsMessage) |
|
s.Step(`^SMTP client sends EHLO$`, smtpClientSendsEHLO) |
|
s.Step(`^SMTP client "([^"]*)" sends message$`, smtpClientNamedSendsMessage) |
|
s.Step(`^SMTP client sends message with bcc "([^"]*)"$`, smtpClientSendsMessageWithBCC) |
|
s.Step(`^SMTP client "([^"]*)" sends message with bcc "([^"]*)"$`, smtpClientNamedSendsMessageWithBCC) |
|
} |
|
|
|
func smtpClientAuthenticates(bddUserID string) error { |
|
return smtpClientNamedAuthenticates("smtp", bddUserID) |
|
} |
|
|
|
func smtpClientNamedAuthenticates(clientID, bddUserID string) error { |
|
account := ctx.GetTestAccount(bddUserID) |
|
if account == nil { |
|
return godog.ErrPending |
|
} |
|
res := ctx.GetSMTPClient(clientID).Login(account.Address(), account.BridgePassword()) |
|
ctx.SetSMTPLastResponse(clientID, res) |
|
return nil |
|
} |
|
|
|
func smtpClientAuthenticatesWithAddress(bddUserID, bddAddressID string) error { |
|
return smtpClientNamedAuthenticatesWithAddress("smtp", bddUserID, bddAddressID) |
|
} |
|
|
|
func smtpClientNamedAuthenticatesWithAddress(clientID, bddUserID, bddAddressID string) error { |
|
account := ctx.GetTestAccountWithAddress(bddUserID, bddAddressID) |
|
if account == nil { |
|
return godog.ErrPending |
|
} |
|
res := ctx.GetSMTPClient(clientID).Login(account.Address(), account.BridgePassword()) |
|
ctx.SetSMTPLastResponse(clientID, res) |
|
return nil |
|
} |
|
|
|
func smtpClientAuthenticatesWithBadPassword(bddUserID string) error { |
|
account := ctx.GetTestAccount(bddUserID) |
|
if account == nil { |
|
return godog.ErrPending |
|
} |
|
res := ctx.GetSMTPClient("smtp").Login(account.Address(), "you shall not pass!") |
|
ctx.SetSMTPLastResponse("smtp", res) |
|
return nil |
|
} |
|
|
|
func smtpClientAuthenticatesWithUsernameAndPassword(bddUserID, password string) error { |
|
res := ctx.GetSMTPClient("smtp").Login(bddUserID, password) |
|
ctx.SetSMTPLastResponse("smtp", res) |
|
return nil |
|
} |
|
|
|
func smtpClientLogsOut() error { |
|
res := ctx.GetSMTPClient("smtp").Logout() |
|
ctx.SetSMTPLastResponse("smtp", res) |
|
return nil |
|
} |
|
|
|
func smtpClientSendsMessage(message *gherkin.DocString) error { |
|
return smtpClientNamedSendsMessage("smtp", message) |
|
} |
|
|
|
func smtpClientSendsEHLO() error { |
|
res := ctx.GetSMTPClient("smtp").SendCommands("EHLO ateist.test") |
|
ctx.SetSMTPLastResponse("smtp", res) |
|
return nil |
|
} |
|
|
|
func smtpClientNamedSendsMessage(clientID string, message *gherkin.DocString) error { |
|
return smtpClientNamedSendsMessageWithBCC(clientID, "", message) |
|
} |
|
|
|
func smtpClientSendsMessageWithBCC(bcc string, message *gherkin.DocString) error { |
|
return smtpClientNamedSendsMessageWithBCC("smtp", bcc, message) |
|
} |
|
|
|
func smtpClientNamedSendsMessageWithBCC(clientID, bcc string, message *gherkin.DocString) error { |
|
res := ctx.GetSMTPClient(clientID).SendMail(strings.NewReader(message.Content), bcc) |
|
ctx.SetSMTPLastResponse(clientID, res) |
|
return nil |
|
}
|
|
|