2019-11-25 03:27:59 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2021-08-11 08:04:35 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
2019-11-25 03:27:59 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
type AvailableMethodsScenario struct {
|
2021-11-05 20:14:42 +07:00
|
|
|
*RodSuite
|
2019-11-25 03:27:59 +07:00
|
|
|
|
|
|
|
methods []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAvailableMethodsScenario(methods []string) *AvailableMethodsScenario {
|
|
|
|
return &AvailableMethodsScenario{
|
2021-11-05 20:14:42 +07:00
|
|
|
RodSuite: new(RodSuite),
|
|
|
|
methods: methods,
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AvailableMethodsScenario) SetupSuite() {
|
2021-11-05 20:14:42 +07:00
|
|
|
browser, err := StartRod()
|
2019-11-25 03:27:59 +07:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
s.RodSession = browser
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AvailableMethodsScenario) TearDownSuite() {
|
2021-11-05 20:14:42 +07:00
|
|
|
err := s.RodSession.Stop()
|
2019-11-25 03:27:59 +07:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AvailableMethodsScenario) SetupTest() {
|
2021-11-05 20:14:42 +07:00
|
|
|
s.Page = s.doCreateTab(s.T(), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Page)
|
|
|
|
}
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
func (s *AvailableMethodsScenario) TearDownTest() {
|
|
|
|
s.collectCoverage(s.Page)
|
|
|
|
s.MustClose()
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AvailableMethodsScenario) TestShouldCheckAvailableMethods() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
2021-11-05 20:14:42 +07:00
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, "")
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
methodsButton := s.WaitElementLocatedByCSSSelector(s.T(), s.Context(ctx), "methods-button")
|
|
|
|
err := methodsButton.Click("left")
|
2019-11-25 03:27:59 +07:00
|
|
|
s.Assert().NoError(err)
|
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
methodsDialog := s.WaitElementLocatedByCSSSelector(s.T(), s.Context(ctx), "methods-dialog")
|
|
|
|
options, err := methodsDialog.Elements(".method-option")
|
2019-11-25 03:27:59 +07:00
|
|
|
s.Assert().NoError(err)
|
|
|
|
s.Assert().Len(options, len(s.methods))
|
|
|
|
|
|
|
|
optionsList := make([]string, 0)
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
for _, o := range options {
|
|
|
|
txt, err := o.Text()
|
|
|
|
s.Assert().NoError(err)
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
optionsList = append(optionsList, txt)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Assert().Len(optionsList, len(s.methods))
|
|
|
|
|
|
|
|
for _, m := range s.methods {
|
2021-02-12 12:59:42 +07:00
|
|
|
s.Assert().True(utils.IsStringInSlice(m, optionsList))
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
}
|