miniauth/pkg/web/web_test.go
2025-03-14 01:49:49 +01:00

39 lines
820 B
Go

package web
import (
"html/template"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
func TestRegistrationDisabled(t *testing.T) {
webConfig := WebConfig{}
webConfig.PublicRegistration = false
web := NewWeb(webConfig)
router := gin.New()
loadTemplates(router)
grpup := router.Group("/web")
web.RegisterRoutes(grpup)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/web/register", nil)
router.ServeHTTP(w, req)
assert.Equal(t, 403, w.Code)
content := string(w.Body.Bytes())
assert.Contains(t, content, "Public registration disabled")
}
func loadTemplates(r *gin.Engine) {
tmpl, err := template.ParseGlob("../../templates/*.html")
if err != nil {
panic(err) // Handle Fehler entsprechend
}
r.SetHTMLTemplate(tmpl)
}