2019-11-24 20:27:59 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
2019-11-24 20:27:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type AvailableMethodsScenario struct {
|
2021-11-05 13:14:42 +00:00
|
|
|
*RodSuite
|
2019-11-24 20:27:59 +00:00
|
|
|
|
|
|
|
methods []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAvailableMethodsScenario(methods []string) *AvailableMethodsScenario {
|
|
|
|
return &AvailableMethodsScenario{
|
2023-01-25 04:11:05 +00:00
|
|
|
RodSuite: NewRodSuite(""),
|
2021-11-05 13:14:42 +00:00
|
|
|
methods: methods,
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AvailableMethodsScenario) 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 *AvailableMethodsScenario) 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 *AvailableMethodsScenario) 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 *AvailableMethodsScenario) TearDownTest() {
|
|
|
|
s.collectCoverage(s.Page)
|
|
|
|
s.MustClose()
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AvailableMethodsScenario) TestShouldCheckAvailableMethods() {
|
|
|
|
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
|
|
|
|
2023-01-12 10:57:44 +00:00
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, BaseDomain, "")
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2022-04-07 05:33:53 +00:00
|
|
|
methodsButton := s.WaitElementLocatedByID(s.T(), s.Context(ctx), "methods-button")
|
2022-09-26 03:10:37 +00:00
|
|
|
err := methodsButton.Click("left", 1)
|
2019-11-24 20:27:59 +00:00
|
|
|
s.Assert().NoError(err)
|
|
|
|
|
2022-04-07 05:33:53 +00:00
|
|
|
methodsDialog := s.WaitElementLocatedByID(s.T(), s.Context(ctx), "methods-dialog")
|
2021-11-05 13:14:42 +00:00
|
|
|
options, err := methodsDialog.Elements(".method-option")
|
2019-11-24 20:27:59 +00:00
|
|
|
s.Assert().NoError(err)
|
|
|
|
s.Assert().Len(options, len(s.methods))
|
|
|
|
|
|
|
|
optionsList := make([]string, 0)
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2019-11-24 20:27:59 +00:00
|
|
|
for _, o := range options {
|
|
|
|
txt, err := o.Text()
|
|
|
|
s.Assert().NoError(err)
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2019-11-24 20:27:59 +00:00
|
|
|
optionsList = append(optionsList, txt)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Assert().Len(optionsList, len(s.methods))
|
|
|
|
|
|
|
|
for _, m := range s.methods {
|
2021-02-12 05:59:42 +00:00
|
|
|
s.Assert().True(utils.IsStringInSlice(m, optionsList))
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
}
|