feat(auth): X-Auth-Request-User context middleware
This commit is contained in:
28
internal/auth/caller_test.go
Normal file
28
internal/auth/caller_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package auth_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"gitea.d-ma.be/mathias/gitea-mcp/internal/auth"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCallerFromContext(t *testing.T) {
|
||||
called := false
|
||||
h := auth.CallerMiddleware(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
|
||||
called = true
|
||||
assert.Equal(t, "mathiasbq", auth.Caller(r.Context()))
|
||||
}))
|
||||
req := httptest.NewRequest(http.MethodPost, "/", nil)
|
||||
req.Header.Set("X-Auth-Request-User", "mathiasbq")
|
||||
rr := httptest.NewRecorder()
|
||||
h.ServeHTTP(rr, req)
|
||||
assert.True(t, called)
|
||||
}
|
||||
|
||||
func TestCallerEmptyWhenHeaderMissing(t *testing.T) {
|
||||
assert.Equal(t, "", auth.Caller(context.Background()))
|
||||
}
|
||||
Reference in New Issue
Block a user