2019-04-24 21:52:08 +00:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
2020-03-28 06:10:39 +00:00
|
|
|
"crypto/sha256"
|
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
|
|
|
"crypto/tls"
|
2019-04-24 21:52:08 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-03-13 05:06:19 +00:00
|
|
|
"github.com/fasthttp/session/v2"
|
2019-04-24 21:52:08 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-03-28 06:10:39 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-04-05 12:37:21 +00:00
|
|
|
|
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
|
|
"github.com/authelia/authelia/internal/utils"
|
2019-04-24 21:52:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestShouldCreateInMemorySessionProvider(t *testing.T) {
|
|
|
|
// The redis configuration is not provided so we create a in-memory provider.
|
|
|
|
configuration := schema.SessionConfiguration{}
|
2020-05-02 16:20:40 +00:00
|
|
|
configuration.Domain = testDomain
|
|
|
|
configuration.Name = testName
|
|
|
|
configuration.Expiration = testExpiration
|
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
|
|
|
providerConfig := NewProviderConfig(configuration, nil)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
|
|
|
assert.Equal(t, "my_session", providerConfig.config.CookieName)
|
2020-05-02 16:20:40 +00:00
|
|
|
assert.Equal(t, testDomain, providerConfig.config.Domain)
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.Equal(t, true, providerConfig.config.Secure)
|
2020-05-18 02:45:47 +00:00
|
|
|
assert.Equal(t, time.Duration(40)*time.Second, providerConfig.config.Expiration)
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.True(t, providerConfig.config.IsSecureFunc(nil))
|
|
|
|
|
|
|
|
assert.Equal(t, "memory", providerConfig.providerName)
|
|
|
|
}
|
|
|
|
|
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 TestShouldCreateRedisSessionProviderTLS(t *testing.T) {
|
|
|
|
configuration := schema.SessionConfiguration{}
|
|
|
|
configuration.Domain = testDomain
|
|
|
|
configuration.Name = testName
|
|
|
|
configuration.Expiration = testExpiration
|
|
|
|
configuration.Redis = &schema.RedisSessionConfiguration{
|
|
|
|
Host: "redis.example.com",
|
|
|
|
Port: 6379,
|
|
|
|
Password: "pass",
|
|
|
|
TLS: &schema.TLSConfig{
|
|
|
|
ServerName: "redis.fqdn.example.com",
|
|
|
|
MinimumVersion: "TLS1.3",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
providerConfig := NewProviderConfig(configuration, nil)
|
|
|
|
|
|
|
|
assert.Nil(t, providerConfig.redisSentinelConfig)
|
|
|
|
assert.Equal(t, "my_session", providerConfig.config.CookieName)
|
|
|
|
assert.Equal(t, testDomain, providerConfig.config.Domain)
|
|
|
|
assert.Equal(t, true, providerConfig.config.Secure)
|
|
|
|
assert.Equal(t, time.Duration(40)*time.Second, providerConfig.config.Expiration)
|
|
|
|
assert.True(t, providerConfig.config.IsSecureFunc(nil))
|
|
|
|
|
|
|
|
assert.Equal(t, "redis", providerConfig.providerName)
|
|
|
|
|
|
|
|
pConfig := providerConfig.redisConfig
|
|
|
|
assert.Equal(t, "redis.example.com:6379", pConfig.Addr)
|
|
|
|
assert.Equal(t, "pass", pConfig.Password)
|
|
|
|
// DbNumber is the fasthttp/session property for the Redis DB Index
|
|
|
|
assert.Equal(t, 0, pConfig.DB)
|
|
|
|
assert.Equal(t, 0, pConfig.PoolSize)
|
|
|
|
assert.Equal(t, 0, pConfig.MinIdleConns)
|
|
|
|
|
|
|
|
require.NotNil(t, pConfig.TLSConfig)
|
|
|
|
require.Equal(t, uint16(tls.VersionTLS13), pConfig.TLSConfig.MinVersion)
|
|
|
|
require.Equal(t, "redis.fqdn.example.com", pConfig.TLSConfig.ServerName)
|
|
|
|
require.False(t, pConfig.TLSConfig.InsecureSkipVerify)
|
|
|
|
}
|
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
func TestShouldCreateRedisSessionProvider(t *testing.T) {
|
|
|
|
configuration := schema.SessionConfiguration{}
|
2020-05-02 16:20:40 +00:00
|
|
|
configuration.Domain = testDomain
|
|
|
|
configuration.Name = testName
|
|
|
|
configuration.Expiration = testExpiration
|
2019-04-24 21:52:08 +00:00
|
|
|
configuration.Redis = &schema.RedisSessionConfiguration{
|
|
|
|
Host: "redis.example.com",
|
|
|
|
Port: 6379,
|
|
|
|
Password: "pass",
|
|
|
|
}
|
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
|
|
|
providerConfig := NewProviderConfig(configuration, nil)
|
2019-04-24 21:52:08 +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
|
|
|
assert.Nil(t, providerConfig.redisSentinelConfig)
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.Equal(t, "my_session", providerConfig.config.CookieName)
|
2020-05-02 16:20:40 +00:00
|
|
|
assert.Equal(t, testDomain, providerConfig.config.Domain)
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.Equal(t, true, providerConfig.config.Secure)
|
2020-05-18 02:45:47 +00:00
|
|
|
assert.Equal(t, time.Duration(40)*time.Second, providerConfig.config.Expiration)
|
|
|
|
assert.True(t, providerConfig.config.IsSecureFunc(nil))
|
|
|
|
|
|
|
|
assert.Equal(t, "redis", providerConfig.providerName)
|
|
|
|
|
|
|
|
pConfig := providerConfig.redisConfig
|
|
|
|
assert.Equal(t, "redis.example.com:6379", pConfig.Addr)
|
|
|
|
assert.Equal(t, "pass", pConfig.Password)
|
|
|
|
// DbNumber is the fasthttp/session property for the Redis DB Index
|
|
|
|
assert.Equal(t, 0, pConfig.DB)
|
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
|
|
|
assert.Equal(t, 0, pConfig.PoolSize)
|
|
|
|
assert.Equal(t, 0, pConfig.MinIdleConns)
|
|
|
|
|
|
|
|
assert.Nil(t, pConfig.TLSConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldCreateRedisSentinelSessionProviderWithoutDuplicateHosts(t *testing.T) {
|
|
|
|
configuration := schema.SessionConfiguration{}
|
|
|
|
configuration.Domain = testDomain
|
|
|
|
configuration.Name = testName
|
|
|
|
configuration.Expiration = testExpiration
|
|
|
|
configuration.Redis = &schema.RedisSessionConfiguration{
|
|
|
|
Host: "REDIS.example.com",
|
|
|
|
Port: 26379,
|
|
|
|
Password: "pass",
|
|
|
|
MaximumActiveConnections: 8,
|
|
|
|
MinimumIdleConnections: 2,
|
|
|
|
HighAvailability: &schema.RedisHighAvailabilityConfiguration{
|
|
|
|
SentinelName: "mysent",
|
|
|
|
SentinelPassword: "mypass",
|
|
|
|
Nodes: []schema.RedisNode{
|
|
|
|
{
|
|
|
|
Host: "redis2.example.com",
|
|
|
|
Port: 26379,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Host: "redis.example.com",
|
|
|
|
Port: 26379,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
providerConfig := NewProviderConfig(configuration, nil)
|
|
|
|
|
|
|
|
assert.Len(t, providerConfig.redisSentinelConfig.SentinelAddrs, 2)
|
|
|
|
assert.Equal(t, providerConfig.redisSentinelConfig.SentinelAddrs[0], "redis.example.com:26379")
|
|
|
|
assert.Equal(t, providerConfig.redisSentinelConfig.SentinelAddrs[1], "redis2.example.com:26379")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldCreateRedisSentinelSessionProvider(t *testing.T) {
|
|
|
|
configuration := schema.SessionConfiguration{}
|
|
|
|
configuration.Domain = testDomain
|
|
|
|
configuration.Name = testName
|
|
|
|
configuration.Expiration = testExpiration
|
|
|
|
configuration.Redis = &schema.RedisSessionConfiguration{
|
|
|
|
Host: "redis.example.com",
|
|
|
|
Port: 26379,
|
|
|
|
Password: "pass",
|
|
|
|
MaximumActiveConnections: 8,
|
|
|
|
MinimumIdleConnections: 2,
|
|
|
|
HighAvailability: &schema.RedisHighAvailabilityConfiguration{
|
|
|
|
SentinelName: "mysent",
|
|
|
|
SentinelPassword: "mypass",
|
|
|
|
Nodes: []schema.RedisNode{
|
|
|
|
{
|
|
|
|
Host: "redis2.example.com",
|
|
|
|
Port: 26379,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
providerConfig := NewProviderConfig(configuration, nil)
|
|
|
|
|
|
|
|
assert.Nil(t, providerConfig.redisConfig)
|
|
|
|
assert.Equal(t, "my_session", providerConfig.config.CookieName)
|
|
|
|
assert.Equal(t, testDomain, providerConfig.config.Domain)
|
|
|
|
assert.Equal(t, true, providerConfig.config.Secure)
|
|
|
|
assert.Equal(t, time.Duration(40)*time.Second, providerConfig.config.Expiration)
|
|
|
|
assert.True(t, providerConfig.config.IsSecureFunc(nil))
|
|
|
|
|
|
|
|
assert.Equal(t, "redis-sentinel", providerConfig.providerName)
|
|
|
|
|
|
|
|
pConfig := providerConfig.redisSentinelConfig
|
|
|
|
assert.Equal(t, "redis.example.com:26379", pConfig.SentinelAddrs[0])
|
|
|
|
assert.Equal(t, "redis2.example.com:26379", pConfig.SentinelAddrs[1])
|
|
|
|
assert.Equal(t, "pass", pConfig.Password)
|
|
|
|
assert.Equal(t, "mysent", pConfig.MasterName)
|
|
|
|
assert.Equal(t, "mypass", pConfig.SentinelPassword)
|
|
|
|
assert.False(t, pConfig.RouteRandomly)
|
|
|
|
assert.False(t, pConfig.RouteByLatency)
|
|
|
|
assert.Equal(t, 8, pConfig.PoolSize)
|
|
|
|
assert.Equal(t, 2, pConfig.MinIdleConns)
|
|
|
|
|
|
|
|
// DbNumber is the fasthttp/session property for the Redis DB Index
|
|
|
|
assert.Equal(t, 0, pConfig.DB)
|
|
|
|
assert.Nil(t, pConfig.TLSConfig)
|
2020-05-18 02:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldCreateRedisSessionProviderWithUnixSocket(t *testing.T) {
|
|
|
|
configuration := schema.SessionConfiguration{}
|
|
|
|
configuration.Domain = testDomain
|
|
|
|
configuration.Name = testName
|
|
|
|
configuration.Expiration = testExpiration
|
|
|
|
configuration.Redis = &schema.RedisSessionConfiguration{
|
|
|
|
Host: "/var/run/redis/redis.sock",
|
|
|
|
Port: 0,
|
|
|
|
Password: "pass",
|
|
|
|
}
|
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
|
|
|
|
|
|
|
providerConfig := NewProviderConfig(configuration, nil)
|
|
|
|
|
|
|
|
assert.Nil(t, providerConfig.redisSentinelConfig)
|
2020-05-18 02:45:47 +00:00
|
|
|
|
|
|
|
assert.Equal(t, "my_session", providerConfig.config.CookieName)
|
|
|
|
assert.Equal(t, testDomain, providerConfig.config.Domain)
|
|
|
|
assert.Equal(t, true, providerConfig.config.Secure)
|
|
|
|
assert.Equal(t, time.Duration(40)*time.Second, providerConfig.config.Expiration)
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.True(t, providerConfig.config.IsSecureFunc(nil))
|
|
|
|
|
|
|
|
assert.Equal(t, "redis", providerConfig.providerName)
|
|
|
|
|
2020-05-18 02:45:47 +00:00
|
|
|
pConfig := providerConfig.redisConfig
|
|
|
|
assert.Equal(t, "/var/run/redis/redis.sock", pConfig.Addr)
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.Equal(t, "pass", pConfig.Password)
|
2020-02-28 00:14:44 +00:00
|
|
|
// DbNumber is the fasthttp/session property for the Redis DB Index
|
2020-05-18 02:45:47 +00:00
|
|
|
assert.Equal(t, 0, pConfig.DB)
|
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
|
|
|
assert.Nil(t, pConfig.TLSConfig)
|
2020-02-28 00:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldSetDbNumber(t *testing.T) {
|
|
|
|
configuration := schema.SessionConfiguration{}
|
2020-05-02 16:20:40 +00:00
|
|
|
configuration.Domain = testDomain
|
|
|
|
configuration.Name = testName
|
|
|
|
configuration.Expiration = testExpiration
|
2020-02-28 00:14:44 +00:00
|
|
|
configuration.Redis = &schema.RedisSessionConfiguration{
|
|
|
|
Host: "redis.example.com",
|
|
|
|
Port: 6379,
|
|
|
|
Password: "pass",
|
|
|
|
DatabaseIndex: 5,
|
|
|
|
}
|
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
|
|
|
|
|
|
|
providerConfig := NewProviderConfig(configuration, nil)
|
|
|
|
|
|
|
|
assert.Nil(t, providerConfig.redisSentinelConfig)
|
|
|
|
|
2020-02-28 00:14:44 +00:00
|
|
|
assert.Equal(t, "redis", providerConfig.providerName)
|
2020-05-18 02:45:47 +00:00
|
|
|
pConfig := providerConfig.redisConfig
|
2020-02-28 00:14:44 +00:00
|
|
|
// DbNumber is the fasthttp/session property for the Redis DB Index
|
2020-05-18 02:45:47 +00:00
|
|
|
assert.Equal(t, 5, pConfig.DB)
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
2020-03-28 06:10:39 +00:00
|
|
|
|
|
|
|
func TestShouldUseEncryptingSerializerWithRedis(t *testing.T) {
|
|
|
|
configuration := schema.SessionConfiguration{}
|
|
|
|
configuration.Secret = "abc"
|
|
|
|
configuration.Redis = &schema.RedisSessionConfiguration{
|
|
|
|
Host: "redis.example.com",
|
|
|
|
Port: 6379,
|
|
|
|
Password: "pass",
|
|
|
|
DatabaseIndex: 5,
|
|
|
|
}
|
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
|
|
|
providerConfig := NewProviderConfig(configuration, nil)
|
2020-03-28 06:10:39 +00:00
|
|
|
|
|
|
|
payload := session.Dict{}
|
|
|
|
payload.Set("key", "value")
|
|
|
|
|
2020-05-18 02:45:47 +00:00
|
|
|
encoded, err := providerConfig.config.EncodeFunc(payload)
|
2020-03-28 06:10:39 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Now we try to decrypt what has been serialized
|
|
|
|
key := sha256.Sum256([]byte("abc"))
|
|
|
|
decrypted, err := utils.Decrypt(encoded, &key)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
decoded := session.Dict{}
|
2020-04-09 01:05:17 +00:00
|
|
|
_, _ = decoded.UnmarshalMsg(decrypted)
|
2020-03-28 06:10:39 +00:00
|
|
|
assert.Equal(t, "value", decoded.Get("key"))
|
|
|
|
}
|