2019-11-25 03:27:59 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-11-05 20:14:42 +07:00
|
|
|
"time"
|
2020-12-16 08:47:31 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
"github.com/go-rod/rod"
|
2020-12-16 08:47:31 +07:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-11-25 03:27:59 +07:00
|
|
|
)
|
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
func (rs *RodSession) doInitiatePasswordReset(t *testing.T, page *rod.Page, username string) {
|
|
|
|
err := rs.WaitElementLocatedByCSSSelector(t, page, "reset-password-button").Click("left")
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(t, err)
|
2019-11-25 03:27:59 +07:00
|
|
|
// Fill in username
|
2021-11-05 20:14:42 +07:00
|
|
|
err = rs.WaitElementLocatedByCSSSelector(t, page, "username-textfield").Input(username)
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(t, err)
|
2019-11-25 03:27:59 +07:00
|
|
|
// And click on the reset button
|
2021-11-05 20:14:42 +07:00
|
|
|
err = rs.WaitElementLocatedByCSSSelector(t, page, "reset-button").Click("left")
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(t, err)
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
func (rs *RodSession) doCompletePasswordReset(t *testing.T, page *rod.Page, newPassword1, newPassword2 string) {
|
2019-11-25 03:27:59 +07:00
|
|
|
link := doGetLinkFromLastMail(t)
|
2021-11-05 20:14:42 +07:00
|
|
|
rs.doVisit(t, page, link)
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
|
|
|
err := rs.WaitElementLocatedByCSSSelector(t, page, "password1-textfield").Input(newPassword1)
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(t, err)
|
2021-11-05 20:14:42 +07:00
|
|
|
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
|
|
|
err = rs.WaitElementLocatedByCSSSelector(t, page, "password2-textfield").Input(newPassword2)
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(t, err)
|
2021-11-05 20:14:42 +07:00
|
|
|
|
|
|
|
err = rs.WaitElementLocatedByCSSSelector(t, page, "reset-button").Click("left")
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(t, err)
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
func (rs *RodSession) doSuccessfullyCompletePasswordReset(t *testing.T, page *rod.Page, newPassword1, newPassword2 string) {
|
|
|
|
rs.doCompletePasswordReset(t, page, newPassword1, newPassword2)
|
|
|
|
rs.verifyIsFirstFactorPage(t, page)
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
func (rs *RodSession) doUnsuccessfulPasswordReset(t *testing.T, page *rod.Page, newPassword1, newPassword2 string) {
|
|
|
|
rs.doCompletePasswordReset(t, page, newPassword1, newPassword2)
|
|
|
|
rs.verifyNotificationDisplayed(t, page, "Your supplied password does not meet the password policy requirements.")
|
2020-11-27 16:59:22 +07:00
|
|
|
}
|
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
func (rs *RodSession) doResetPassword(t *testing.T, page *rod.Page, username, newPassword1, newPassword2 string, unsuccessful bool) {
|
|
|
|
rs.doInitiatePasswordReset(t, page, username)
|
2019-11-25 03:27:59 +07:00
|
|
|
// then wait for the "email sent notification"
|
2021-11-05 20:14:42 +07:00
|
|
|
rs.verifyMailNotificationDisplayed(t, page)
|
2020-11-27 16:59:22 +07:00
|
|
|
|
|
|
|
if unsuccessful {
|
2021-11-05 20:14:42 +07:00
|
|
|
rs.doUnsuccessfulPasswordReset(t, page, newPassword1, newPassword2)
|
2020-11-27 16:59:22 +07:00
|
|
|
} else {
|
2021-11-05 20:14:42 +07:00
|
|
|
rs.doSuccessfullyCompletePasswordReset(t, page, newPassword1, newPassword2)
|
2020-11-27 16:59:22 +07:00
|
|
|
}
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|