improvements for inbucket email test and re-enable Email mention test (#5647)
Now if we dont get the mailbox to check the email we try 5 times, if still no message we disable the email verification.
Этот коммит содержится в:
коммит произвёл
enahum
родитель
b756ae17c0
Коммит
11f1859de1
@@ -997,51 +997,62 @@ func TestDeletePosts(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
// func TestEmailMention(t *testing.T) {
|
||||
// th := Setup().InitBasic()
|
||||
// Client := th.BasicClient
|
||||
// channel1 := th.BasicChannel
|
||||
// Client.Must(Client.AddChannelMember(channel1.Id, th.BasicUser2.Id))
|
||||
func TestEmailMention(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
Client := th.BasicClient
|
||||
channel1 := th.BasicChannel
|
||||
Client.Must(Client.AddChannelMember(channel1.Id, th.BasicUser2.Id))
|
||||
|
||||
// th.LoginBasic2()
|
||||
// //Set the notification properties
|
||||
// data := make(map[string]string)
|
||||
// data["user_id"] = th.BasicUser2.Id
|
||||
// data["email"] = "true"
|
||||
// data["desktop"] = "all"
|
||||
// data["desktop_sound"] = "false"
|
||||
// data["comments"] = "any"
|
||||
// Client.Must(Client.UpdateUserNotify(data))
|
||||
th.LoginBasic2()
|
||||
//Set the notification properties
|
||||
data := make(map[string]string)
|
||||
data["user_id"] = th.BasicUser2.Id
|
||||
data["email"] = "true"
|
||||
data["desktop"] = "all"
|
||||
data["desktop_sound"] = "false"
|
||||
data["comments"] = "any"
|
||||
Client.Must(Client.UpdateUserNotify(data))
|
||||
|
||||
// store.Must(app.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
// UserId: th.BasicUser2.Id,
|
||||
// Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
// Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
// Value: "0",
|
||||
// }}))
|
||||
store.Must(app.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
UserId: th.BasicUser2.Id,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
Value: "0",
|
||||
}}))
|
||||
|
||||
// //Delete all the messages before create a mention post
|
||||
// utils.DeleteMailBox(th.BasicUser2.Email)
|
||||
//Delete all the messages before create a mention post
|
||||
utils.DeleteMailBox(th.BasicUser2.Email)
|
||||
|
||||
// //Send a mention message from user1 to user2
|
||||
// th.LoginBasic()
|
||||
// time.Sleep(10 * time.Millisecond)
|
||||
// post1 := &model.Post{ChannelId: channel1.Id, Message: "@" + th.BasicUser2.Username + " this is a test"}
|
||||
// post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post)
|
||||
//Send a mention message from user1 to user2
|
||||
th.LoginBasic()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
post1 := &model.Post{ChannelId: channel1.Id, Message: "@" + th.BasicUser2.Username + " this is a test"}
|
||||
post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post)
|
||||
|
||||
// //Check if the email was send to the rigth email address and the mention
|
||||
// if resultsMailbox, err := utils.GetMailBox(th.BasicUser2.Email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], th.BasicUser2.Email) {
|
||||
// t.Fatal("Wrong To recipient")
|
||||
// } else {
|
||||
// if resultsEmail, err := utils.GetMessageFromMailbox(th.BasicUser2.Email, resultsMailbox[0].ID); err == nil {
|
||||
// if !strings.Contains(resultsEmail.Body.Text, post1.Message) {
|
||||
// t.Log(resultsEmail.Body.Text)
|
||||
// t.Fatal("Received wrong Message")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(th.BasicUser2.Email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], th.BasicUser2.Email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(th.BasicUser2.Email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Body.Text, post1.Message) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Received wrong Message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
func TestFuzzyPosts(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
|
||||
@@ -1330,14 +1330,27 @@ func TestResetPassword(t *testing.T) {
|
||||
}
|
||||
|
||||
//Check if the email was send to the rigth email address and the recovery key match
|
||||
if resultsMailbox, err := utils.GetMailBox(user.Email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], user.Email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(user.Email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Body.Text, recovery.Code) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Log(recovery.Code)
|
||||
t.Fatal("Received wrong recovery code")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(user.Email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], user.Email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(user.Email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Body.Text, recovery.Code) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Log(recovery.Code)
|
||||
t.Fatal("Received wrong recovery code")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -789,14 +789,26 @@ func TestResetPassword(t *testing.T) {
|
||||
}
|
||||
|
||||
// Check if the email was send to the right email address and the recovery key match
|
||||
if resultsMailbox, err := utils.GetMailBox(user.Email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], user.Email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(user.Email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Body.Text, recovery.Code) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Log(recovery.Code)
|
||||
t.Fatal("Received wrong recovery code")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(user.Email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], user.Email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(user.Email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Body.Text, recovery.Code) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Log(recovery.Code)
|
||||
t.Fatal("Received wrong recovery code")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,17 +30,29 @@ func TestSendChangeUsernameEmail(t *testing.T) {
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(emailTo); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], emailTo) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(emailTo, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(emailTo)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], emailTo) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(emailTo, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,21 +78,33 @@ func TestSendEmailChangeVerifyEmail(t *testing.T) {
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(newUserEmail); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], newUserEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(newUserEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(newUserEmail)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong new email in the message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(newUserEmail)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], newUserEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(newUserEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(newUserEmail)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong new email in the message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,17 +130,29 @@ func TestSendEmailChangeEmail(t *testing.T) {
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(oldEmail); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], oldEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(oldEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(oldEmail)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], oldEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(oldEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,21 +178,33 @@ func TestSendVerifyEmail(t *testing.T) {
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(userEmail); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], userEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(userEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(userEmail)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong new email in the message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(userEmail)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], userEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(userEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(userEmail)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong new email in the message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,17 +230,29 @@ func TestSendSignInChangeEmail(t *testing.T) {
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,17 +279,29 @@ func TestSendWelcomeEmail(t *testing.T) {
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,25 +316,37 @@ func TestSendWelcomeEmail(t *testing.T) {
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedVerifyEmail) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(email)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong email in the message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedVerifyEmail) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(email)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong email in the message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,17 +372,29 @@ func TestSendPasswordChangeEmail(t *testing.T) {
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -324,17 +420,29 @@ func TestSendMfaChangeEmail(t *testing.T) {
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -349,17 +457,29 @@ func TestSendMfaChangeEmail(t *testing.T) {
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -385,35 +505,58 @@ func TestSendInviteEmails(t *testing.T) {
|
||||
SendInviteEmails(th.BasicTeam, senderName, invites, siteURL)
|
||||
|
||||
//Check if the email was send to the rigth email address to email1
|
||||
if resultsMailbox, err := utils.GetMailBox(email1); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], email1) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email1, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Log(expectedSubject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email1)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email1) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email1, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Log(expectedSubject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Check if the email was send to the rigth email address to email2
|
||||
if resultsMailbox, err := utils.GetMailBox(email2); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], email2) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email2, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Log(expectedSubject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
err = utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email2)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email2) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email2, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Log(expectedSubject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package utils
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -58,11 +60,22 @@ func GetMailBox(email string) (results JSONMessageHeaderInbucket, err error) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var record JSONMessageHeaderInbucket
|
||||
if err := json.NewDecoder(resp.Body).Decode(&record); err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
if resp.Body == nil {
|
||||
return nil, fmt.Errorf("No Mailbox")
|
||||
}
|
||||
|
||||
var record JSONMessageHeaderInbucket
|
||||
err = json.NewDecoder(resp.Body).Decode(&record)
|
||||
switch {
|
||||
case err == io.EOF:
|
||||
return nil, fmt.Errorf("Error: %s", err)
|
||||
case err != nil:
|
||||
return nil, fmt.Errorf("Error: %s", err)
|
||||
}
|
||||
if len(record) == 0 {
|
||||
return nil, fmt.Errorf("No mailbox")
|
||||
}
|
||||
|
||||
return record, nil
|
||||
}
|
||||
|
||||
@@ -87,7 +100,6 @@ func GetMessageFromMailbox(email, id string) (results JSONMessageInbucket, err e
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := json.NewDecoder(resp.Body).Decode(&record); err != nil {
|
||||
fmt.Println(err)
|
||||
return record, err
|
||||
}
|
||||
return record, nil
|
||||
@@ -113,3 +125,21 @@ func DeleteMailBox(email string) (err error) {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RetryInbucket(attempts int, callback func() error) (err error) {
|
||||
for i := 0; ; i++ {
|
||||
err = callback()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if i >= (attempts - 1) {
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
fmt.Println("retrying...")
|
||||
}
|
||||
return fmt.Errorf("After %d attempts, last error: %s", attempts, err)
|
||||
}
|
||||
|
||||
@@ -47,13 +47,25 @@ func TestSendMail(t *testing.T) {
|
||||
t.Fatal("Should connect to the STMP Server")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := GetMailBox(emailTo); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], emailTo) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := GetMessageFromMailbox(emailTo, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Body.Text, emailBody) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Received message")
|
||||
var resultsMailbox JSONMessageHeaderInbucket
|
||||
err := RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = GetMailBox(emailTo)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], emailTo) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := GetMessageFromMailbox(emailTo, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Body.Text, emailBody) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Received message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user