2019-11-24 20:27:59 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/tebeka/selenium"
|
2021-02-12 05:59:42 +00:00
|
|
|
|
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 {
|
|
|
|
*SeleniumSuite
|
|
|
|
|
|
|
|
methods []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAvailableMethodsScenario(methods []string) *AvailableMethodsScenario {
|
|
|
|
return &AvailableMethodsScenario{
|
|
|
|
SeleniumSuite: new(SeleniumSuite),
|
|
|
|
methods: methods,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AvailableMethodsScenario) SetupSuite() {
|
|
|
|
wds, err := StartWebDriver()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.SeleniumSuite.WebDriverSession = wds
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AvailableMethodsScenario) TearDownSuite() {
|
|
|
|
err := s.WebDriverSession.Stop()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AvailableMethodsScenario) SetupTest() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
s.doLogout(ctx, s.T())
|
|
|
|
s.doVisit(s.T(), HomeBaseURL)
|
|
|
|
s.verifyIsHome(ctx, s.T())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AvailableMethodsScenario) TestShouldCheckAvailableMethods() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, "")
|
|
|
|
|
|
|
|
methodsButton := s.WaitElementLocatedByID(ctx, s.T(), "methods-button")
|
|
|
|
err := methodsButton.Click()
|
|
|
|
s.Assert().NoError(err)
|
|
|
|
|
|
|
|
methodsDialog := s.WaitElementLocatedByID(ctx, s.T(), "methods-dialog")
|
|
|
|
options, err := methodsDialog.FindElements(selenium.ByClassName, "method-option")
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|