This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cloudflared
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -32,6 +33,28 @@ func TestDecodeTokenRejectsInvalid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeTokenURLSafe(t *testing.T) {
|
||||
payload := `{"a":"account-1","t":"tunnel-2","s":"secret-3"}`
|
||||
encoded := base64.RawURLEncoding.EncodeToString([]byte(payload))
|
||||
if _, _, _, err := DecodeToken(encoded); err != nil {
|
||||
t.Fatalf("URL-safe token 应可解码: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeBase64Flexible(t *testing.T) {
|
||||
raw := []byte{0xfb, 0xef, 0xbe, 0xad}
|
||||
for _, encoded := range []string{
|
||||
base64.RawURLEncoding.EncodeToString(raw),
|
||||
base64.URLEncoding.EncodeToString(raw),
|
||||
base64.RawStdEncoding.EncodeToString(raw),
|
||||
} {
|
||||
got, err := decodeBase64(encoded)
|
||||
if err != nil || !bytes.Equal(got, raw) {
|
||||
t.Fatalf("编码 %q 解码失败:%v", encoded, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildIngressInvariants(t *testing.T) {
|
||||
got := BuildIngress([]string{"B.example.com", "a.example.com", "a.example.com", " "}, "http://127.0.0.1:80")
|
||||
if len(got) != 3 {
|
||||
|
||||
Reference in New Issue
Block a user