mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
The server module named github.com/hanzoai/team/server/v8 — a path that resolves to the retired workspace's repository, not this one — while server/public still published github.com/mattermost/mattermost/server/public. Both are github.com/hanzoteam/server/... now, which is where this code actually lives. That second half is what made the binary unbootable. Upstream's public path stayed claimed by upstream, mattermost-plugin-ai imported it, and the build linked public/model twice; public/plugin's gob.Register then ran twice under one name and panicked at init, before main. Reverting the rename traded the brand for a working binary. Rebranding the plugin alongside it needs no such trade: the agents fork is github.com/hanzoteam/agents/v2 against our public module, so no module named mattermost/mattermost is in the graph at all. Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and it is ours.
99 lines
3.8 KiB
Go
99 lines
3.8 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package api4
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/hanzoteam/server/server/public/model"
|
|
)
|
|
|
|
func handlerForGzip(t *testing.T) func(*Context, http.ResponseWriter, *http.Request) {
|
|
return func(_ *Context, w http.ResponseWriter, _ *http.Request) {
|
|
// gziphandler default requires body size greater than 1400 bytes
|
|
var body [1400]byte
|
|
_, err := w.Write(body[:])
|
|
require.NoError(t, err)
|
|
}
|
|
}
|
|
|
|
func testAPIHandlerGzipMode(t *testing.T, name string, h http.Handler, token string) {
|
|
t.Run("Handler: "+name+" No Accept-Encoding", func(t *testing.T) {
|
|
resp := httptest.NewRecorder()
|
|
req := httptest.NewRequest("GET", "/v1/workspace/test", nil)
|
|
req.Header.Set(model.HeaderAuth, "Bearer "+token)
|
|
h.ServeHTTP(resp, req)
|
|
assert.Equal(t, http.StatusOK, resp.Code)
|
|
assert.Equal(t, "", resp.Header().Get("Content-Encoding"))
|
|
})
|
|
|
|
t.Run("Handler: "+name+" With Accept-Encoding", func(t *testing.T) {
|
|
resp := httptest.NewRecorder()
|
|
req := httptest.NewRequest("GET", "/v1/workspace/test", nil)
|
|
req.Header.Set("Accept-Encoding", "gzip")
|
|
req.Header.Set(model.HeaderAuth, "Bearer "+token)
|
|
|
|
h.ServeHTTP(resp, req)
|
|
assert.Equal(t, http.StatusOK, resp.Code)
|
|
assert.Equal(t, "gzip", resp.Header().Get("Content-Encoding"))
|
|
})
|
|
}
|
|
|
|
func testAPIHandlerNoGzipMode(t *testing.T, name string, h http.Handler, token string) {
|
|
t.Run("Handler: "+name+" No Accept-Encoding", func(t *testing.T) {
|
|
resp := httptest.NewRecorder()
|
|
req := httptest.NewRequest("GET", "/v1/workspace/test", nil)
|
|
req.Header.Set(model.HeaderAuth, "Bearer "+token)
|
|
|
|
h.ServeHTTP(resp, req)
|
|
assert.Equal(t, http.StatusOK, resp.Code)
|
|
assert.Equal(t, "", resp.Header().Get("Content-Encoding"))
|
|
})
|
|
|
|
t.Run("Handler: "+name+" With Accept-Encoding", func(t *testing.T) {
|
|
resp := httptest.NewRecorder()
|
|
req := httptest.NewRequest("GET", "/v1/workspace/test", nil)
|
|
req.Header.Set("Accept-Encoding", "gzip")
|
|
req.Header.Set(model.HeaderAuth, "Bearer "+token)
|
|
|
|
h.ServeHTTP(resp, req)
|
|
assert.Equal(t, http.StatusOK, resp.Code)
|
|
assert.Equal(t, "", resp.Header().Get("Content-Encoding"))
|
|
})
|
|
}
|
|
|
|
func TestAPIHandlersWithGzip(t *testing.T) {
|
|
mainHelper.Parallel(t)
|
|
th := Setup(t)
|
|
|
|
api, err := Init(th.Server)
|
|
require.NoError(t, err)
|
|
session, _ := th.App.GetSession(th.Client.AuthToken)
|
|
|
|
t.Run("with WebserverMode == \"gzip\"", func(t *testing.T) {
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.WebserverMode = "gzip" })
|
|
|
|
testAPIHandlerGzipMode(t, "ApiHandler", api.APIHandler(handlerForGzip(t)), "")
|
|
testAPIHandlerGzipMode(t, "ApiSessionRequired", api.APISessionRequired(handlerForGzip(t)), session.Token)
|
|
testAPIHandlerGzipMode(t, "ApiSessionRequiredMfa", api.APISessionRequiredMfa(handlerForGzip(t)), session.Token)
|
|
testAPIHandlerGzipMode(t, "ApiHandlerTrustRequester", api.APIHandlerTrustRequester(handlerForGzip(t)), "")
|
|
testAPIHandlerGzipMode(t, "ApiSessionRequiredTrustRequester", api.APISessionRequiredTrustRequester(handlerForGzip(t)), session.Token)
|
|
})
|
|
|
|
t.Run("with WebserverMode == \"nogzip\"", func(t *testing.T) {
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.WebserverMode = "nogzip" })
|
|
|
|
testAPIHandlerNoGzipMode(t, "ApiHandler", api.APIHandler(handlerForGzip(t)), "")
|
|
testAPIHandlerNoGzipMode(t, "ApiSessionRequired", api.APISessionRequired(handlerForGzip(t)), session.Token)
|
|
testAPIHandlerNoGzipMode(t, "ApiSessionRequiredMfa", api.APISessionRequiredMfa(handlerForGzip(t)), session.Token)
|
|
testAPIHandlerNoGzipMode(t, "ApiHandlerTrustRequester", api.APIHandlerTrustRequester(handlerForGzip(t)), "")
|
|
testAPIHandlerNoGzipMode(t, "ApiSessionRequiredTrustRequester", api.APISessionRequiredTrustRequester(handlerForGzip(t)), session.Token)
|
|
})
|
|
}
|