From d1d4f9945bd95f7583104ed7820b77a5ba81bb23 Mon Sep 17 00:00:00 2001 From: smail Date: Wed, 30 Sep 2026 04:45:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E6=9F=A5=E6=A3=80=E6=9F=A5=E7=82=B9?= =?UTF-8?q?=EF=BC=9A=E8=A1=A5=E5=85=85=E5=AF=86=E7=A0=81=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E5=9B=9E=E5=BD=92=E9=94=99=E8=AF=AF=E8=AF=8A=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为管理员密码重置回归保留响应体诊断,明确分组范围授权失败原因。 --- .../password_reset_permissions_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/controllers/password_reset_permissions_test.go b/backend/controllers/password_reset_permissions_test.go index 7f28924..3adc3cf 100644 --- a/backend/controllers/password_reset_permissions_test.go +++ b/backend/controllers/password_reset_permissions_test.go @@ -69,8 +69,8 @@ func TestEditUserPasswordResetRoleMatrix(t *testing.T) { adminContext.SessionVersion = admin.SessionVersion adminContext.SecurityVersion = admin.SecurityVersion - if result := editUserRequest(t, adminContext, `{"id":`+itoa(user.ID)+`,"password":"ResetUser123","disabled":0}`); result != 0 { - t.Fatalf("administrator could not reset regular user: %d", result) + if result, body := editUserResponse(t, adminContext, `{"id":`+itoa(user.ID)+`,"password":"ResetUser123","disabled":0}`); result != 0 { + t.Fatalf("administrator could not reset regular user: %d: %s", result, body) } assertUserPassword(t, user.ID, "ResetUser123") @@ -88,6 +88,20 @@ func TestEditUserPasswordResetRoleMatrix(t *testing.T) { } } +func editUserResponse(t *testing.T, ctx *appcontext.Context, payload string) (int, string) { + t.Helper() + recorder := httptest.NewRecorder() + request := httptest.NewRequest(http.MethodPost, "/api/user/edit", strings.NewReader(payload)) + EditUser(ctx, recorder, request) + var result struct { + ErrorNo int `json:"errorNo"` + } + if err := json.Unmarshal(recorder.Body.Bytes(), &result); err != nil { + t.Fatal(err) + } + return result.ErrorNo, recorder.Body.String() +} + func TestPasswordChangeRevokesOfflineCredentialsAtomically(t *testing.T) { oldConfig := config.Instance oldDB := db.Instance