Initialize Clash Web source and deployment documentation
This commit is contained in:
commit
8e0fa00a73
66 files changed
+8532
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/x509"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSubscriptionDownloadErrorsExplainCauseWithoutURL(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
err error
|
||||
phrase string
|
||||
}{
|
||||
{x509.UnknownAuthorityError{}, "CA 证书包"},
|
||||
{x509.HostnameError{}, "域名不匹配"},
|
||||
{x509.CertificateInvalidError{}, "证书校验失败"},
|
||||
{&net.DNSError{Err: "no such host", Name: "private.example"}, "域名解析失败"},
|
||||
{context.DeadlineExceeded, "下载超时"},
|
||||
{context.Canceled, "已取消"},
|
||||
{syscall.ECONNREFUSED, "连接被拒绝"},
|
||||
} {
|
||||
wrapped := &url.Error{Op: "Get", URL: "https://private.example/sub?token=secret-token", Err: test.err}
|
||||
message := subscriptionDownloadError(wrapped).Error()
|
||||
if !strings.Contains(message, test.phrase) {
|
||||
t.Fatalf("cause not explained: %s", message)
|
||||
}
|
||||
if strings.Contains(message, "secret-token") || strings.Contains(message, "private.example") {
|
||||
t.Fatal("download error exposed subscription URL")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user