From 336276be9876eb030b8ade92c0e8fb97af05a776 Mon Sep 17 00:00:00 2001 From: Clement Michaud Date: Thu, 5 Dec 2019 22:35:03 +0100 Subject: [PATCH] Be able to run scenarii in isolation for each suite. --- internal/suites/suite_bypass_all_test.go | 29 +++++++++--- internal/suites/suite_docker_test.go | 13 ++++-- internal/suites/suite_duo_push_test.go | 44 +++++++++++++------ .../suites/suite_high_availability_test.go | 29 +++++++++--- internal/suites/suite_kubernetes_test.go | 13 ++++-- internal/suites/suite_ldap_test.go | 13 ++++-- internal/suites/suite_mariadb_test.go | 13 ++++-- internal/suites/suite_postgres_test.go | 13 ++++-- internal/suites/suite_short_timeouts_test.go | 13 ++++-- internal/suites/suite_standalone_test.go | 36 ++++++++++----- internal/suites/suite_traefik_test.go | 13 ++++-- 11 files changed, 172 insertions(+), 57 deletions(-) diff --git a/internal/suites/suite_bypass_all_test.go b/internal/suites/suite_bypass_all_test.go index 3e21c719c..f47d46734 100644 --- a/internal/suites/suite_bypass_all_test.go +++ b/internal/suites/suite_bypass_all_test.go @@ -10,15 +10,15 @@ import ( "github.com/stretchr/testify/suite" ) -type BypassAllSuite struct { +type BypassAllWebDriverSuite struct { *SeleniumSuite } -func NewBypassAllSuite() *BypassAllSuite { - return &BypassAllSuite{SeleniumSuite: new(SeleniumSuite)} +func NewBypassAllWebDriverSuite() *BypassAllWebDriverSuite { + return &BypassAllWebDriverSuite{SeleniumSuite: new(SeleniumSuite)} } -func (s *BypassAllSuite) SetupSuite() { +func (s *BypassAllWebDriverSuite) SetupSuite() { wds, err := StartWebDriver() if err != nil { @@ -28,7 +28,7 @@ func (s *BypassAllSuite) SetupSuite() { s.WebDriverSession = wds } -func (s *BypassAllSuite) TearDownSuite() { +func (s *BypassAllWebDriverSuite) TearDownSuite() { err := s.WebDriverSession.Stop() if err != nil { @@ -36,7 +36,7 @@ func (s *BypassAllSuite) TearDownSuite() { } } -func (s *BypassAllSuite) TestShouldAccessPublicResource() { +func (s *BypassAllWebDriverSuite) TestShouldAccessPublicResource() { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -47,7 +47,22 @@ func (s *BypassAllSuite) TestShouldAccessPublicResource() { s.verifySecretAuthorized(ctx, s.T()) } +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()) +} + func TestBypassAllSuite(t *testing.T) { suite.Run(t, NewBypassAllSuite()) - suite.Run(t, NewCustomHeadersScenario()) } diff --git a/internal/suites/suite_docker_test.go b/internal/suites/suite_docker_test.go index 67d5e7ea0..95462645e 100644 --- a/internal/suites/suite_docker_test.go +++ b/internal/suites/suite_docker_test.go @@ -14,7 +14,14 @@ func NewDockerSuite() *DockerSuite { return &DockerSuite{SeleniumSuite: new(SeleniumSuite)} } -func TestDockerSuite(t *testing.T) { - suite.Run(t, NewOneFactorScenario()) - suite.Run(t, NewTwoFactorScenario()) +func (s *DockerSuite) TestOneFactorScenario() { + suite.Run(s.T(), NewOneFactorScenario()) +} + +func (s *DockerSuite) TestTwoFactorScenario() { + suite.Run(s.T(), NewTwoFactorScenario()) +} + +func TestDockerSuite(t *testing.T) { + suite.Run(t, NewDockerSuite()) } diff --git a/internal/suites/suite_duo_push_test.go b/internal/suites/suite_duo_push_test.go index 405f8ce7c..ff61079b7 100644 --- a/internal/suites/suite_duo_push_test.go +++ b/internal/suites/suite_duo_push_test.go @@ -9,15 +9,15 @@ import ( "github.com/stretchr/testify/suite" ) -type DuoPushSuite struct { +type DuoPushWebDriverSuite struct { *SeleniumSuite } -func NewDuoPushSuite() *DuoPushSuite { - return &DuoPushSuite{SeleniumSuite: new(SeleniumSuite)} +func NewDuoPushWebDriverSuite() *DuoPushWebDriverSuite { + return &DuoPushWebDriverSuite{SeleniumSuite: new(SeleniumSuite)} } -func (s *DuoPushSuite) SetupSuite() { +func (s *DuoPushWebDriverSuite) SetupSuite() { wds, err := StartWebDriver() if err != nil { @@ -27,7 +27,7 @@ func (s *DuoPushSuite) SetupSuite() { s.WebDriverSession = wds } -func (s *DuoPushSuite) TearDownSuite() { +func (s *DuoPushWebDriverSuite) TearDownSuite() { err := s.WebDriverSession.Stop() if err != nil { @@ -35,14 +35,14 @@ func (s *DuoPushSuite) TearDownSuite() { } } -func (s *DuoPushSuite) SetupTest() { +func (s *DuoPushWebDriverSuite) SetupTest() { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() s.doLogout(ctx, s.T()) } -func (s *DuoPushSuite) TearDownTest() { +func (s *DuoPushWebDriverSuite) TearDownTest() { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -50,7 +50,7 @@ func (s *DuoPushSuite) TearDownTest() { s.WaitElementLocatedByID(ctx, s.T(), "one-time-password-method") } -func (s *DuoPushSuite) TestShouldSucceedAuthentication() { +func (s *DuoPushWebDriverSuite) TestShouldSucceedAuthentication() { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() @@ -61,7 +61,7 @@ func (s *DuoPushSuite) TestShouldSucceedAuthentication() { s.WaitElementLocatedByClassName(ctx, s.T(), "success-icon") } -func (s *DuoPushSuite) TestShouldFailAuthentication() { +func (s *DuoPushWebDriverSuite) TestShouldFailAuthentication() { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() @@ -72,11 +72,29 @@ func (s *DuoPushSuite) TestShouldFailAuthentication() { s.WaitElementLocatedByClassName(ctx, s.T(), "failure-icon") } -func TestDuoPushSuite(t *testing.T) { - suite.Run(t, NewDuoPushSuite()) - suite.Run(t, NewAvailableMethodsScenario([]string{ +type DuoPushSuite struct { + suite.Suite +} + +func NewDuoPushSuite() *DuoPushSuite { + return &DuoPushSuite{} +} + +func (s *DuoPushSuite) TestDuoPushWebDriverSuite() { + suite.Run(s.T(), NewDuoPushWebDriverSuite()) +} + +func (s *DuoPushSuite) TestAvailableMethodsScenario() { + suite.Run(s.T(), NewAvailableMethodsScenario([]string{ "ONE-TIME PASSWORD", "PUSH NOTIFICATION", })) - suite.Run(t, NewUserPreferencesScenario()) +} + +func (s *DuoPushSuite) TestUserPreferencesScenario() { + suite.Run(s.T(), NewUserPreferencesScenario()) +} + +func TestDuoPushSuite(t *testing.T) { + suite.Run(t, NewDuoPushSuite()) } diff --git a/internal/suites/suite_high_availability_test.go b/internal/suites/suite_high_availability_test.go index 562676d1e..f19084bb6 100644 --- a/internal/suites/suite_high_availability_test.go +++ b/internal/suites/suite_high_availability_test.go @@ -203,15 +203,32 @@ func (s *HighAvailabilitySuite) TestBasicAuth() { s.Assert().Equal(DoGetWithAuth(s.T(), "john", "password"), 200) s.Assert().Equal(DoGetWithAuth(s.T(), "john", "bad-password"), 302) s.Assert().Equal(DoGetWithAuth(s.T(), "dontexist", "password"), 302) +} +func (s *HighAvailabilitySuite) TestOneFactorScenario() { + suite.Run(s.T(), NewOneFactorScenario()) +} + +func (s *HighAvailabilitySuite) TestTwoFactorScenario() { + suite.Run(s.T(), NewTwoFactorScenario()) +} + +func (s *HighAvailabilitySuite) TestRegulationScenario() { + suite.Run(s.T(), NewRegulationScenario()) +} + +func (s *HighAvailabilitySuite) TestCustomHeadersScenario() { + suite.Run(s.T(), NewCustomHeadersScenario()) +} + +func (s *HighAvailabilitySuite) TestRedirectionCheckScenario() { + suite.Run(s.T(), NewRedirectionCheckScenario()) +} + +func (s *HighAvailabilitySuite) TestHighAvailabilityWebDriverSuite() { + suite.Run(s.T(), NewHighAvailabilityWebDriverSuite()) } func TestHighAvailabilitySuite(t *testing.T) { - suite.Run(t, NewOneFactorScenario()) - suite.Run(t, NewTwoFactorScenario()) - suite.Run(t, NewRegulationScenario()) - suite.Run(t, NewCustomHeadersScenario()) - suite.Run(t, NewRedirectionCheckScenario()) - suite.Run(t, NewHighAvailabilityWebDriverSuite()) suite.Run(t, NewHighAvailabilitySuite()) } diff --git a/internal/suites/suite_kubernetes_test.go b/internal/suites/suite_kubernetes_test.go index f41679c58..8162e882c 100644 --- a/internal/suites/suite_kubernetes_test.go +++ b/internal/suites/suite_kubernetes_test.go @@ -14,7 +14,14 @@ func NewKubernetesSuite() *KubernetesSuite { return &KubernetesSuite{SeleniumSuite: new(SeleniumSuite)} } -func TestKubernetesSuite(t *testing.T) { - suite.Run(t, NewOneFactorScenario()) - suite.Run(t, NewTwoFactorScenario()) +func (s *KubernetesSuite) TestOneFactorScenario() { + suite.Run(s.T(), NewOneFactorScenario()) +} + +func (s *KubernetesSuite) TestTwoFactorScenario() { + suite.Run(s.T(), NewTwoFactorScenario()) +} + +func TestKubernetesSuite(t *testing.T) { + suite.Run(t, NewKubernetesSuite()) } diff --git a/internal/suites/suite_ldap_test.go b/internal/suites/suite_ldap_test.go index 521dcf4ec..0794fbad4 100644 --- a/internal/suites/suite_ldap_test.go +++ b/internal/suites/suite_ldap_test.go @@ -14,7 +14,14 @@ func NewLDAPSuite() *LDAPSuite { return &LDAPSuite{SeleniumSuite: new(SeleniumSuite)} } -func TestLDAPSuite(t *testing.T) { - suite.Run(t, NewOneFactorScenario()) - suite.Run(t, NewTwoFactorScenario()) +func (s *LDAPSuite) TestOneFactorScenario() { + suite.Run(s.T(), NewOneFactorScenario()) +} + +func (s *LDAPSuite) TestTwoFactorScenario() { + suite.Run(s.T(), NewTwoFactorScenario()) +} + +func TestLDAPSuite(t *testing.T) { + suite.Run(t, NewLDAPSuite()) } diff --git a/internal/suites/suite_mariadb_test.go b/internal/suites/suite_mariadb_test.go index c114bb00d..1b29de7c9 100644 --- a/internal/suites/suite_mariadb_test.go +++ b/internal/suites/suite_mariadb_test.go @@ -14,7 +14,14 @@ func NewMariadbSuite() *MariadbSuite { return &MariadbSuite{SeleniumSuite: new(SeleniumSuite)} } -func TestMariadbSuite(t *testing.T) { - suite.Run(t, NewOneFactorScenario()) - suite.Run(t, NewTwoFactorScenario()) +func (s *MariadbSuite) TestOneFactorScenario() { + suite.Run(s.T(), NewOneFactorScenario()) +} + +func (s *MariadbSuite) TestTwoFactorScenario() { + suite.Run(s.T(), NewTwoFactorScenario()) +} + +func TestMariadbSuite(t *testing.T) { + suite.Run(t, NewMariadbSuite()) } diff --git a/internal/suites/suite_postgres_test.go b/internal/suites/suite_postgres_test.go index 59af70cd0..805f20c60 100644 --- a/internal/suites/suite_postgres_test.go +++ b/internal/suites/suite_postgres_test.go @@ -14,7 +14,14 @@ func NewPostgresSuite() *PostgresSuite { return &PostgresSuite{SeleniumSuite: new(SeleniumSuite)} } -func TestPostgresSuite(t *testing.T) { - suite.Run(t, NewOneFactorScenario()) - suite.Run(t, NewTwoFactorScenario()) +func (s *PostgresSuite) TestOneFactorScenario() { + suite.Run(s.T(), NewOneFactorScenario()) +} + +func (s *PostgresSuite) TestTwoFactorScenario() { + suite.Run(s.T(), NewTwoFactorScenario()) +} + +func TestPostgresSuite(t *testing.T) { + suite.Run(t, NewPostgresSuite()) } diff --git a/internal/suites/suite_short_timeouts_test.go b/internal/suites/suite_short_timeouts_test.go index 58f51f4e8..675638f6d 100644 --- a/internal/suites/suite_short_timeouts_test.go +++ b/internal/suites/suite_short_timeouts_test.go @@ -14,7 +14,14 @@ func NewShortTimeoutsSuite() *ShortTimeoutsSuite { return &ShortTimeoutsSuite{SeleniumSuite: new(SeleniumSuite)} } -func TestShortTimeoutsSuite(t *testing.T) { - suite.Run(t, NewInactivityScenario()) - suite.Run(t, NewRegulationScenario()) +func (s *ShortTimeoutsSuite) TestInactivityScenario() { + suite.Run(s.T(), NewInactivityScenario()) +} + +func (s *ShortTimeoutsSuite) TestRegulationScenario() { + suite.Run(s.T(), NewRegulationScenario()) +} + +func TestShortTimeoutsSuite(t *testing.T) { + suite.Run(t, NewShortTimeoutsSuite()) } diff --git a/internal/suites/suite_standalone_test.go b/internal/suites/suite_standalone_test.go index 6629d538d..8265844a8 100644 --- a/internal/suites/suite_standalone_test.go +++ b/internal/suites/suite_standalone_test.go @@ -121,18 +121,34 @@ func (s *StandaloneSuite) TestShouldVerifyAPIVerifyRedirectFromXOriginalHostURI( s.Assert().Equal(string(body), fmt.Sprintf("Found. Redirecting to %s?rd=https://secure.example.com:8080/", LoginBaseURL)) } -func TestStandaloneWebDriverScenario(t *testing.T) { - suite.Run(t, NewStandaloneWebDriverSuite()) +func (s *StandaloneSuite) TestStandaloneWebDriverScenario() { + suite.Run(s.T(), NewStandaloneWebDriverSuite()) +} + +func (s *StandaloneSuite) TestOneFactorScenario() { + suite.Run(s.T(), NewOneFactorScenario()) +} + +func (s *StandaloneSuite) TestTwoFactorScenario() { + suite.Run(s.T(), NewTwoFactorScenario()) +} + +func (s *StandaloneSuite) TestBypassPolicyScenario() { + suite.Run(s.T(), NewBypassPolicyScenario()) +} + +func (s *StandaloneSuite) TestBackendProtectionScenario() { + suite.Run(s.T(), NewBackendProtectionScenario()) +} + +func (s *StandaloneSuite) TestResetPasswordScenario() { + suite.Run(s.T(), NewResetPasswordScenario()) +} + +func (s *StandaloneSuite) TestAvailableMethodsScenario() { + suite.Run(s.T(), NewAvailableMethodsScenario([]string{"ONE-TIME PASSWORD"})) } func TestStandaloneSuite(t *testing.T) { - suite.Run(t, NewOneFactorScenario()) - suite.Run(t, NewTwoFactorScenario()) - suite.Run(t, NewBypassPolicyScenario()) - suite.Run(t, NewBackendProtectionScenario()) - suite.Run(t, NewResetPasswordScenario()) - suite.Run(t, NewAvailableMethodsScenario([]string{"ONE-TIME PASSWORD"})) - - suite.Run(t, NewStandaloneWebDriverSuite()) suite.Run(t, NewStandaloneSuite()) } diff --git a/internal/suites/suite_traefik_test.go b/internal/suites/suite_traefik_test.go index 0d87ab774..cc7505eea 100644 --- a/internal/suites/suite_traefik_test.go +++ b/internal/suites/suite_traefik_test.go @@ -14,7 +14,14 @@ func NewTraefikSuite() *TraefikSuite { return &TraefikSuite{SeleniumSuite: new(SeleniumSuite)} } -func TestTraefikSuite(t *testing.T) { - suite.Run(t, NewOneFactorScenario()) - suite.Run(t, NewTwoFactorScenario()) +func (s *TraefikSuite) TestOneFactorScenario() { + suite.Run(s.T(), NewOneFactorScenario()) +} + +func (s *TraefikSuite) TestTwoFactorScenario() { + suite.Run(s.T(), NewTwoFactorScenario()) +} + +func TestTraefikSuite(t *testing.T) { + suite.Run(t, NewTraefikSuite()) }