2019-11-24 20:27:59 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ResetPasswordScenario struct {
|
2021-11-05 13:14:42 +00:00
|
|
|
*RodSuite
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewResetPasswordScenario() *ResetPasswordScenario {
|
2021-11-05 13:14:42 +00:00
|
|
|
return &ResetPasswordScenario{RodSuite: new(RodSuite)}
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ResetPasswordScenario) SetupSuite() {
|
2021-11-05 13:14:42 +00:00
|
|
|
browser, err := StartRod()
|
2019-11-24 20:27:59 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.RodSession = browser
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ResetPasswordScenario) TearDownSuite() {
|
2021-11-05 13:14:42 +00:00
|
|
|
err := s.RodSession.Stop()
|
2019-11-24 20:27:59 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ResetPasswordScenario) SetupTest() {
|
2021-11-05 13:14:42 +00:00
|
|
|
s.Page = s.doCreateTab(s.T(), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Page)
|
|
|
|
}
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
func (s *ResetPasswordScenario) TearDownTest() {
|
|
|
|
s.collectCoverage(s.Page)
|
|
|
|
s.MustClose()
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ResetPasswordScenario) TestShouldResetPassword() {
|
2021-11-05 13:14:42 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), GetLoginBaseURL())
|
|
|
|
s.verifyIsFirstFactorPage(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Reset the password to abc.
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doResetPassword(s.T(), s.Context(ctx), "john", "abc", "abc", false)
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Try to login with the old password.
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, "")
|
|
|
|
s.verifyNotificationDisplayed(s.T(), s.Context(ctx), "Incorrect username or password.")
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Try to login with the new password.
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "abc", false, "")
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Logout.
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLogout(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Reset the original password.
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doResetPassword(s.T(), s.Context(ctx), "john", "password", "password", false)
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ResetPasswordScenario) TestShouldMakeAttackerThinkPasswordResetIsInitiated() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
2021-11-05 13:14:42 +00:00
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), GetLoginBaseURL())
|
|
|
|
s.verifyIsFirstFactorPage(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2020-01-21 00:10:00 +00:00
|
|
|
// Try to initiate a password reset of an nonexistent user.
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doInitiatePasswordReset(s.T(), s.Context(ctx), "i_dont_exist")
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Check that the notification make the attacker thinks the process is initiated.
|
2021-11-05 13:14:42 +00:00
|
|
|
s.verifyMailNotificationDisplayed(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ResetPasswordScenario) TestShouldLetUserNoticeThereIsAPasswordMismatch() {
|
2021-11-05 13:14:42 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), GetLoginBaseURL())
|
|
|
|
s.verifyIsFirstFactorPage(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doInitiatePasswordReset(s.T(), s.Context(ctx), "john")
|
|
|
|
s.verifyMailNotificationDisplayed(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doCompletePasswordReset(s.T(), s.Context(ctx), "password", "another_password")
|
|
|
|
s.verifyNotificationDisplayed(s.T(), s.Context(ctx), "Passwords do not match.")
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunResetPasswordScenario(t *testing.T) {
|
2021-03-14 07:08:26 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping suite test in short mode")
|
|
|
|
}
|
|
|
|
|
2019-11-24 20:27:59 +00:00
|
|
|
suite.Run(t, NewResetPasswordScenario())
|
|
|
|
}
|