Support IPv4 HTTP public gateway entries
This commit is contained in:
1 parent
6f01d31f97
commit
6d5973bea3
11 files changed
+146
-32
No files matched your search
@@ -68,8 +68,8 @@ func RenderWithOptions(opts RenderOptions, routes gin.RoutesInfo, authPort int)
|
||||
if scheme == "" {
|
||||
scheme = "https"
|
||||
}
|
||||
if !tlsservice.ValidDomain(domain) {
|
||||
return "", "", fmt.Errorf("请输入有效的单个完整域名")
|
||||
if !tlsservice.ValidPublicHost(scheme, domain) {
|
||||
return "", "", fmt.Errorf("请输入有效域名;HTTP 也支持 IPv4 地址")
|
||||
}
|
||||
if !tlsservice.ValidScheme(scheme) {
|
||||
return "", "", fmt.Errorf("协议仅支持 http 或 https")
|
||||
|
||||
@@ -111,6 +111,18 @@ func TestRenderHTTPCustomPort(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderHTTPIPv4AndRejectHTTPSIPv4(t *testing.T) {
|
||||
opts := RenderOptions{Domain: "121.4.111.208", Scheme: "http", Port: 28080}
|
||||
site, httpsSite, err := RenderWithOptions(opts, nil, 0)
|
||||
if err != nil || httpsSite != "" || !strings.Contains(site, "listen 28080;") || !strings.Contains(site, "server_name 121.4.111.208;") {
|
||||
t.Fatalf("HTTP IPv4 rendering failed: %v, %q, %q", err, site, httpsSite)
|
||||
}
|
||||
opts.Scheme = "https"
|
||||
if _, _, err := RenderWithOptions(opts, nil, 0); err == nil {
|
||||
t.Fatal("HTTPS IPv4 must be rejected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderHTTPSCustomPort(t *testing.T) {
|
||||
routes := gin.RoutesInfo{{Method: "GET", Path: "/api/health"}}
|
||||
httpSite, httpsSite, err := RenderWithOptions(RenderOptions{Domain: "vpn.example.com", Scheme: "https", Port: 8443}, routes, 0)
|
||||
|
||||
Reference in new issue
Block a user