mirror of
https://github.com/gofiber/storage.git
synced 2025-10-06 17:17:18 +08:00
chore: verify mtls properly in tests
This commit is contained in:
@@ -77,6 +77,7 @@ func WithImage(image string) Option {
|
|||||||
// Container represents a running Redis container
|
// Container represents a running Redis container
|
||||||
type Container struct {
|
type Container struct {
|
||||||
URL string
|
URL string
|
||||||
|
cmds []string
|
||||||
Addrs []string
|
Addrs []string
|
||||||
Host string
|
Host string
|
||||||
Port int
|
Port int
|
||||||
@@ -106,16 +107,17 @@ func Start(t testing.TB, opts ...Option) *Container {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
tcOpts := []testcontainers.ContainerCustomizer{}
|
tcOpts := []testcontainers.ContainerCustomizer{}
|
||||||
|
|
||||||
|
var cmds []string
|
||||||
if config.UseTLS {
|
if config.UseTLS {
|
||||||
tcOpts = append(tcOpts, redis.WithTLS())
|
tcOpts = append(tcOpts, redis.WithTLS())
|
||||||
|
|
||||||
cmds := []string{
|
cmds = append(cmds,
|
||||||
"--port", "0",
|
"--port", "0",
|
||||||
"--tls-port", "6379",
|
"--tls-port", "6379",
|
||||||
"--tls-cert-file", "/tls/server.crt",
|
"--tls-cert-file", "/tls/server.crt",
|
||||||
"--tls-key-file", "/tls/server.key",
|
"--tls-key-file", "/tls/server.key",
|
||||||
"--tls-ca-cert-file", "/tls/ca.crt",
|
"--tls-ca-cert-file", "/tls/ca.crt",
|
||||||
}
|
)
|
||||||
|
|
||||||
cmds = append(cmds, "--tls-auth-clients", func() string {
|
cmds = append(cmds, "--tls-auth-clients", func() string {
|
||||||
if config.MTLSDisabled {
|
if config.MTLSDisabled {
|
||||||
@@ -133,6 +135,7 @@ func Start(t testing.TB, opts ...Option) *Container {
|
|||||||
|
|
||||||
ctr := &Container{
|
ctr := &Container{
|
||||||
TLSConfig: c.TLSConfig(),
|
TLSConfig: c.TLSConfig(),
|
||||||
|
cmds: cmds,
|
||||||
}
|
}
|
||||||
|
|
||||||
uri, err := c.ConnectionString(ctx)
|
uri, err := c.ConnectionString(ctx)
|
||||||
|
@@ -42,7 +42,7 @@ func TestStart(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("with-tls", func(t *testing.T) {
|
t.Run("with-tls", func(t *testing.T) {
|
||||||
t.Run("secure-url", func(t *testing.T) {
|
t.Run("secure-url", func(t *testing.T) {
|
||||||
t.Run("mtls-disabled", func(t *testing.T) {
|
t.Run("mtls-enabled", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
ctr := Start(t, WithTLS(true, false))
|
ctr := Start(t, WithTLS(true, false))
|
||||||
@@ -52,15 +52,17 @@ func TestStart(t *testing.T) {
|
|||||||
require.Empty(t, ctr.Addrs)
|
require.Empty(t, ctr.Addrs)
|
||||||
require.Empty(t, ctr.Host)
|
require.Empty(t, ctr.Host)
|
||||||
require.Zero(t, ctr.Port)
|
require.Zero(t, ctr.Port)
|
||||||
|
require.Contains(t, ctr.cmds, "--tls-auth-clients", "yes")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("mtls-enabled", func(t *testing.T) {
|
t.Run("mtls-disabled", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
ctr := Start(t, WithTLS(true, true))
|
ctr := Start(t, WithTLS(true, true))
|
||||||
require.NotEmpty(t, ctr.URL)
|
require.NotEmpty(t, ctr.URL)
|
||||||
require.True(t, strings.HasPrefix(ctr.URL, "rediss://"))
|
require.True(t, strings.HasPrefix(ctr.URL, "rediss://"))
|
||||||
require.NotNil(t, ctr.TLSConfig)
|
require.NotNil(t, ctr.TLSConfig)
|
||||||
|
require.Contains(t, ctr.cmds, "--tls-auth-clients", "no")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user