将密码找回指引切换为本机管理命令
This commit is contained in:
1 parent
a0ed64d0b0
commit
6af7c5ab3b
7 files changed
+180
-6
No files matched your search
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/admin"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/auth"
|
||||
)
|
||||
|
||||
@@ -21,7 +20,6 @@ type passwordResetResolution struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Action string `json:"action"`
|
||||
ResetPath string `json:"reset_path,omitempty"`
|
||||
}
|
||||
|
||||
// resolvePasswordResetAccount 根据账户标识返回对应的密码处理内容。
|
||||
@@ -52,8 +50,7 @@ func (s *Server) resolvePasswordResetAccount(c *gin.Context) {
|
||||
AccountLabel: "超级管理员",
|
||||
Title: "超级管理员密码重置",
|
||||
Description: "已识别为超级管理员账户。超级管理员不能通过普通重置页面修改密码,请使用 Scert-admin 开启的一次性重置入口。",
|
||||
Action: "use_super_admin_entry",
|
||||
ResetPath: admin.ResetPath,
|
||||
Action: "local_admin_command",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPasswordResetResolutionOnlyOffersLocalAdminCommand(t *testing.T) {
|
||||
cfg := readyTestConfig(t.TempDir())
|
||||
cfg.Admin.Username = "owner"
|
||||
cfg.Admin.Email = "owner@example.test"
|
||||
server := New(Dependencies{Config: cfg, Repository: &stubDomainRepository{}})
|
||||
for _, identifier := range []string{"owner", "owner@example.test"} {
|
||||
t.Run(identifier, func(t *testing.T) {
|
||||
body, err := json.Marshal(map[string]string{"identifier": identifier})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/v1/password-reset/resolve", strings.NewReader(string(body)))
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
response := httptest.NewRecorder()
|
||||
server.Handler().ServeHTTP(response, request)
|
||||
if response.Code != http.StatusOK {
|
||||
t.Fatalf("查询失败:%d %s", response.Code, response.Body.String())
|
||||
}
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if payload["account_type"] != "super_admin" || payload["action"] != "local_admin_command" {
|
||||
t.Fatalf("超级管理员没有返回本机命令指引:%v", payload)
|
||||
}
|
||||
for _, field := range []string{"reset_path", "reset_url", "token", "nonce"} {
|
||||
if _, exists := payload[field]; exists {
|
||||
t.Fatalf("公开查询泄露了重置入口或会话字段:%s", field)
|
||||
}
|
||||
}
|
||||
if len(response.Result().Cookies()) != 0 {
|
||||
t.Fatal("公开查询不应创建重置会话")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user