aboutsummaryrefslogtreecommitdiff
path: root/clientapi
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-03-17 12:09:45 +0100
committerGitHub <noreply@github.com>2023-03-17 11:09:45 +0000
commit5579121c6f27105342a2aea05cf9a3119d73cecb (patch)
tree1d8b7bec90079b6f693585d306c19019ea426870 /clientapi
parentd88f71ab71a60348518f7fa6735ac9f0bfb472c3 (diff)
Preparations for removing `BaseDendrite` (#3016)
Preparations to actually remove/replace `BaseDendrite`. Quite a few changes: - SyncAPI accepts an `fulltext.Indexer` interface (fulltext is removed from `BaseDendrite`) - Caches are removed from `BaseDendrite` - Introduces a `Router` struct (likely to change) - also fixes #2903 - Introduces a `sqlutil.ConnectionManager`, which should remove `base.DatabaseConnection` later on - probably more
Diffstat (limited to 'clientapi')
-rw-r--r--clientapi/admin_test.go19
-rw-r--r--clientapi/routing/joinroom_test.go4
-rw-r--r--clientapi/routing/login_test.go6
-rw-r--r--clientapi/routing/register_test.go11
-rw-r--r--clientapi/routing/routing.go8
5 files changed, 29 insertions, 19 deletions
diff --git a/clientapi/admin_test.go b/clientapi/admin_test.go
index 300d3a88..46e2d303 100644
--- a/clientapi/admin_test.go
+++ b/clientapi/admin_test.go
@@ -8,6 +8,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/federationapi"
+ "github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/roomserver"
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config"
@@ -37,7 +38,8 @@ func TestAdminResetPassword(t *testing.T) {
SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"},
})
- rsAPI := roomserver.NewInternalAPI(base)
+ caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.DisableMetrics)
+ rsAPI := roomserver.NewInternalAPI(base, caches)
// Needed for changing the password/login
userAPI := userapi.NewInternalAPI(base, rsAPI, nil)
// We mostly need the userAPI for this test, so nil for other APIs/caches etc.
@@ -71,7 +73,7 @@ func TestAdminResetPassword(t *testing.T) {
"password": password,
}))
rec := httptest.NewRecorder()
- base.PublicClientAPIMux.ServeHTTP(rec, req)
+ base.Routers.Client.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("failed to login: %s", rec.Body.String())
}
@@ -124,7 +126,7 @@ func TestAdminResetPassword(t *testing.T) {
}
rec := httptest.NewRecorder()
- base.DendriteAdminMux.ServeHTTP(rec, req)
+ base.Routers.DendriteAdmin.ServeHTTP(rec, req)
t.Logf("%s", rec.Body.String())
if tc.wantOK && rec.Code != http.StatusOK {
t.Fatalf("expected http status %d, got %d: %s", http.StatusOK, rec.Code, rec.Body.String())
@@ -148,15 +150,16 @@ func TestPurgeRoom(t *testing.T) {
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
base, baseClose := testrig.CreateBaseDendrite(t, dbType)
+ caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.DisableMetrics)
defer baseClose()
fedClient := base.CreateFederationClient()
- rsAPI := roomserver.NewInternalAPI(base)
+ rsAPI := roomserver.NewInternalAPI(base, caches)
userAPI := userapi.NewInternalAPI(base, rsAPI, nil)
// this starts the JetStream consumers
- syncapi.AddPublicRoutes(base, userAPI, rsAPI)
- federationapi.NewInternalAPI(base, fedClient, rsAPI, base.Caches, nil, true)
+ syncapi.AddPublicRoutes(base, userAPI, rsAPI, caches)
+ federationapi.NewInternalAPI(base, fedClient, rsAPI, caches, nil, true)
rsAPI.SetFederationAPI(nil, nil)
// Create the room
@@ -193,7 +196,7 @@ func TestPurgeRoom(t *testing.T) {
"password": password,
}))
rec := httptest.NewRecorder()
- base.PublicClientAPIMux.ServeHTTP(rec, req)
+ base.Routers.Client.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("failed to login: %s", rec.Body.String())
}
@@ -218,7 +221,7 @@ func TestPurgeRoom(t *testing.T) {
req.Header.Set("Authorization", "Bearer "+accessTokens[aliceAdmin])
rec := httptest.NewRecorder()
- base.DendriteAdminMux.ServeHTTP(rec, req)
+ base.Routers.DendriteAdmin.ServeHTTP(rec, req)
t.Logf("%s", rec.Body.String())
if tc.wantOK && rec.Code != http.StatusOK {
t.Fatalf("expected http status %d, got %d: %s", http.StatusOK, rec.Code, rec.Body.String())
diff --git a/clientapi/routing/joinroom_test.go b/clientapi/routing/joinroom_test.go
index 1450ef4b..de8f9538 100644
--- a/clientapi/routing/joinroom_test.go
+++ b/clientapi/routing/joinroom_test.go
@@ -7,6 +7,7 @@ import (
"testing"
"time"
+ "github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/dendrite/appservice"
@@ -27,7 +28,8 @@ func TestJoinRoomByIDOrAlias(t *testing.T) {
base, baseClose := testrig.CreateBaseDendrite(t, dbType)
defer baseClose()
- rsAPI := roomserver.NewInternalAPI(base)
+ caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.DisableMetrics)
+ rsAPI := roomserver.NewInternalAPI(base, caches)
userAPI := userapi.NewInternalAPI(base, rsAPI, nil)
asAPI := appservice.NewInternalAPI(base, userAPI, rsAPI)
rsAPI.SetFederationAPI(nil, nil) // creates the rs.Inputer etc
diff --git a/clientapi/routing/login_test.go b/clientapi/routing/login_test.go
index b72db9d8..fd3d8cba 100644
--- a/clientapi/routing/login_test.go
+++ b/clientapi/routing/login_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
+ "github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/roomserver"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib"
@@ -36,7 +37,8 @@ func TestLogin(t *testing.T) {
SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"},
})
- rsAPI := roomserver.NewInternalAPI(base)
+ caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.DisableMetrics)
+ rsAPI := roomserver.NewInternalAPI(base, caches)
// Needed for /login
userAPI := userapi.NewInternalAPI(base, rsAPI, nil)
@@ -114,7 +116,7 @@ func TestLogin(t *testing.T) {
"password": password,
}))
rec := httptest.NewRecorder()
- base.PublicClientAPIMux.ServeHTTP(rec, req)
+ base.Routers.Client.ServeHTTP(rec, req)
if tc.wantOK && rec.Code != http.StatusOK {
t.Fatalf("failed to login: %s", rec.Body.String())
}
diff --git a/clientapi/routing/register_test.go b/clientapi/routing/register_test.go
index 651e3d3d..c06b0ae1 100644
--- a/clientapi/routing/register_test.go
+++ b/clientapi/routing/register_test.go
@@ -30,6 +30,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/internal"
+ "github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/roomserver"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/test"
@@ -407,7 +408,8 @@ func Test_register(t *testing.T) {
base, baseClose := testrig.CreateBaseDendrite(t, dbType)
defer baseClose()
- rsAPI := roomserver.NewInternalAPI(base)
+ caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.DisableMetrics)
+ rsAPI := roomserver.NewInternalAPI(base, caches)
userAPI := userapi.NewInternalAPI(base, rsAPI, nil)
for _, tc := range testCases {
@@ -578,7 +580,8 @@ func TestRegisterUserWithDisplayName(t *testing.T) {
defer baseClose()
base.Cfg.Global.ServerName = "server"
- rsAPI := roomserver.NewInternalAPI(base)
+ caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.DisableMetrics)
+ rsAPI := roomserver.NewInternalAPI(base, caches)
userAPI := userapi.NewInternalAPI(base, rsAPI, nil)
deviceName, deviceID := "deviceName", "deviceID"
expectedDisplayName := "DisplayName"
@@ -616,8 +619,8 @@ func TestRegisterAdminUsingSharedSecret(t *testing.T) {
base.Cfg.Global.ServerName = "server"
sharedSecret := "dendritetest"
base.Cfg.ClientAPI.RegistrationSharedSecret = sharedSecret
-
- rsAPI := roomserver.NewInternalAPI(base)
+ caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.DisableMetrics)
+ rsAPI := roomserver.NewInternalAPI(base, caches)
userAPI := userapi.NewInternalAPI(base, rsAPI, nil)
expectedDisplayName := "rabbit"
diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go
index 028d02e9..4ef2ac92 100644
--- a/clientapi/routing/routing.go
+++ b/clientapi/routing/routing.go
@@ -63,10 +63,10 @@ func Setup(
extRoomsProvider api.ExtraPublicRoomsProvider,
mscCfg *config.MSCs, natsClient *nats.Conn,
) {
- publicAPIMux := base.PublicClientAPIMux
- wkMux := base.PublicWellKnownAPIMux
- synapseAdminRouter := base.SynapseAdminMux
- dendriteAdminRouter := base.DendriteAdminMux
+ publicAPIMux := base.Routers.Client
+ wkMux := base.Routers.WellKnown
+ synapseAdminRouter := base.Routers.SynapseAdmin
+ dendriteAdminRouter := base.Routers.DendriteAdmin
if base.EnableMetrics {
prometheus.MustRegister(amtRegUsers, sendEventDuration)