32c7074f41
- 删除 KBBindingSnapshot 的 secret_entry_allowed 能力位与服务端 catalog/save 的 KB 传输门禁 - 非 HTTPS 控制台保留明文传输提示,但不再阻断 Key 录入 - 保留 QA AI 严格 HTTPS/回环校验、管理员认证、写意图头与 Key 不回显 - 补齐明文 HTTP 页面与服务端写入回归测试,同步运行手册和 CHANGELOG
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestSecretTransportAllowedAcceptsBareIPv6Loopback(t *testing.T) {
|
|
request := httptest.NewRequest(http.MethodPost, "http://placeholder/api/v1/kb-bindings/test", nil)
|
|
request.Host = "[::1]"
|
|
if !secretTransportAllowed(request, false) {
|
|
t.Fatal("bare [::1] Host was rejected as a loopback transport")
|
|
}
|
|
request.Host = "console.example"
|
|
if secretTransportAllowed(request, false) {
|
|
t.Fatal("public name without TLS was accepted")
|
|
}
|
|
}
|
|
|
|
func TestSecretTransportRejectsBracketedNonIPv6Hosts(t *testing.T) {
|
|
for _, host := range []string{"[127.0.0.1]", "[127.0.0.1]:28188", "[localhost]", "[localhost]:28188"} {
|
|
request := httptest.NewRequest(http.MethodPost, "http://placeholder/api/v1/kb-bindings/test", nil)
|
|
request.Host = host
|
|
if secretTransportAllowed(request, false) {
|
|
t.Fatalf("Host %q was accepted as a loopback transport", host)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSecretTransportRejectsMalformedIPv6Suffixes(t *testing.T) {
|
|
for _, host := range []string{"[::1]junk", "[::1]:", "[::1]:abc"} {
|
|
request := httptest.NewRequest(http.MethodPost, "http://placeholder/api/v1/kb-bindings/test", nil)
|
|
request.Host = host
|
|
if secretTransportAllowed(request, false) {
|
|
t.Fatalf("Host %q was accepted as a loopback transport", host)
|
|
}
|
|
}
|
|
}
|