Skip to content

Commit 3eb4c7e

Browse files
committed
msc3861: cr fixes
1 parent 8df6442 commit 3eb4c7e

File tree

6 files changed

+36
-39
lines changed

6 files changed

+36
-39
lines changed

clientapi/admin_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,16 +1561,19 @@ func TestAdminCheckUsernameAvailable(t *testing.T) {
15611561
t.Fatalf("expected http status %d, got %d: %s", http.StatusOK, rec.Code, rec.Body.String())
15621562
}
15631563

1564+
// Nothing more to check, test is done.
15641565
if tc.wantOK {
1565-
b := make(map[string]bool, 1)
1566-
_ = json.NewDecoder(rec.Body).Decode(&b)
1567-
available, ok := b["available"]
1568-
if !ok {
1569-
t.Fatal("'available' not found in body")
1570-
}
1571-
if available != tc.isAvailable {
1572-
t.Fatalf("expected 'available' to be %t, got %t instead", tc.isAvailable, available)
1573-
}
1566+
return
1567+
}
1568+
1569+
b := make(map[string]bool, 1)
1570+
_ = json.NewDecoder(rec.Body).Decode(&b)
1571+
available, ok := b["available"]
1572+
if !ok {
1573+
t.Fatal("'available' not found in body")
1574+
}
1575+
if available != tc.isAvailable {
1576+
t.Fatalf("expected 'available' to be %t, got %t instead", tc.isAvailable, available)
15741577
}
15751578
})
15761579
}
@@ -2311,7 +2314,7 @@ func TestAdminRetrieveAccount(t *testing.T) {
23112314
}
23122315

23132316
for _, tc := range testCase {
2314-
t.Run("Retrieve existing account", func(t *testing.T) {
2317+
t.Run(tc.Name, func(t *testing.T) {
23152318
req := test.NewRequest(t, http.MethodGet, "/_synapse/admin/v2/users/"+tc.User.ID)
23162319
req.Header.Set("Authorization", "Bearer "+adminToken)
23172320

clientapi/routing/admin.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -560,26 +560,24 @@ func AdminUserDeviceRetrieveCreate(
560560
}
561561

562562
userDeviceExists := false
563-
{
564-
var rs api.QueryDevicesResponse
565-
if err = userAPI.QueryDevices(req.Context(), &api.QueryDevicesRequest{UserID: userID}, &rs); err != nil {
566-
logger.WithError(err).Error("QueryDevices")
567-
return util.JSONResponse{
568-
Code: http.StatusInternalServerError,
569-
JSON: spec.InternalServerError{},
570-
}
563+
var rs api.QueryDevicesResponse
564+
if err = userAPI.QueryDevices(req.Context(), &api.QueryDevicesRequest{UserID: userID}, &rs); err != nil {
565+
logger.WithError(err).Error("QueryDevices")
566+
return util.JSONResponse{
567+
Code: http.StatusInternalServerError,
568+
JSON: spec.InternalServerError{},
571569
}
572-
if !rs.UserExists {
573-
return util.JSONResponse{
574-
Code: http.StatusNotFound,
575-
JSON: spec.NotFound("Given user ID does not exist"),
576-
}
570+
}
571+
if !rs.UserExists {
572+
return util.JSONResponse{
573+
Code: http.StatusNotFound,
574+
JSON: spec.NotFound("Given user ID does not exist"),
577575
}
578-
for i := range rs.Devices {
579-
if d := rs.Devices[i]; d.ID == payload.DeviceID && d.UserID == userID {
580-
userDeviceExists = true
581-
break
582-
}
576+
}
577+
for i := range rs.Devices {
578+
if d := rs.Devices[i]; d.ID == payload.DeviceID && d.UserID == userID {
579+
userDeviceExists = true
580+
break
583581
}
584582
}
585583

clientapi/routing/register.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,19 @@ func (d *sessionsDict) deleteSession(sessionID string) {
128128
func (d *sessionsDict) allowCrossSigningKeysReplacement(userID string) int64 {
129129
d.Lock()
130130
defer d.Unlock()
131-
ts := time.Now().Add(crossSigningKeysReplacementDuration).UnixMilli()
131+
allowedUntilTS := time.Now().Add(crossSigningKeysReplacementDuration).UnixMilli()
132132
t, ok := d.crossSigningKeysReplacement[userID]
133133
if ok {
134134
t.Reset(crossSigningKeysReplacementDuration)
135-
return ts
135+
return allowedUntilTS
136136
}
137137
d.crossSigningKeysReplacement[userID] = time.AfterFunc(
138138
crossSigningKeysReplacementDuration,
139139
func() {
140140
d.restrictCrossSigningKeysReplacement(userID)
141141
},
142142
)
143-
return ts
143+
return allowedUntilTS
144144
}
145145

146146
func (d *sessionsDict) isCrossSigningKeysReplacementAllowed(userID string) bool {

clientapi/routing/routing.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,10 @@ func Setup(
349349
})).Methods(http.MethodPost)
350350
synapseAdminRouter.Handle("/admin/v2/users/{userID}",
351351
httputil.MakeServiceAdminAPI("admin_manage_user", m.AdminToken, func(r *http.Request) util.JSONResponse {
352-
switch r.Method {
353-
case http.MethodGet:
352+
if r.Method == http.MethodGet {
354353
return AdminRetrieveAccount(r, cfg, userAPI)
355-
case http.MethodPut:
356-
return AdminCreateOrModifyAccount(r, userAPI, cfg)
357-
default:
358-
return util.JSONResponse{Code: http.StatusMethodNotAllowed, JSON: nil}
359354
}
355+
return AdminCreateOrModifyAccount(r, userAPI, cfg)
360356
})).Methods(http.MethodPut, http.MethodGet)
361357
synapseAdminRouter.Handle("/admin/v2/users/{userID}/devices",
362358
httputil.MakeServiceAdminAPI("admin_create_retrieve_user_devices", m.AdminToken, func(r *http.Request) util.JSONResponse {

internal/httputil/httpapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func MakeServiceAdminAPI(
163163
}
164164
}
165165
if token != serviceToken {
166-
logger.Debugf("Invalid service token '%s'", token)
166+
logger.Debug("Invalid service token")
167167
return util.JSONResponse{
168168
Code: http.StatusForbidden,
169169
JSON: spec.UnknownToken(token),

setup/monolith.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type Monolith struct {
5151
ExtPublicRoomsProvider api.ExtraPublicRoomsProvider
5252
ExtUserDirectoryProvider userapi.QuerySearchProfilesAPI
5353

54-
UserVerifierProvider *UserVerifierProvider
54+
UserVerifierProvider httputil.UserVerifier
5555
}
5656

5757
// AddAllPublicRoutes attaches all public paths to the given router

0 commit comments

Comments
 (0)