aboutsummaryrefslogtreecommitdiff
path: root/clientapi
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-03-22 09:21:32 +0100
committerGitHub <noreply@github.com>2023-03-22 09:21:32 +0100
commit5e85a00cb36c3d343cd5b6f6a18435989724a135 (patch)
treeb22c34dd0a6cdc04025b90086843f9084a876412 /clientapi
parentec6879e5ae2919c903707475ce8d72244b2a6847 (diff)
Remove `BaseDendrite` (#3023)
Removes `BaseDendrite` to, hopefully, make testing and composing of components easier in the future.
Diffstat (limited to 'clientapi')
-rw-r--r--clientapi/admin_test.go50
-rw-r--r--clientapi/clientapi.go29
-rw-r--r--clientapi/routing/auth_fallback_test.go46
-rw-r--r--clientapi/routing/joinroom_test.go20
-rw-r--r--clientapi/routing/login_test.go25
-rw-r--r--clientapi/routing/register_test.go74
-rw-r--r--clientapi/routing/routing.go23
7 files changed, 149 insertions, 118 deletions
diff --git a/clientapi/admin_test.go b/clientapi/admin_test.go
index 46e2d303..4d2bf67b 100644
--- a/clientapi/admin_test.go
+++ b/clientapi/admin_test.go
@@ -5,13 +5,17 @@ import (
"net/http"
"net/http/httptest"
"testing"
+ "time"
"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/internal/httputil"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver"
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config"
+ "github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/dendrite/syncapi"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
@@ -30,20 +34,22 @@ func TestAdminResetPassword(t *testing.T) {
ctx := context.Background()
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
- base, baseClose := testrig.CreateBaseDendrite(t, dbType)
- defer baseClose()
-
+ cfg, processCtx, close := testrig.CreateConfig(t, dbType)
+ defer close()
+ natsInstance := jetstream.NATSInstance{}
// add a vhost
- base.Cfg.Global.VirtualHosts = append(base.Cfg.Global.VirtualHosts, &config.VirtualHost{
+ cfg.Global.VirtualHosts = append(cfg.Global.VirtualHosts, &config.VirtualHost{
SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"},
})
- caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.DisableMetrics)
- rsAPI := roomserver.NewInternalAPI(base, caches)
+ routers := httputil.NewRouters()
+ cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
+ caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics)
+ rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics)
// Needed for changing the password/login
- userAPI := userapi.NewInternalAPI(base, rsAPI, nil)
+ userAPI := userapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, rsAPI, nil)
// We mostly need the userAPI for this test, so nil for other APIs/caches etc.
- AddPublicRoutes(base, nil, rsAPI, nil, nil, nil, userAPI, nil, nil)
+ AddPublicRoutes(processCtx, routers, cfg, &natsInstance, nil, rsAPI, nil, nil, nil, userAPI, nil, nil, caching.DisableMetrics)
// Create the users in the userapi and login
accessTokens := map[*test.User]string{
@@ -73,7 +79,7 @@ func TestAdminResetPassword(t *testing.T) {
"password": password,
}))
rec := httptest.NewRecorder()
- base.Routers.Client.ServeHTTP(rec, req)
+ routers.Client.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("failed to login: %s", rec.Body.String())
}
@@ -126,7 +132,7 @@ func TestAdminResetPassword(t *testing.T) {
}
rec := httptest.NewRecorder()
- base.Routers.DendriteAdmin.ServeHTTP(rec, req)
+ 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())
@@ -149,17 +155,19 @@ func TestPurgeRoom(t *testing.T) {
ctx := context.Background()
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()
+ cfg, processCtx, close := testrig.CreateConfig(t, dbType)
+ caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics)
+ natsInstance := jetstream.NATSInstance{}
+ defer close()
- fedClient := base.CreateFederationClient()
- rsAPI := roomserver.NewInternalAPI(base, caches)
- userAPI := userapi.NewInternalAPI(base, rsAPI, nil)
+ routers := httputil.NewRouters()
+ cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
+ rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics)
+ userAPI := userapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, rsAPI, nil)
// this starts the JetStream consumers
- syncapi.AddPublicRoutes(base, userAPI, rsAPI, caches)
- federationapi.NewInternalAPI(base, fedClient, rsAPI, caches, nil, true)
+ syncapi.AddPublicRoutes(processCtx, routers, cfg, cm, &natsInstance, userAPI, rsAPI, caches, caching.DisableMetrics)
+ federationapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, nil, rsAPI, caches, nil, true)
rsAPI.SetFederationAPI(nil, nil)
// Create the room
@@ -168,7 +176,7 @@ func TestPurgeRoom(t *testing.T) {
}
// We mostly need the rsAPI for this test, so nil for other APIs/caches etc.
- AddPublicRoutes(base, nil, rsAPI, nil, nil, nil, userAPI, nil, nil)
+ AddPublicRoutes(processCtx, routers, cfg, &natsInstance, nil, rsAPI, nil, nil, nil, userAPI, nil, nil, caching.DisableMetrics)
// Create the users in the userapi and login
accessTokens := map[*test.User]string{
@@ -196,7 +204,7 @@ func TestPurgeRoom(t *testing.T) {
"password": password,
}))
rec := httptest.NewRecorder()
- base.Routers.Client.ServeHTTP(rec, req)
+ routers.Client.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("failed to login: %s", rec.Body.String())
}
@@ -221,7 +229,7 @@ func TestPurgeRoom(t *testing.T) {
req.Header.Set("Authorization", "Bearer "+accessTokens[aliceAdmin])
rec := httptest.NewRecorder()
- base.Routers.DendriteAdmin.ServeHTTP(rec, req)
+ 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/clientapi.go b/clientapi/clientapi.go
index e9985d43..d35f1d4d 100644
--- a/clientapi/clientapi.go
+++ b/clientapi/clientapi.go
@@ -15,6 +15,9 @@
package clientapi
import (
+ "github.com/matrix-org/dendrite/internal/httputil"
+ "github.com/matrix-org/dendrite/setup/config"
+ "github.com/matrix-org/dendrite/setup/process"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
@@ -25,13 +28,15 @@ import (
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
"github.com/matrix-org/dendrite/internal/transactions"
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
- "github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/jetstream"
)
// AddPublicRoutes sets up and registers HTTP handlers for the ClientAPI component.
func AddPublicRoutes(
- base *base.BaseDendrite,
+ processContext *process.ProcessContext,
+ routers httputil.Routers,
+ cfg *config.Dendrite,
+ natsInstance *jetstream.NATSInstance,
federation *gomatrixserverlib.FederationClient,
rsAPI roomserverAPI.ClientRoomserverAPI,
asAPI appserviceAPI.AppServiceInternalAPI,
@@ -39,27 +44,25 @@ func AddPublicRoutes(
fsAPI federationAPI.ClientFederationAPI,
userAPI userapi.ClientUserAPI,
userDirectoryProvider userapi.QuerySearchProfilesAPI,
- extRoomsProvider api.ExtraPublicRoomsProvider,
+ extRoomsProvider api.ExtraPublicRoomsProvider, enableMetrics bool,
) {
- cfg := &base.Cfg.ClientAPI
- mscCfg := &base.Cfg.MSCs
- js, natsClient := base.NATS.Prepare(base.ProcessContext, &cfg.Matrix.JetStream)
+ js, natsClient := natsInstance.Prepare(processContext, &cfg.Global.JetStream)
syncProducer := &producers.SyncAPIProducer{
JetStream: js,
- TopicReceiptEvent: cfg.Matrix.JetStream.Prefixed(jetstream.OutputReceiptEvent),
- TopicSendToDeviceEvent: cfg.Matrix.JetStream.Prefixed(jetstream.OutputSendToDeviceEvent),
- TopicTypingEvent: cfg.Matrix.JetStream.Prefixed(jetstream.OutputTypingEvent),
- TopicPresenceEvent: cfg.Matrix.JetStream.Prefixed(jetstream.OutputPresenceEvent),
+ TopicReceiptEvent: cfg.Global.JetStream.Prefixed(jetstream.OutputReceiptEvent),
+ TopicSendToDeviceEvent: cfg.Global.JetStream.Prefixed(jetstream.OutputSendToDeviceEvent),
+ TopicTypingEvent: cfg.Global.JetStream.Prefixed(jetstream.OutputTypingEvent),
+ TopicPresenceEvent: cfg.Global.JetStream.Prefixed(jetstream.OutputPresenceEvent),
UserAPI: userAPI,
- ServerName: cfg.Matrix.ServerName,
+ ServerName: cfg.Global.ServerName,
}
routing.Setup(
- base,
+ routers,
cfg, rsAPI, asAPI,
userAPI, userDirectoryProvider, federation,
syncProducer, transactionsCache, fsAPI,
- extRoomsProvider, mscCfg, natsClient,
+ extRoomsProvider, natsClient, enableMetrics,
)
}
diff --git a/clientapi/routing/auth_fallback_test.go b/clientapi/routing/auth_fallback_test.go
index 534581bd..afeca051 100644
--- a/clientapi/routing/auth_fallback_test.go
+++ b/clientapi/routing/auth_fallback_test.go
@@ -10,30 +10,28 @@ import (
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/setup/config"
- "github.com/matrix-org/dendrite/test/testrig"
)
func Test_AuthFallback(t *testing.T) {
- base, _, _ := testrig.Base(nil)
- defer base.Close()
-
+ cfg := config.Dendrite{}
+ cfg.Defaults(config.DefaultOpts{Generate: true, SingleDatabase: true})
for _, useHCaptcha := range []bool{false, true} {
for _, recaptchaEnabled := range []bool{false, true} {
for _, wantErr := range []bool{false, true} {
t.Run(fmt.Sprintf("useHCaptcha(%v) - recaptchaEnabled(%v) - wantErr(%v)", useHCaptcha, recaptchaEnabled, wantErr), func(t *testing.T) {
// Set the defaults for each test
- base.Cfg.ClientAPI.Defaults(config.DefaultOpts{Generate: true, SingleDatabase: true})
- base.Cfg.ClientAPI.RecaptchaEnabled = recaptchaEnabled
- base.Cfg.ClientAPI.RecaptchaPublicKey = "pub"
- base.Cfg.ClientAPI.RecaptchaPrivateKey = "priv"
+ cfg.ClientAPI.Defaults(config.DefaultOpts{Generate: true, SingleDatabase: true})
+ cfg.ClientAPI.RecaptchaEnabled = recaptchaEnabled
+ cfg.ClientAPI.RecaptchaPublicKey = "pub"
+ cfg.ClientAPI.RecaptchaPrivateKey = "priv"
if useHCaptcha {
- base.Cfg.ClientAPI.RecaptchaSiteVerifyAPI = "https://hcaptcha.com/siteverify"
- base.Cfg.ClientAPI.RecaptchaApiJsUrl = "https://js.hcaptcha.com/1/api.js"
- base.Cfg.ClientAPI.RecaptchaFormField = "h-captcha-response"
- base.Cfg.ClientAPI.RecaptchaSitekeyClass = "h-captcha"
+ cfg.ClientAPI.RecaptchaSiteVerifyAPI = "https://hcaptcha.com/siteverify"
+ cfg.ClientAPI.RecaptchaApiJsUrl = "https://js.hcaptcha.com/1/api.js"
+ cfg.ClientAPI.RecaptchaFormField = "h-captcha-response"
+ cfg.ClientAPI.RecaptchaSitekeyClass = "h-captcha"
}
cfgErrs := &config.ConfigErrors{}
- base.Cfg.ClientAPI.Verify(cfgErrs)
+ cfg.ClientAPI.Verify(cfgErrs)
if len(*cfgErrs) > 0 {
t.Fatalf("(hCaptcha=%v) unexpected config errors: %s", useHCaptcha, cfgErrs.Error())
}
@@ -41,7 +39,7 @@ func Test_AuthFallback(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/?session=1337", nil)
rec := httptest.NewRecorder()
- AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &base.Cfg.ClientAPI)
+ AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &cfg.ClientAPI)
if !recaptchaEnabled {
if rec.Code != http.StatusBadRequest {
t.Fatalf("unexpected response code: %d, want %d", rec.Code, http.StatusBadRequest)
@@ -50,8 +48,8 @@ func Test_AuthFallback(t *testing.T) {
t.Fatalf("unexpected response body: %s", rec.Body.String())
}
} else {
- if !strings.Contains(rec.Body.String(), base.Cfg.ClientAPI.RecaptchaSitekeyClass) {
- t.Fatalf("body does not contain %s: %s", base.Cfg.ClientAPI.RecaptchaSitekeyClass, rec.Body.String())
+ if !strings.Contains(rec.Body.String(), cfg.ClientAPI.RecaptchaSitekeyClass) {
+ t.Fatalf("body does not contain %s: %s", cfg.ClientAPI.RecaptchaSitekeyClass, rec.Body.String())
}
}
@@ -64,14 +62,14 @@ func Test_AuthFallback(t *testing.T) {
}))
defer srv.Close() // nolint: errcheck
- base.Cfg.ClientAPI.RecaptchaSiteVerifyAPI = srv.URL
+ cfg.ClientAPI.RecaptchaSiteVerifyAPI = srv.URL
// check the result after sending the captcha
req = httptest.NewRequest(http.MethodPost, "/?session=1337", nil)
req.Form = url.Values{}
- req.Form.Add(base.Cfg.ClientAPI.RecaptchaFormField, "someRandomValue")
+ req.Form.Add(cfg.ClientAPI.RecaptchaFormField, "someRandomValue")
rec = httptest.NewRecorder()
- AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &base.Cfg.ClientAPI)
+ AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &cfg.ClientAPI)
if recaptchaEnabled {
if !wantErr {
if rec.Code != http.StatusOK {
@@ -105,7 +103,7 @@ func Test_AuthFallback(t *testing.T) {
t.Run("unknown fallbacks are handled correctly", func(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "/?session=1337", nil)
rec := httptest.NewRecorder()
- AuthFallback(rec, req, "DoesNotExist", &base.Cfg.ClientAPI)
+ AuthFallback(rec, req, "DoesNotExist", &cfg.ClientAPI)
if rec.Code != http.StatusNotImplemented {
t.Fatalf("unexpected http status: %d, want %d", rec.Code, http.StatusNotImplemented)
}
@@ -114,7 +112,7 @@ func Test_AuthFallback(t *testing.T) {
t.Run("unknown methods are handled correctly", func(t *testing.T) {
req := httptest.NewRequest(http.MethodDelete, "/?session=1337", nil)
rec := httptest.NewRecorder()
- AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &base.Cfg.ClientAPI)
+ AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &cfg.ClientAPI)
if rec.Code != http.StatusMethodNotAllowed {
t.Fatalf("unexpected http status: %d, want %d", rec.Code, http.StatusMethodNotAllowed)
}
@@ -123,7 +121,7 @@ func Test_AuthFallback(t *testing.T) {
t.Run("missing session parameter is handled correctly", func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
- AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &base.Cfg.ClientAPI)
+ AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &cfg.ClientAPI)
if rec.Code != http.StatusBadRequest {
t.Fatalf("unexpected http status: %d, want %d", rec.Code, http.StatusBadRequest)
}
@@ -132,7 +130,7 @@ func Test_AuthFallback(t *testing.T) {
t.Run("missing session parameter is handled correctly", func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
- AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &base.Cfg.ClientAPI)
+ AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &cfg.ClientAPI)
if rec.Code != http.StatusBadRequest {
t.Fatalf("unexpected http status: %d, want %d", rec.Code, http.StatusBadRequest)
}
@@ -141,7 +139,7 @@ func Test_AuthFallback(t *testing.T) {
t.Run("missing 'response' is handled correctly", func(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "/?session=1337", nil)
rec := httptest.NewRecorder()
- AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &base.Cfg.ClientAPI)
+ AuthFallback(rec, req, authtypes.LoginTypeRecaptcha, &cfg.ClientAPI)
if rec.Code != http.StatusBadRequest {
t.Fatalf("unexpected http status: %d, want %d", rec.Code, http.StatusBadRequest)
}
diff --git a/clientapi/routing/joinroom_test.go b/clientapi/routing/joinroom_test.go
index de8f9538..fd58ff5d 100644
--- a/clientapi/routing/joinroom_test.go
+++ b/clientapi/routing/joinroom_test.go
@@ -8,6 +8,8 @@ import (
"time"
"github.com/matrix-org/dendrite/internal/caching"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
+ "github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/dendrite/appservice"
@@ -25,13 +27,15 @@ func TestJoinRoomByIDOrAlias(t *testing.T) {
ctx := context.Background()
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
- base, baseClose := testrig.CreateBaseDendrite(t, dbType)
- defer baseClose()
+ cfg, processCtx, close := testrig.CreateConfig(t, dbType)
+ defer close()
- 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)
+ cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
+ caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics)
+ natsInstance := jetstream.NATSInstance{}
+ rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics)
+ userAPI := userapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, rsAPI, nil)
+ asAPI := appservice.NewInternalAPI(processCtx, cfg, &natsInstance, userAPI, rsAPI)
rsAPI.SetFederationAPI(nil, nil) // creates the rs.Inputer etc
// Create the users in the userapi
@@ -63,7 +67,7 @@ func TestJoinRoomByIDOrAlias(t *testing.T) {
RoomAliasName: "alias",
Invite: []string{bob.ID},
GuestCanJoin: false,
- }, aliceDev, &base.Cfg.ClientAPI, userAPI, rsAPI, asAPI, time.Now())
+ }, aliceDev, &cfg.ClientAPI, userAPI, rsAPI, asAPI, time.Now())
crResp, ok := resp.JSON.(createRoomResponse)
if !ok {
t.Fatalf("response is not a createRoomResponse: %+v", resp)
@@ -78,7 +82,7 @@ func TestJoinRoomByIDOrAlias(t *testing.T) {
Preset: presetPublicChat,
Invite: []string{charlie.ID},
GuestCanJoin: true,
- }, aliceDev, &base.Cfg.ClientAPI, userAPI, rsAPI, asAPI, time.Now())
+ }, aliceDev, &cfg.ClientAPI, userAPI, rsAPI, asAPI, time.Now())
crRespWithGuestAccess, ok := resp.JSON.(createRoomResponse)
if !ok {
t.Fatalf("response is not a createRoomResponse: %+v", resp)
diff --git a/clientapi/routing/login_test.go b/clientapi/routing/login_test.go
index fd3d8cba..b2773076 100644
--- a/clientapi/routing/login_test.go
+++ b/clientapi/routing/login_test.go
@@ -7,11 +7,15 @@ import (
"net/http/httptest"
"strings"
"testing"
+ "time"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/internal/caching"
+ "github.com/matrix-org/dendrite/internal/httputil"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver"
"github.com/matrix-org/dendrite/setup/config"
+ "github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
@@ -29,21 +33,24 @@ func TestLogin(t *testing.T) {
ctx := context.Background()
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
- base, baseClose := testrig.CreateBaseDendrite(t, dbType)
- defer baseClose()
- base.Cfg.ClientAPI.RateLimiting.Enabled = false
+ cfg, processCtx, close := testrig.CreateConfig(t, dbType)
+ defer close()
+ cfg.ClientAPI.RateLimiting.Enabled = false
+ natsInstance := jetstream.NATSInstance{}
// add a vhost
- base.Cfg.Global.VirtualHosts = append(base.Cfg.Global.VirtualHosts, &config.VirtualHost{
+ cfg.Global.VirtualHosts = append(cfg.Global.VirtualHosts, &config.VirtualHost{
SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"},
})
- caches := caching.NewRistrettoCache(base.Cfg.Global.Cache.EstimatedMaxSize, base.Cfg.Global.Cache.MaxAge, caching.DisableMetrics)
- rsAPI := roomserver.NewInternalAPI(base, caches)
+ cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
+ routers := httputil.NewRouters()
+ caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics)
+ rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics)
// Needed for /login
- userAPI := userapi.NewInternalAPI(base, rsAPI, nil)
+ userAPI := userapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, rsAPI, nil)
// We mostly need the userAPI for this test, so nil for other APIs/caches etc.
- Setup(base, &base.Cfg.ClientAPI, nil, nil, userAPI, nil, nil, nil, nil, nil, nil, &base.Cfg.MSCs, nil)
+ Setup(routers, cfg, nil, nil, userAPI, nil, nil, nil, nil, nil, nil, nil, caching.DisableMetrics)
// Create password
password := util.RandomString(8)
@@ -116,7 +123,7 @@ func TestLogin(t *testing.T) {
"password": password,
}))
rec := httptest.NewRecorder()
- base.Routers.Client.ServeHTTP(rec, req)
+ 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 c06b0ae1..46cd8b2b 100644
--- a/clientapi/routing/register_test.go
+++ b/clientapi/routing/register_test.go
@@ -31,8 +31,10 @@ import (
"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/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver"
"github.com/matrix-org/dendrite/setup/config"
+ "github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/dendrite/test"
"github.com/matrix-org/dendrite/test/testrig"
"github.com/matrix-org/dendrite/userapi"
@@ -405,12 +407,15 @@ func Test_register(t *testing.T) {
}
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
- base, baseClose := testrig.CreateBaseDendrite(t, dbType)
- defer baseClose()
+ cfg, processCtx, close := testrig.CreateConfig(t, dbType)
+ defer close()
- 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)
+ caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics)
+ natsInstance := jetstream.NATSInstance{}
+
+ cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
+ rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics)
+ userAPI := userapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, rsAPI, nil)
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
@@ -432,16 +437,16 @@ func Test_register(t *testing.T) {
}
}))
defer srv.Close()
- base.Cfg.ClientAPI.RecaptchaSiteVerifyAPI = srv.URL
+ cfg.ClientAPI.RecaptchaSiteVerifyAPI = srv.URL
}
- if err := base.Cfg.Derive(); err != nil {
+ if err := cfg.Derive(); err != nil {
t.Fatalf("failed to derive config: %s", err)
}
- base.Cfg.ClientAPI.RecaptchaEnabled = tc.enableRecaptcha
- base.Cfg.ClientAPI.RegistrationDisabled = tc.registrationDisabled
- base.Cfg.ClientAPI.GuestsDisabled = tc.guestsDisabled
+ cfg.ClientAPI.RecaptchaEnabled = tc.enableRecaptcha
+ cfg.ClientAPI.RegistrationDisabled = tc.registrationDisabled
+ cfg.ClientAPI.GuestsDisabled = tc.guestsDisabled
if tc.kind == "" {
tc.kind = "user"
@@ -469,15 +474,15 @@ func Test_register(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("/?kind=%s", tc.kind), body)
- resp := Register(req, userAPI, &base.Cfg.ClientAPI)
+ resp := Register(req, userAPI, &cfg.ClientAPI)
t.Logf("Resp: %+v", resp)
// The first request should return a userInteractiveResponse
switch r := resp.JSON.(type) {
case userInteractiveResponse:
// Check that the flows are the ones we configured
- if !reflect.DeepEqual(r.Flows, base.Cfg.Derived.Registration.Flows) {
- t.Fatalf("unexpected registration flows: %+v, want %+v", r.Flows, base.Cfg.Derived.Registration.Flows)
+ if !reflect.DeepEqual(r.Flows, cfg.Derived.Registration.Flows) {
+ t.Fatalf("unexpected registration flows: %+v, want %+v", r.Flows, cfg.Derived.Registration.Flows)
}
case *jsonerror.MatrixError:
if !reflect.DeepEqual(tc.wantResponse, resp) {
@@ -533,7 +538,7 @@ func Test_register(t *testing.T) {
req = httptest.NewRequest(http.MethodPost, "/", body)
- resp = Register(req, userAPI, &base.Cfg.ClientAPI)
+ resp = Register(req, userAPI, &cfg.ClientAPI)
switch resp.JSON.(type) {
case *jsonerror.MatrixError:
@@ -576,17 +581,19 @@ func Test_register(t *testing.T) {
func TestRegisterUserWithDisplayName(t *testing.T) {
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
- base, baseClose := testrig.CreateBaseDendrite(t, dbType)
- defer baseClose()
- base.Cfg.Global.ServerName = "server"
-
- 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)
+ cfg, processCtx, close := testrig.CreateConfig(t, dbType)
+ defer close()
+ cfg.Global.ServerName = "server"
+
+ caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics)
+ natsInstance := jetstream.NATSInstance{}
+ cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
+ rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics)
+ userAPI := userapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, rsAPI, nil)
deviceName, deviceID := "deviceName", "deviceID"
expectedDisplayName := "DisplayName"
response := completeRegistration(
- base.Context(),
+ processCtx.Context(),
userAPI,
"user",
"server",
@@ -606,7 +613,7 @@ func TestRegisterUserWithDisplayName(t *testing.T) {
req := api.QueryProfileRequest{UserID: "@user:server"}
var res api.QueryProfileResponse
- err := userAPI.QueryProfile(base.Context(), &req, &res)
+ err := userAPI.QueryProfile(processCtx.Context(), &req, &res)
assert.NoError(t, err)
assert.Equal(t, expectedDisplayName, res.DisplayName)
})
@@ -614,14 +621,17 @@ func TestRegisterUserWithDisplayName(t *testing.T) {
func TestRegisterAdminUsingSharedSecret(t *testing.T) {
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
- base, baseClose := testrig.CreateBaseDendrite(t, dbType)
- defer baseClose()
- base.Cfg.Global.ServerName = "server"
+ cfg, processCtx, close := testrig.CreateConfig(t, dbType)
+ defer close()
+ natsInstance := jetstream.NATSInstance{}
+ cfg.Global.ServerName = "server"
sharedSecret := "dendritetest"
- base.Cfg.ClientAPI.RegistrationSharedSecret = sharedSecret
- 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)
+ cfg.ClientAPI.RegistrationSharedSecret = sharedSecret
+
+ cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
+ caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics)
+ rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics)
+ userAPI := userapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, rsAPI, nil)
expectedDisplayName := "rabbit"
jsonStr := []byte(`{"admin":true,"mac":"24dca3bba410e43fe64b9b5c28306693bf3baa9f","nonce":"759f047f312b99ff428b21d581256f8592b8976e58bc1b543972dc6147e529a79657605b52d7becd160ff5137f3de11975684319187e06901955f79e5a6c5a79","password":"wonderland","username":"alice","displayname":"rabbit"}`)
@@ -645,7 +655,7 @@ func TestRegisterAdminUsingSharedSecret(t *testing.T) {
ssrr := httptest.NewRequest(http.MethodPost, "/", body)
response := handleSharedSecretRegistration(
- &base.Cfg.ClientAPI,
+ &cfg.ClientAPI,
userAPI,
r,
ssrr,
@@ -654,7 +664,7 @@ func TestRegisterAdminUsingSharedSecret(t *testing.T) {
profilReq := api.QueryProfileRequest{UserID: "@alice:server"}
var profileRes api.QueryProfileResponse
- err = userAPI.QueryProfile(base.Context(), &profilReq, &profileRes)
+ err = userAPI.QueryProfile(processCtx.Context(), &profilReq, &profileRes)
assert.NoError(t, err)
assert.Equal(t, expectedDisplayName, profileRes.DisplayName)
})
diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go
index 4ef2ac92..6a86980d 100644
--- a/clientapi/routing/routing.go
+++ b/clientapi/routing/routing.go
@@ -21,7 +21,6 @@ import (
"sync"
"github.com/gorilla/mux"
- "github.com/matrix-org/dendrite/setup/base"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
@@ -50,8 +49,8 @@ import (
// applied:
// nolint: gocyclo
func Setup(
- base *base.BaseDendrite,
- cfg *config.ClientAPI,
+ routers httputil.Routers,
+ dendriteCfg *config.Dendrite,
rsAPI roomserverAPI.ClientRoomserverAPI,
asAPI appserviceAPI.AppServiceInternalAPI,
userAPI userapi.ClientUserAPI,
@@ -61,14 +60,16 @@ func Setup(
transactionsCache *transactions.Cache,
federationSender federationAPI.ClientFederationAPI,
extRoomsProvider api.ExtraPublicRoomsProvider,
- mscCfg *config.MSCs, natsClient *nats.Conn,
+ natsClient *nats.Conn, enableMetrics bool,
) {
- publicAPIMux := base.Routers.Client
- wkMux := base.Routers.WellKnown
- synapseAdminRouter := base.Routers.SynapseAdmin
- dendriteAdminRouter := base.Routers.DendriteAdmin
-
- if base.EnableMetrics {
+ cfg := &dendriteCfg.ClientAPI
+ mscCfg := &dendriteCfg.MSCs
+ publicAPIMux := routers.Client
+ wkMux := routers.WellKnown
+ synapseAdminRouter := routers.SynapseAdmin
+ dendriteAdminRouter := routers.DendriteAdmin
+
+ if enableMetrics {
prometheus.MustRegister(amtRegUsers, sendEventDuration)
}
@@ -656,7 +657,7 @@ func Setup(
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
v3mux.Handle("/auth/{authType}/fallback/web",
- httputil.MakeHTMLAPI("auth_fallback", base.EnableMetrics, func(w http.ResponseWriter, req *http.Request) {
+ httputil.MakeHTMLAPI("auth_fallback", enableMetrics, func(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
AuthFallback(w, req, vars["authType"], cfg)
}),