feat: configure MariaDB TLS for setup and runtime connections (#5)
This commit is contained in:
1 parent
15f81e053c
commit
370407d3ba
9 files changed
+325
-9
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.mchus.pro/mchus/quoteforge/internal/localdb"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestSetupFreshSettingsValidateTLS(t *testing.T) {
|
||||
local, err := localdb.New(filepath.Join(t.TempDir(), "qfs.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer local.Close()
|
||||
handler := &SetupHandler{localDB: local}
|
||||
for _, test := range []struct {
|
||||
path string
|
||||
handler gin.HandlerFunc
|
||||
}{{"/setup/test", handler.TestConnection}, {"/setup", handler.SaveConnection}} {
|
||||
router := gin.New()
|
||||
router.POST(test.path, test.handler)
|
||||
body := url.Values{"host": {"db.example"}, "user": {"example"}, "tls_mode": {"invalid"}}.Encode()
|
||||
req := httptest.NewRequest(http.MethodPost, test.path, strings.NewReader(body))
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
w := httptest.NewRecorder()
|
||||
router.ServeHTTP(w, req)
|
||||
if w.Code != http.StatusUnprocessableEntity {
|
||||
t.Fatalf("%s: status=%d body=%s", test.path, w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user