2019-11-02 21:32:58 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
2019-11-25 03:27:59 +07:00
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2019-11-02 21:32:58 +07:00
|
|
|
"testing"
|
2019-11-25 03:27:59 +07:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
2019-11-02 21:32:58 +07:00
|
|
|
)
|
|
|
|
|
2019-12-06 04:35:03 +07:00
|
|
|
type BypassAllWebDriverSuite struct {
|
2021-11-05 20:14:42 +07:00
|
|
|
*RodSuite
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|
|
|
|
|
2019-12-06 04:35:03 +07:00
|
|
|
func NewBypassAllWebDriverSuite() *BypassAllWebDriverSuite {
|
2021-11-05 20:14:42 +07:00
|
|
|
return &BypassAllWebDriverSuite{RodSuite: new(RodSuite)}
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|
|
|
|
|
2019-12-06 04:35:03 +07:00
|
|
|
func (s *BypassAllWebDriverSuite) 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
|
|
|
}
|
|
|
|
|
2019-12-06 04:35:03 +07:00
|
|
|
func (s *BypassAllWebDriverSuite) 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
func (s *BypassAllWebDriverSuite) SetupTest() {
|
|
|
|
s.Page = s.doCreateTab(s.T(), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Page)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BypassAllWebDriverSuite) TearDownTest() {
|
|
|
|
s.collectCoverage(s.Page)
|
|
|
|
s.MustClose()
|
|
|
|
}
|
|
|
|
|
2019-12-06 04:35:03 +07:00
|
|
|
func (s *BypassAllWebDriverSuite) TestShouldAccessPublicResource() {
|
2019-11-25 03:27:59 +07:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*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.doVisit(s.T(), s.Context(ctx), fmt.Sprintf("%s/secret.html", AdminBaseURL))
|
|
|
|
s.verifySecretAuthorized(s.T(), s.Context(ctx))
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), fmt.Sprintf("%s/secret.html", PublicBaseURL))
|
|
|
|
s.verifySecretAuthorized(s.T(), s.Context(ctx))
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
2019-12-06 04:35:03 +07:00
|
|
|
type BypassAllSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewBypassAllSuite() *BypassAllSuite {
|
|
|
|
return &BypassAllSuite{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BypassAllSuite) TestBypassAllWebDriverSuite() {
|
|
|
|
suite.Run(s.T(), NewBypassAllWebDriverSuite())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BypassAllSuite) TestCustomHeadersScenario() {
|
|
|
|
suite.Run(s.T(), NewCustomHeadersScenario())
|
|
|
|
}
|
|
|
|
|
2019-11-02 21:32:58 +07:00
|
|
|
func TestBypassAllSuite(t *testing.T) {
|
2021-03-14 14:08:26 +07:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping suite test in short mode")
|
|
|
|
}
|
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
suite.Run(t, NewBypassAllSuite())
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|