feat: secure service connections and login

This commit is contained in:
2026-11-06 21:14:49 +03:00
parent cb51354889
commit 48918e8b19
59 changed files with 1980 additions and 316 deletions
+7 -2
View File
@@ -4,6 +4,7 @@ import (
"context"
"crypto/rand"
"crypto/sha256"
"crypto/tls"
"encoding/base64"
"encoding/hex"
"encoding/json"
@@ -14,7 +15,7 @@ import (
"github.com/valkey-io/valkey-go"
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
)
const (
@@ -40,11 +41,15 @@ type Store struct {
client valkey.Client
}
func New(rawURL string) (*Store, error) {
func New(rawURL string, tlsConfiguration ...*tls.Config) (*Store, error) {
option, err := valkey.ParseURL(rawURL)
if err != nil {
return nil, fmt.Errorf("%w: parse Valkey URL: %w", ErrStore, err)
}
if len(tlsConfiguration) > 0 && tlsConfiguration[0] != nil {
option.TLSConfig = tlsConfiguration[0].Clone()
}
option.DisableCache = true
client, err := valkey.NewClient(option)
if err != nil {
+10 -2
View File
@@ -11,7 +11,8 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/suite"
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/session"
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/tlsconfig"
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/session"
)
type SessionSuite struct {
@@ -34,7 +35,14 @@ func (s *SessionSuite) SetupSuite() {
s.Require().NoError(err)
rawURL = strings.TrimSpace(string(data))
}
store, err := session.New(rawURL)
tlsConfiguration, err := tlsconfig.LoadClient(tlsconfig.ClientConfig{
CAPath: os.Getenv("TEST_CACHE_TLS_CA_PATH"),
CertificatePath: os.Getenv("TEST_CACHE_TLS_CERTIFICATE_PATH"),
PrivateKeyPath: os.Getenv("TEST_CACHE_TLS_PRIVATE_KEY_PATH"),
ServerName: os.Getenv("TEST_CACHE_TLS_SERVER_NAME"),
})
s.Require().NoError(err)
store, err := session.New(rawURL, tlsConfiguration)
s.Require().NoError(err)
s.store = store
}