2019-11-24 20:27:59 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-12-16 01:47:31 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
"github.com/go-rod/rod"
|
2020-12-16 01:47:31 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-11-24 20:27:59 +00:00
|
|
|
)
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
func (rs *RodSession) doInitiatePasswordReset(t *testing.T, page *rod.Page, username string) {
|
2022-09-26 03:10:37 +00:00
|
|
|
err := rs.WaitElementLocatedByID(t, page, "reset-password-button").Click("left", 1)
|
2020-12-16 01:47:31 +00:00
|
|
|
require.NoError(t, err)
|
2022-01-31 05:25:15 +00:00
|
|
|
// Fill in username.
|
2022-04-07 05:33:53 +00:00
|
|
|
err = rs.WaitElementLocatedByID(t, page, "username-textfield").Input(username)
|
2020-12-16 01:47:31 +00:00
|
|
|
require.NoError(t, err)
|
2022-01-31 05:25:15 +00:00
|
|
|
// And click on the reset button.
|
2022-09-26 03:10:37 +00:00
|
|
|
err = rs.WaitElementLocatedByID(t, page, "reset-button").Click("left", 1)
|
2020-12-16 01:47:31 +00:00
|
|
|
require.NoError(t, err)
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
func (rs *RodSession) doCompletePasswordReset(t *testing.T, page *rod.Page, newPassword1, newPassword2 string) {
|
2019-11-24 20:27:59 +00:00
|
|
|
link := doGetLinkFromLastMail(t)
|
2021-11-05 13:14:42 +00:00
|
|
|
rs.doVisit(t, page, link)
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2022-12-07 09:22:03 +00:00
|
|
|
password1 := rs.WaitElementLocatedByID(t, page, "password1-textfield")
|
|
|
|
password2 := rs.WaitElementLocatedByID(t, page, "password2-textfield")
|
2021-11-05 13:14:42 +00:00
|
|
|
|
2022-12-07 09:22:03 +00:00
|
|
|
password1:
|
|
|
|
err := password1.MustSelectAllText().Input(newPassword1)
|
2020-12-16 01:47:31 +00:00
|
|
|
require.NoError(t, err)
|
2021-11-05 13:14:42 +00:00
|
|
|
|
2022-12-07 09:22:03 +00:00
|
|
|
if password1.MustText() != newPassword1 {
|
|
|
|
goto password1
|
|
|
|
}
|
2021-11-05 13:14:42 +00:00
|
|
|
|
2022-12-07 09:22:03 +00:00
|
|
|
password2:
|
|
|
|
err = password2.MustSelectAllText().Input(newPassword2)
|
2020-12-16 01:47:31 +00:00
|
|
|
require.NoError(t, err)
|
2021-11-05 13:14:42 +00:00
|
|
|
|
2022-12-07 09:22:03 +00:00
|
|
|
if password2.MustText() != newPassword2 {
|
|
|
|
goto password2
|
|
|
|
}
|
|
|
|
|
2022-09-26 03:10:37 +00:00
|
|
|
err = rs.WaitElementLocatedByID(t, page, "reset-button").Click("left", 1)
|
2020-12-16 01:47:31 +00:00
|
|
|
require.NoError(t, err)
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 13:14:42 +00: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-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 13:14:42 +00: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 09:59:22 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
func (rs *RodSession) doResetPassword(t *testing.T, page *rod.Page, username, newPassword1, newPassword2 string, unsuccessful bool) {
|
|
|
|
rs.doInitiatePasswordReset(t, page, username)
|
2022-01-31 05:25:15 +00:00
|
|
|
// then wait for the "email sent notification".
|
2021-11-05 13:14:42 +00:00
|
|
|
rs.verifyMailNotificationDisplayed(t, page)
|
2020-11-27 09:59:22 +00:00
|
|
|
|
|
|
|
if unsuccessful {
|
2021-11-05 13:14:42 +00:00
|
|
|
rs.doUnsuccessfulPasswordReset(t, page, newPassword1, newPassword2)
|
2020-11-27 09:59:22 +00:00
|
|
|
} else {
|
2021-11-05 13:14:42 +00:00
|
|
|
rs.doSuccessfullyCompletePasswordReset(t, page, newPassword1, newPassword2)
|
2020-11-27 09:59:22 +00:00
|
|
|
}
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|