mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-13 21:02:25 +03:00
msc3861: cr fixes
This commit is contained in:
parent
8df644263c
commit
3eb4c7e1bd
6 changed files with 36 additions and 39 deletions
|
@ -1561,16 +1561,19 @@ func TestAdminCheckUsernameAvailable(t *testing.T) {
|
||||||
t.Fatalf("expected http status %d, got %d: %s", http.StatusOK, rec.Code, rec.Body.String())
|
t.Fatalf("expected http status %d, got %d: %s", http.StatusOK, rec.Code, rec.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nothing more to check, test is done.
|
||||||
if tc.wantOK {
|
if tc.wantOK {
|
||||||
b := make(map[string]bool, 1)
|
return
|
||||||
_ = json.NewDecoder(rec.Body).Decode(&b)
|
}
|
||||||
available, ok := b["available"]
|
|
||||||
if !ok {
|
b := make(map[string]bool, 1)
|
||||||
t.Fatal("'available' not found in body")
|
_ = json.NewDecoder(rec.Body).Decode(&b)
|
||||||
}
|
available, ok := b["available"]
|
||||||
if available != tc.isAvailable {
|
if !ok {
|
||||||
t.Fatalf("expected 'available' to be %t, got %t instead", tc.isAvailable, available)
|
t.Fatal("'available' not found in body")
|
||||||
}
|
}
|
||||||
|
if available != tc.isAvailable {
|
||||||
|
t.Fatalf("expected 'available' to be %t, got %t instead", tc.isAvailable, available)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2311,7 +2314,7 @@ func TestAdminRetrieveAccount(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCase {
|
for _, tc := range testCase {
|
||||||
t.Run("Retrieve existing account", func(t *testing.T) {
|
t.Run(tc.Name, func(t *testing.T) {
|
||||||
req := test.NewRequest(t, http.MethodGet, "/_synapse/admin/v2/users/"+tc.User.ID)
|
req := test.NewRequest(t, http.MethodGet, "/_synapse/admin/v2/users/"+tc.User.ID)
|
||||||
req.Header.Set("Authorization", "Bearer "+adminToken)
|
req.Header.Set("Authorization", "Bearer "+adminToken)
|
||||||
|
|
||||||
|
|
|
@ -560,26 +560,24 @@ func AdminUserDeviceRetrieveCreate(
|
||||||
}
|
}
|
||||||
|
|
||||||
userDeviceExists := false
|
userDeviceExists := false
|
||||||
{
|
var rs api.QueryDevicesResponse
|
||||||
var rs api.QueryDevicesResponse
|
if err = userAPI.QueryDevices(req.Context(), &api.QueryDevicesRequest{UserID: userID}, &rs); err != nil {
|
||||||
if err = userAPI.QueryDevices(req.Context(), &api.QueryDevicesRequest{UserID: userID}, &rs); err != nil {
|
logger.WithError(err).Error("QueryDevices")
|
||||||
logger.WithError(err).Error("QueryDevices")
|
return util.JSONResponse{
|
||||||
return util.JSONResponse{
|
Code: http.StatusInternalServerError,
|
||||||
Code: http.StatusInternalServerError,
|
JSON: spec.InternalServerError{},
|
||||||
JSON: spec.InternalServerError{},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !rs.UserExists {
|
}
|
||||||
return util.JSONResponse{
|
if !rs.UserExists {
|
||||||
Code: http.StatusNotFound,
|
return util.JSONResponse{
|
||||||
JSON: spec.NotFound("Given user ID does not exist"),
|
Code: http.StatusNotFound,
|
||||||
}
|
JSON: spec.NotFound("Given user ID does not exist"),
|
||||||
}
|
}
|
||||||
for i := range rs.Devices {
|
}
|
||||||
if d := rs.Devices[i]; d.ID == payload.DeviceID && d.UserID == userID {
|
for i := range rs.Devices {
|
||||||
userDeviceExists = true
|
if d := rs.Devices[i]; d.ID == payload.DeviceID && d.UserID == userID {
|
||||||
break
|
userDeviceExists = true
|
||||||
}
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,11 +128,11 @@ func (d *sessionsDict) deleteSession(sessionID string) {
|
||||||
func (d *sessionsDict) allowCrossSigningKeysReplacement(userID string) int64 {
|
func (d *sessionsDict) allowCrossSigningKeysReplacement(userID string) int64 {
|
||||||
d.Lock()
|
d.Lock()
|
||||||
defer d.Unlock()
|
defer d.Unlock()
|
||||||
ts := time.Now().Add(crossSigningKeysReplacementDuration).UnixMilli()
|
allowedUntilTS := time.Now().Add(crossSigningKeysReplacementDuration).UnixMilli()
|
||||||
t, ok := d.crossSigningKeysReplacement[userID]
|
t, ok := d.crossSigningKeysReplacement[userID]
|
||||||
if ok {
|
if ok {
|
||||||
t.Reset(crossSigningKeysReplacementDuration)
|
t.Reset(crossSigningKeysReplacementDuration)
|
||||||
return ts
|
return allowedUntilTS
|
||||||
}
|
}
|
||||||
d.crossSigningKeysReplacement[userID] = time.AfterFunc(
|
d.crossSigningKeysReplacement[userID] = time.AfterFunc(
|
||||||
crossSigningKeysReplacementDuration,
|
crossSigningKeysReplacementDuration,
|
||||||
|
@ -140,7 +140,7 @@ func (d *sessionsDict) allowCrossSigningKeysReplacement(userID string) int64 {
|
||||||
d.restrictCrossSigningKeysReplacement(userID)
|
d.restrictCrossSigningKeysReplacement(userID)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return ts
|
return allowedUntilTS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *sessionsDict) isCrossSigningKeysReplacementAllowed(userID string) bool {
|
func (d *sessionsDict) isCrossSigningKeysReplacementAllowed(userID string) bool {
|
||||||
|
|
|
@ -349,14 +349,10 @@ func Setup(
|
||||||
})).Methods(http.MethodPost)
|
})).Methods(http.MethodPost)
|
||||||
synapseAdminRouter.Handle("/admin/v2/users/{userID}",
|
synapseAdminRouter.Handle("/admin/v2/users/{userID}",
|
||||||
httputil.MakeServiceAdminAPI("admin_manage_user", m.AdminToken, func(r *http.Request) util.JSONResponse {
|
httputil.MakeServiceAdminAPI("admin_manage_user", m.AdminToken, func(r *http.Request) util.JSONResponse {
|
||||||
switch r.Method {
|
if r.Method == http.MethodGet {
|
||||||
case http.MethodGet:
|
|
||||||
return AdminRetrieveAccount(r, cfg, userAPI)
|
return AdminRetrieveAccount(r, cfg, userAPI)
|
||||||
case http.MethodPut:
|
|
||||||
return AdminCreateOrModifyAccount(r, userAPI, cfg)
|
|
||||||
default:
|
|
||||||
return util.JSONResponse{Code: http.StatusMethodNotAllowed, JSON: nil}
|
|
||||||
}
|
}
|
||||||
|
return AdminCreateOrModifyAccount(r, userAPI, cfg)
|
||||||
})).Methods(http.MethodPut, http.MethodGet)
|
})).Methods(http.MethodPut, http.MethodGet)
|
||||||
synapseAdminRouter.Handle("/admin/v2/users/{userID}/devices",
|
synapseAdminRouter.Handle("/admin/v2/users/{userID}/devices",
|
||||||
httputil.MakeServiceAdminAPI("admin_create_retrieve_user_devices", m.AdminToken, func(r *http.Request) util.JSONResponse {
|
httputil.MakeServiceAdminAPI("admin_create_retrieve_user_devices", m.AdminToken, func(r *http.Request) util.JSONResponse {
|
||||||
|
|
|
@ -163,7 +163,7 @@ func MakeServiceAdminAPI(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if token != serviceToken {
|
if token != serviceToken {
|
||||||
logger.Debugf("Invalid service token '%s'", token)
|
logger.Debug("Invalid service token")
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusForbidden,
|
Code: http.StatusForbidden,
|
||||||
JSON: spec.UnknownToken(token),
|
JSON: spec.UnknownToken(token),
|
||||||
|
|
|
@ -51,7 +51,7 @@ type Monolith struct {
|
||||||
ExtPublicRoomsProvider api.ExtraPublicRoomsProvider
|
ExtPublicRoomsProvider api.ExtraPublicRoomsProvider
|
||||||
ExtUserDirectoryProvider userapi.QuerySearchProfilesAPI
|
ExtUserDirectoryProvider userapi.QuerySearchProfilesAPI
|
||||||
|
|
||||||
UserVerifierProvider *UserVerifierProvider
|
UserVerifierProvider httputil.UserVerifier
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAllPublicRoutes attaches all public paths to the given router
|
// AddAllPublicRoutes attaches all public paths to the given router
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue