2019-11-02 14:32:58 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
2019-11-24 20:27:59 +00:00
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2019-11-02 14:32:58 +00:00
|
|
|
"testing"
|
2019-11-24 20:27:59 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/suite"
|
2023-04-15 05:03:14 +00:00
|
|
|
"github.com/valyala/fasthttp"
|
2019-11-02 14:32:58 +00:00
|
|
|
)
|
|
|
|
|
2019-11-24 20:27:59 +00:00
|
|
|
type HighAvailabilityWebDriverSuite struct {
|
2021-11-05 13:14:42 +00:00
|
|
|
*RodSuite
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|
|
|
|
|
2019-11-24 20:27:59 +00:00
|
|
|
func NewHighAvailabilityWebDriverSuite() *HighAvailabilityWebDriverSuite {
|
2023-01-25 04:11:05 +00:00
|
|
|
return &HighAvailabilityWebDriverSuite{
|
|
|
|
RodSuite: NewRodSuite(""),
|
|
|
|
}
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HighAvailabilityWebDriverSuite) SetupSuite() {
|
2023-01-25 04:11:05 +00:00
|
|
|
s.BaseSuite.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
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HighAvailabilityWebDriverSuite) 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:49:52 +00:00
|
|
|
func (s *HighAvailabilityWebDriverSuite) SetupTest() {
|
2021-11-05 13:14:42 +00:00
|
|
|
s.Page = s.doCreateTab(s.T(), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Page)
|
|
|
|
}
|
2019-11-30 16:49:52 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
func (s *HighAvailabilityWebDriverSuite) TearDownTest() {
|
|
|
|
s.collectCoverage(s.Page)
|
|
|
|
s.MustClose()
|
2019-11-30 16:49:52 +00:00
|
|
|
}
|
|
|
|
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
func (s *HighAvailabilityWebDriverSuite) TestShouldKeepUserSessionActive() {
|
2021-11-05 13:14:42 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
secret := s.doRegisterThenLogout(s.T(), s.Context(ctx), "john", "password")
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
|
|
|
err := haDockerEnvironment.Restart("redis-node-0")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLoginTwoFactor(s.T(), s.Context(ctx), "john", "password", false, secret, "")
|
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HighAvailabilityWebDriverSuite) TestShouldKeepUserSessionActiveWithPrimaryRedisNodeFailure() {
|
2021-11-05 13:14:42 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
secret := s.doRegisterThenLogout(s.T(), s.Context(ctx), "john", "password")
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLoginTwoFactor(s.T(), s.Context(ctx), "john", "password", false, secret, "")
|
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
|
|
|
err := haDockerEnvironment.Stop("redis-node-0")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
err = haDockerEnvironment.Start("redis-node-0")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}()
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Context(ctx))
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Verify the user is still authenticated.
|
2023-01-12 10:57:44 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), GetLoginBaseURL(BaseDomain))
|
2021-11-05 13:14:42 +00:00
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
|
|
|
// Then logout and login again to check we can see the secret.
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLogout(s.T(), s.Context(ctx))
|
|
|
|
s.verifyIsFirstFactorPage(s.T(), s.Context(ctx))
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLoginTwoFactor(s.T(), s.Context(ctx), "john", "password", false, secret, fmt.Sprintf("%s/secret.html", SecureBaseURL))
|
|
|
|
s.verifySecretAuthorized(s.T(), s.Context(ctx))
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HighAvailabilityWebDriverSuite) TestShouldKeepUserSessionActiveWithPrimaryRedisSentinelFailureAndSecondaryRedisNodeFailure() {
|
2021-11-05 13:14:42 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
secret := s.doRegisterThenLogout(s.T(), s.Context(ctx), "john", "password")
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLoginTwoFactor(s.T(), s.Context(ctx), "john", "password", false, secret, "")
|
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
|
|
|
err := haDockerEnvironment.Stop("redis-sentinel-0")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
err = haDockerEnvironment.Start("redis-sentinel-0")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}()
|
|
|
|
|
|
|
|
err = haDockerEnvironment.Stop("redis-node-2")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
err = haDockerEnvironment.Start("redis-node-2")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}()
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Context(ctx))
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Verify the user is still authenticated.
|
2023-01-12 10:57:44 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), GetLoginBaseURL(BaseDomain))
|
2021-11-05 13:14:42 +00:00
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
}
|
|
|
|
|
2019-11-24 20:27:59 +00:00
|
|
|
func (s *HighAvailabilityWebDriverSuite) TestShouldKeepUserDataInDB() {
|
2021-11-05 13:14:42 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
|
|
|
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
|
|
|
secret := s.doRegisterThenLogout(s.T(), s.Context(ctx), "john", "password")
|
2019-11-24 20:27:59 +00:00
|
|
|
|
|
|
|
err := haDockerEnvironment.Restart("mariadb")
|
2019-12-07 16:40:42 +00:00
|
|
|
s.Require().NoError(err)
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLoginTwoFactor(s.T(), s.Context(ctx), "john", "password", false, secret, "")
|
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HighAvailabilityWebDriverSuite) TestShouldKeepSessionAfterAutheliaRestart() {
|
2019-12-08 12:16:13 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 120*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
|
|
|
secret := s.doRegisterAndLogin2FA(s.T(), s.Context(ctx), "john", "password", false, "")
|
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
|
|
|
|
err := haDockerEnvironment.Restart("authelia-backend")
|
2019-12-08 12:16:13 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
err = waitUntilAutheliaBackendIsReady(haDockerEnvironment)
|
|
|
|
s.Require().NoError(err)
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Verify the user is still authenticated.
|
2023-01-12 10:57:44 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), GetLoginBaseURL(BaseDomain))
|
2021-11-05 13:14:42 +00:00
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Then logout and login again to check the secret is still there.
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLogout(s.T(), s.Context(ctx))
|
|
|
|
s.verifyIsFirstFactorPage(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLoginTwoFactor(s.T(), s.Context(ctx), "john", "password", false, secret, fmt.Sprintf("%s/secret.html", SecureBaseURL))
|
|
|
|
s.verifySecretAuthorized(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var UserJohn = "john"
|
2023-01-25 04:11:05 +00:00
|
|
|
|
2019-11-24 20:27:59 +00:00
|
|
|
var UserBob = "bob"
|
2023-01-25 04:11:05 +00:00
|
|
|
|
2019-11-24 20:27:59 +00:00
|
|
|
var UserHarry = "harry"
|
|
|
|
|
|
|
|
var Users = []string{UserJohn, UserBob, UserHarry}
|
|
|
|
|
|
|
|
var expectedAuthorizations = map[string](map[string]bool){
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/secret.html", PublicBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: true, UserBob: true, UserHarry: true,
|
|
|
|
},
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/secret.html", SecureBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: true, UserBob: true, UserHarry: true,
|
|
|
|
},
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/secret.html", AdminBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: true, UserBob: false, UserHarry: false,
|
|
|
|
},
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/secret.html", SingleFactorBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: true, UserBob: true, UserHarry: true,
|
|
|
|
},
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/secret.html", MX1MailBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: true, UserBob: true, UserHarry: false,
|
|
|
|
},
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/secret.html", MX2MailBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: false, UserBob: true, UserHarry: false,
|
|
|
|
},
|
|
|
|
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/groups/admin/secret.html", DevBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: true, UserBob: false, UserHarry: false,
|
|
|
|
},
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/groups/dev/secret.html", DevBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: true, UserBob: true, UserHarry: false,
|
|
|
|
},
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/users/john/secret.html", DevBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: true, UserBob: false, UserHarry: false,
|
|
|
|
},
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/users/harry/secret.html", DevBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: true, UserBob: false, UserHarry: true,
|
|
|
|
},
|
2021-03-14 07:08:26 +00:00
|
|
|
fmt.Sprintf("%s/users/bob/secret.html", DevBaseURL): {
|
2019-11-24 20:27:59 +00:00
|
|
|
UserJohn: true, UserBob: true, UserHarry: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HighAvailabilityWebDriverSuite) TestShouldVerifyAccessControl() {
|
2021-11-05 13:14:42 +00:00
|
|
|
verifyUserIsAuthorized := func(ctx context.Context, t *testing.T, targetURL string, authorized bool) {
|
|
|
|
s.doVisit(t, s.Context(ctx), targetURL)
|
|
|
|
s.verifyURLIs(t, s.Context(ctx), targetURL)
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2019-11-24 20:27:59 +00:00
|
|
|
if authorized {
|
2021-11-05 13:14:42 +00:00
|
|
|
s.verifySecretAuthorized(t, s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
} else {
|
2021-11-05 13:14:42 +00:00
|
|
|
s.verifyBodyContains(t, s.Context(ctx), "403 Forbidden")
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
verifyAuthorization := func(username string) func(t *testing.T) {
|
|
|
|
return func(t *testing.T) {
|
2023-01-12 10:57:44 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
2021-11-05 13:14:42 +00:00
|
|
|
defer func() {
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
cancel()
|
|
|
|
}()
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doRegisterAndLogin2FA(t, s.Context(ctx), username, "password", false, "")
|
2019-11-24 20:27:59 +00:00
|
|
|
|
|
|
|
for url, authorizations := range expectedAuthorizations {
|
2019-11-30 16:49:52 +00:00
|
|
|
t.Run(url, func(t *testing.T) {
|
2021-11-05 13:14:42 +00:00
|
|
|
verifyUserIsAuthorized(ctx, t, url, authorizations[username])
|
2019-11-30 16:49:52 +00:00
|
|
|
})
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLogout(t, s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-09 01:05:17 +00:00
|
|
|
for _, user := range Users {
|
|
|
|
s.T().Run(user, verifyAuthorization(user))
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HighAvailabilitySuite struct {
|
2023-01-25 04:11:05 +00:00
|
|
|
*BaseSuite
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2019-11-02 14:32:58 +00:00
|
|
|
func NewHighAvailabilitySuite() *HighAvailabilitySuite {
|
2023-01-25 04:11:05 +00:00
|
|
|
return &HighAvailabilitySuite{
|
|
|
|
BaseSuite: &BaseSuite{
|
|
|
|
Name: highAvailabilitySuiteName,
|
|
|
|
},
|
|
|
|
}
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func DoGetWithAuth(t *testing.T, username, password string) int {
|
|
|
|
client := NewHTTPClient()
|
2023-04-15 05:03:14 +00:00
|
|
|
req, err := http.NewRequest(fasthttp.MethodGet, fmt.Sprintf("%s/secret.html", SingleFactorBaseURL), nil)
|
2019-11-24 20:27:59 +00:00
|
|
|
assert.NoError(t, err)
|
2021-03-14 07:08:26 +00:00
|
|
|
req.SetBasicAuth(username, password)
|
2019-11-24 20:27:59 +00:00
|
|
|
|
|
|
|
res, err := client.Do(req)
|
|
|
|
assert.NoError(t, err)
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2019-11-24 20:27:59 +00:00
|
|
|
return res.StatusCode
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HighAvailabilitySuite) TestBasicAuth() {
|
2023-04-15 05:03:14 +00:00
|
|
|
s.Assert().Equal(fasthttp.StatusOK, DoGetWithAuth(s.T(), "john", "password"))
|
|
|
|
s.Assert().Equal(fasthttp.StatusFound, DoGetWithAuth(s.T(), "john", "bad-password"))
|
|
|
|
s.Assert().Equal(fasthttp.StatusFound, DoGetWithAuth(s.T(), "dontexist", "password"))
|
2019-12-05 21:35:03 +00:00
|
|
|
}
|
|
|
|
|
2022-05-04 01:01:36 +00:00
|
|
|
func (s *HighAvailabilitySuite) Test1FAScenario() {
|
|
|
|
suite.Run(s.T(), New1FAScenario())
|
2019-12-05 21:35:03 +00:00
|
|
|
}
|
|
|
|
|
2022-05-04 01:01:36 +00:00
|
|
|
func (s *HighAvailabilitySuite) Test2FAScenario() {
|
|
|
|
suite.Run(s.T(), New2FAScenario())
|
2019-12-05 21:35:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
}
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *HighAvailabilitySuite) TestHighAvailabilityWebDriverSuite() {
|
|
|
|
suite.Run(s.T(), NewHighAvailabilityWebDriverSuite())
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-07 16:40:42 +00:00
|
|
|
func TestHighAvailabilityWebDriverSuite(t *testing.T) {
|
2021-03-14 07:08:26 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping suite test in short mode")
|
|
|
|
}
|
|
|
|
|
2019-12-07 16:40:42 +00:00
|
|
|
suite.Run(t, NewHighAvailabilityWebDriverSuite())
|
|
|
|
}
|
|
|
|
|
2019-11-02 14:32:58 +00:00
|
|
|
func TestHighAvailabilitySuite(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, NewHighAvailabilitySuite())
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|