权限整改:完善 DNS 项目归属展示与进度清单
补充 DNS 账户管理页面的项目归属展示和权限拒绝回归测试,更新四份中文整改进度清单,保持总体验收位置为 P0-03 完成待复审。
This commit is contained in:
1 parent
b8fd536dbd
commit
07f86f1413
8 files changed
+89
-6
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -78,6 +79,37 @@ func TestDNSCredentialUseRejectsUnauthorizedProject(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSettingsDNSProjectAssignmentRequiresDNSManagePermission(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
cfg := config.Default(dir)
|
||||
cfg.SetupReady = true
|
||||
cfg.DNS.VerificationState = "verified"
|
||||
cfg.Web.Hostname = "scert.example.test"
|
||||
cfg.Admin.Username = "admin"
|
||||
cfg.Admin.Email = "admin@example.test"
|
||||
cfg.Admin.PasswordHash = mustTestPasswordHash(t, "Password123")
|
||||
configPath := filepath.Join(dir, "config", "scert.json")
|
||||
if err := cfg.Save(configPath); err != nil {
|
||||
t.Fatalf("保存测试配置失败:%v", err)
|
||||
}
|
||||
server := New(Dependencies{
|
||||
Config: cfg, ConfigPath: configPath,
|
||||
ProjectDomains: projectDomainRepositoryStub{authorizeErr: repository.ErrProjectAccessDenied},
|
||||
})
|
||||
cookie := loginForSettingsTest(t, server)
|
||||
request := httptest.NewRequest(http.MethodPut, "/api/v1/settings", strings.NewReader(`{"dns":{"project_id":"project-a"}}`))
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
request.AddCookie(cookie)
|
||||
response := httptest.NewRecorder()
|
||||
server.Handler().ServeHTTP(response, request)
|
||||
if response.Code != http.StatusForbidden {
|
||||
t.Fatalf("无 DNS 管理权限修改项目归属应返回 403,实际为 %d:%s", response.Code, response.Body.String())
|
||||
}
|
||||
if server.config.DNS.ProjectID != "default" {
|
||||
t.Fatalf("拒绝修改后 DNS 项目归属不应变化:%q", server.config.DNS.ProjectID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminDNSTestReturnsVerificationResult(t *testing.T) {
|
||||
cfg := config.Default(t.TempDir())
|
||||
cfg.SetupReady = true
|
||||
|
||||
Reference in new issue
Block a user