25 lines
615 B
Go
25 lines
615 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/gochat/gochat/internal/auth"
|
|
)
|
|
|
|
func TestWebhookAuth_NoToken(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
registry := &auth.WebhookTokenRegistry{}
|
|
r := gin.New()
|
|
r.Use(WebhookAuth(registry))
|
|
r.POST("/:channel_type/:identifier/webhook", func(c *gin.Context) { c.JSON(200, gin.H{"ok": true}) })
|
|
|
|
w := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodPost, "/web_widget/test-inbox/webhook", nil)
|
|
r.ServeHTTP(w, req)
|
|
assert.Equal(t, 401, w.Code)
|
|
} |