2019-11-02 14:32:58 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
2019-11-24 20:27:59 +00:00
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2019-11-02 14:32:58 +00:00
|
|
|
"testing"
|
2019-11-24 20:27:59 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
2019-11-02 14:32:58 +00:00
|
|
|
)
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
type BypassAllWebDriverSuite struct {
|
2021-11-05 13:14:42 +00:00
|
|
|
*RodSuite
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func NewBypassAllWebDriverSuite() *BypassAllWebDriverSuite {
|
2021-11-05 13:14:42 +00:00
|
|
|
return &BypassAllWebDriverSuite{RodSuite: new(RodSuite)}
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *BypassAllWebDriverSuite) 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
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *BypassAllWebDriverSuite) 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 13:14:42 +00: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-05 21:35:03 +00:00
|
|
|
func (s *BypassAllWebDriverSuite) TestShouldAccessPublicResource() {
|
2019-11-24 20:27:59 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*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), fmt.Sprintf("%s/secret.html", AdminBaseURL))
|
|
|
|
s.verifySecretAuthorized(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), fmt.Sprintf("%s/secret.html", PublicBaseURL))
|
|
|
|
s.verifySecretAuthorized(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00: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 14:32:58 +00:00
|
|
|
func TestBypassAllSuite(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, NewBypassAllSuite())
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|