更新密码找回uniapp

This commit is contained in:
hero920103 committed 2026-11-16 17:22:50 +08:00
1 parent 7f9a66da0f
commit 3fdda89833
1304 files changed
+3503 -26132

No files matched your search

+2 -28
View File
@@ -8,9 +8,6 @@ import (
beego "github.com/beego/beego/v2/server/web"
)
// TestNormalizeHost 覆盖用户在绑定框里可能输入的各种写法。
// 归一化结果直接写进 yz_system_tenant_domain.full_domain,
// 而官网渲染是按 Host 精确等值查这张表,所以这里一旦放宽就会出现「绑了但打不开」。
func TestNormalizeHost(t *testing.T) {
cases := []struct {
name string
@@ -55,16 +52,13 @@ func TestNormalizeHost(t *testing.T) {
}
}
// TestNormalizeHostTooLong 超过 253 字节的主机名不合法,必须拒绝。
func TestNormalizeHostTooLong(t *testing.T) {
long := strings.Repeat("a.", 130) + "com" // 远超 253
long := strings.Repeat("a.", 130) + "com"
if got := NormalizeHost(long); got != "" {
t.Errorf("超长域名应被拒绝,实际返回 %q", got)
}
}
// TestCertPathsStaysInsideCertDir 证书目录名来自数据库里的域名,
// 必须保证拼出来的路径落在 ssl_cert_dir 内,不能被 ../ 之类的脏数据带出去。
func TestCertPathsStaysInsideCertDir(t *testing.T) {
root := filepath.Clean(SSLCertDir())
@@ -85,7 +79,6 @@ func TestCertPathsStaysInsideCertDir(t *testing.T) {
}
}
// TestCertPathsFileNames 落盘文件名必须与 Nginx 配置里引用的名字一致。
func TestCertPathsFileNames(t *testing.T) {
certPath, keyPath := CertPaths("www.example.com")
if filepath.Base(certPath) != "fullchain.pem" {
@@ -99,10 +92,7 @@ func TestCertPathsFileNames(t *testing.T) {
}
}
// TestVerifyCustomDomainDNSWithoutConfig 平台没配解析目标时,
// 不能去打 DNS 也不能误判通过,要直接给出「联系管理员」的提示。
func TestVerifyCustomDomainDNSWithoutConfig(t *testing.T) {
// 测试环境没有加载 app.conf,GetCustomDomainGuide 返回空配置
guide := GetCustomDomainGuide()
if guide.CnameTarget != "" || len(guide.AIPs) > 0 {
t.Skip("当前环境读到了解析目标配置,跳过空配置分支")
@@ -117,7 +107,6 @@ func TestVerifyCustomDomainDNSWithoutConfig(t *testing.T) {
}
}
// TestVerifyCustomDomainDNSRejectsBadHost 非法域名在检测入口就要拦住。
func TestVerifyCustomDomainDNSRejectsBadHost(t *testing.T) {
passed, msg := VerifyCustomDomainDNS("not a domain")
if passed {
@@ -128,9 +117,6 @@ func TestVerifyCustomDomainDNSRejectsBadHost(t *testing.T) {
}
}
// withTempCertDir 把 ssl_cert_dir 指到临时目录。
// 默认值是 /www/wwwroot/ssl-certs,在 Windows 上会落到当前盘根目录,
// 跑测试不该在仓库外面留文件。
func withTempCertDir(t *testing.T) string {
t.Helper()
dir := t.TempDir()
@@ -144,10 +130,7 @@ func withTempCertDir(t *testing.T) string {
return dir
}
// TestChallengeTokenValidation token 会被拼进文件名,
// 必须先过正则;否则 `../../` 这类 token 能让 Go 读写证书目录外的文件。
func TestChallengeTokenValidation(t *testing.T) {
// 合法:base64url,长度 16-128
valid := []string{
strings.Repeat("a", 16),
strings.Repeat("a", 128),
@@ -176,8 +159,6 @@ func TestChallengeTokenValidation(t *testing.T) {
}
}
// TestGetHTTP01ChallengeRejectsBadToken 未命中内存时,
// 非法 token 不能进到读文件那一步。
func TestGetHTTP01ChallengeRejectsBadToken(t *testing.T) {
if _, ok := GetHTTP01Challenge("../../etc/passwd"); ok {
t.Error("非法 token 不应返回内容")
@@ -187,8 +168,6 @@ func TestGetHTTP01ChallengeRejectsBadToken(t *testing.T) {
}
}
// TestChallengeStoreRoundTrip 内存与磁盘两层的存取与删除。
// 磁盘那层是给「签发进程」与「应答 CA 回访的进程」不是同一个的部署方式兜底的。
func TestChallengeStoreRoundTrip(t *testing.T) {
dir := withTempCertDir(t)
@@ -203,7 +182,6 @@ func TestChallengeStoreRoundTrip(t *testing.T) {
t.Fatalf("取回的 keyAuth = %q ok=%v,期望 %q true", got, ok, keyAuth)
}
// 磁盘兜底:清掉内存后仍要能读到
challengeMu.Lock()
delete(challengeStore, token)
challengeMu.Unlock()
@@ -223,7 +201,6 @@ func TestChallengeStoreRoundTrip(t *testing.T) {
// 否则会向 CA 重复下单,白白消耗频控额度。
func TestTryLockIssueSerializes(t *testing.T) {
host := "lock-test.example.com"
// 清掉可能残留的状态
t.Cleanup(func() { unlockIssue(host, false) })
ok, _ := tryLockIssue(host)
@@ -246,7 +223,6 @@ func TestTryLockIssueSerializes(t *testing.T) {
unlockIssue(host, false)
}
// TestTryLockIssueCooldown 失败后进入冷却期,避免租户连点把 CA 额度打满。
func TestTryLockIssueCooldown(t *testing.T) {
host := "cooldown-test.example.com"
t.Cleanup(func() { unlockIssue(host, false) })
@@ -255,7 +231,7 @@ func TestTryLockIssueCooldown(t *testing.T) {
if !ok {
t.Fatal("首次抢锁应成功")
}
unlockIssue(host, true) // 标记失败
unlockIssue(host, true)
ok2, reason := tryLockIssue(host)
if ok2 {
@@ -265,7 +241,6 @@ func TestTryLockIssueCooldown(t *testing.T) {
t.Errorf("冷却提示应包含等待时间,实际 %q", reason)
}
// 成功一次要把冷却清掉
unlockIssue(host, false)
if ok3, reason3 := tryLockIssue(host); !ok3 {
t.Errorf("成功后应清除冷却,实际被拒: %s", reason3)
@@ -273,7 +248,6 @@ func TestTryLockIssueCooldown(t *testing.T) {
unlockIssue(host, false)
}
// TestIssueCertificateAsyncRejectsBadHost 非法域名不该发起签发流程。
func TestIssueCertificateAsyncRejectsBadHost(t *testing.T) {
if ok, _ := IssueCertificateAsync(0, "not a domain"); ok {
t.Error("非法域名不应发起签发")