mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
83488d52a6
* refactor(suites): replace selenium with go-rod This change replaces [tebeka/selenium](https://github.com/tebeka/selenium) with [go-rod](https://github.com/go-rod/rod). We no longer have a chromedriver/external driver dependency to utilise Selenium as we instead utilise the Chrome Dev Protocol to communicate with the browser. Rod [documents](https://go-rod.github.io/#/why-rod) benefits of choosing the library as opposed to the available alternatives.
61 lines
2.1 KiB
Go
61 lines
2.1 KiB
Go
package suites
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/go-rod/rod"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func (rs *RodSession) doInitiatePasswordReset(t *testing.T, page *rod.Page, username string) {
|
|
err := rs.WaitElementLocatedByCSSSelector(t, page, "reset-password-button").Click("left")
|
|
require.NoError(t, err)
|
|
// Fill in username
|
|
err = rs.WaitElementLocatedByCSSSelector(t, page, "username-textfield").Input(username)
|
|
require.NoError(t, err)
|
|
// And click on the reset button
|
|
err = rs.WaitElementLocatedByCSSSelector(t, page, "reset-button").Click("left")
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func (rs *RodSession) doCompletePasswordReset(t *testing.T, page *rod.Page, newPassword1, newPassword2 string) {
|
|
link := doGetLinkFromLastMail(t)
|
|
rs.doVisit(t, page, link)
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
err := rs.WaitElementLocatedByCSSSelector(t, page, "password1-textfield").Input(newPassword1)
|
|
require.NoError(t, err)
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
err = rs.WaitElementLocatedByCSSSelector(t, page, "password2-textfield").Input(newPassword2)
|
|
require.NoError(t, err)
|
|
|
|
err = rs.WaitElementLocatedByCSSSelector(t, page, "reset-button").Click("left")
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func (rs *RodSession) doSuccessfullyCompletePasswordReset(t *testing.T, page *rod.Page, newPassword1, newPassword2 string) {
|
|
rs.doCompletePasswordReset(t, page, newPassword1, newPassword2)
|
|
rs.verifyIsFirstFactorPage(t, page)
|
|
}
|
|
|
|
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.")
|
|
}
|
|
|
|
func (rs *RodSession) doResetPassword(t *testing.T, page *rod.Page, username, newPassword1, newPassword2 string, unsuccessful bool) {
|
|
rs.doInitiatePasswordReset(t, page, username)
|
|
// then wait for the "email sent notification"
|
|
rs.verifyMailNotificationDisplayed(t, page)
|
|
|
|
if unsuccessful {
|
|
rs.doUnsuccessfulPasswordReset(t, page, newPassword1, newPassword2)
|
|
} else {
|
|
rs.doSuccessfullyCompletePasswordReset(t, page, newPassword1, newPassword2)
|
|
}
|
|
}
|