This repository has been archived on 2025-10-08. You can view files and clone it, but cannot push or open issues or pull requests.
miniauthold/pkg/web/web_test.go
kekskurse 6962d40d78
Some checks failed
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/playwright Pipeline failed
ci/woodpecker/push/deplyoment unknown status
add globale config
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)
}