Files
ocis/services/proxy/pkg/middleware/create_home_test.go
Paul FaureandClaude Opus 5.5 1347e3607d fix(proxy): don't log an error when create-home finds no user (#13102)
Requests on unprotected routes can carry a reva token without a resolved
user: reva's internal downloads to the data gateway (/data) are sent with
the caller's token. create_home logged "no user in context" at error level
for each of them, so every download added an error line. Log at debug with
the path instead; the request is passed on unchanged, as before.

Fixes #13101


Claude-Session: https://claude.ai/code/session_01WpoeSoKYEdgQcWjEzTVKpT

Signed-off-by: Paul Faure <paul@faure.ca>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:50:55 +02:00

40 lines
1.1 KiB
Go

package middleware
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
)
// A request with a reva token but no user, like reva's internal download requests to
// the data gateway, is passed on unchanged and does not log an error.
func TestCreateHomeWithoutUserPassesThroughQuietly(t *testing.T) {
// Other tests in this package raise the global level; let error lines through.
defer zerolog.SetGlobalLevel(zerolog.GlobalLevel())
zerolog.SetGlobalLevel(zerolog.TraceLevel)
var buf bytes.Buffer
logger := log.Logger{Logger: zerolog.New(&buf).Level(zerolog.InfoLevel)}
nextCalled := false
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
nextCalled = true
w.WriteHeader(http.StatusOK)
})
sut := CreateHome(Logger(logger))(next)
req := httptest.NewRequest(http.MethodGet, "/data/some-transfer-token", nil)
req.Header.Set("x-access-token", "a-token")
rw := httptest.NewRecorder()
sut.ServeHTTP(rw, req)
assert.True(t, nextCalled)
assert.Equal(t, http.StatusOK, rw.Code)
assert.Empty(t, buf.String())
}