summaryrefslogtreecommitdiff
path: root/internal/storage/sql_provider_backend_mysql_test.go
blob: f5bd2bee7f81474dc28f5c052de26591aa4afcb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package storage

import (
	"crypto/tls"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	"github.com/authelia/authelia/v4/internal/configuration/schema"
)

func TestNewMySQLProvider(t *testing.T) {
	standardAddress, err := schema.NewAddress("tcp://mysql")
	require.NoError(t, err)

	testCases := []struct {
		name string
		have *schema.Configuration
	}{
		{
			"ShouldHandleBasic",
			&schema.Configuration{
				Storage: schema.Storage{
					MySQL: &schema.StorageMySQL{
						StorageSQL: schema.StorageSQL{
							Address:  &schema.AddressTCP{Address: *standardAddress},
							Database: "authelia",
						},
					},
				},
			},
		},
		{
			"ShouldHandleTLS",
			&schema.Configuration{
				Storage: schema.Storage{
					MySQL: &schema.StorageMySQL{
						StorageSQL: schema.StorageSQL{
							Address:  &schema.AddressTCP{Address: *standardAddress},
							Database: "authelia",
							TLS: &schema.TLS{
								MinimumVersion: schema.TLSVersion{Value: tls.VersionTLS12},
								MaximumVersion: schema.TLSVersion{Value: tls.VersionTLS13},
								SkipVerify:     false,
								ServerName:     "mysql",
							},
						},
					},
				},
			},
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			assert.NotNil(t, NewMySQLProvider(tc.have, nil))
		})
	}
}