Add files via upload

This commit is contained in:
公明
2026-07-20 10:49:40 +08:00
committed by GitHub
parent cb0d61a48d
commit 9a269ac0ec
2 changed files with 45 additions and 0 deletions
+14
View File
@@ -44,3 +44,17 @@ func ApplyDevHTTPSBootstrap(cfg *Config) {
}
cfg.Server.TLSAutoSelfSign = true
}
// ApplyPlainHTTPBootstrap 供 --http / 一键脚本使用:强制主站使用明文 HTTP。
// 它会覆盖配置文件中的 TLS 开关、自签证书以及证书路径,避免 --http 仍被配置中的 HTTPS 选项重新启用。
func ApplyPlainHTTPBootstrap(cfg *Config) {
if cfg == nil {
return
}
cfg.Server.TLSEnabled = false
cfg.Server.TLSAutoSelfSign = false
cfg.Server.TLSCertPath = ""
cfg.Server.TLSKeyPath = ""
disabled := false
cfg.Server.TLSHTTPRedirect = &disabled
}
@@ -0,0 +1,31 @@
package config
import "testing"
func TestApplyPlainHTTPBootstrapDisablesConfiguredTLS(t *testing.T) {
enabled := true
cfg := &Config{
Server: ServerConfig{
TLSEnabled: true,
TLSAutoSelfSign: true,
TLSCertPath: "/tmp/server.crt",
TLSKeyPath: "/tmp/server.key",
TLSHTTPRedirect: &enabled,
},
}
ApplyPlainHTTPBootstrap(cfg)
if MainWebUIUsesHTTPS(&cfg.Server) {
t.Fatal("expected --http bootstrap to disable main web UI HTTPS")
}
if ServerHTTPRedirectEnabled(&cfg.Server) {
t.Fatal("expected --http bootstrap to disable HTTP to HTTPS redirect")
}
if cfg.Server.TLSCertPath != "" || cfg.Server.TLSKeyPath != "" {
t.Fatalf("expected TLS cert paths to be cleared, got cert=%q key=%q", cfg.Server.TLSCertPath, cfg.Server.TLSKeyPath)
}
if cfg.Server.TLSHTTPRedirect == nil || *cfg.Server.TLSHTTPRedirect {
t.Fatal("expected TLSHTTPRedirect to be explicitly disabled")
}
}