This commit is contained in:
@@ -2,7 +2,6 @@ package cloudflared
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"log/slog"
|
||||
"path/filepath"
|
||||
@@ -13,7 +12,7 @@ import (
|
||||
"github.com/fonu/fonu/internal/secret"
|
||||
)
|
||||
|
||||
func TestAppSettingsDefaultToken(t *testing.T) {
|
||||
func TestAppSettingsAccountAndAPIToken(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
conn, err := db.Open(filepath.Join(dir, "test.db"))
|
||||
if err != nil {
|
||||
@@ -28,25 +27,17 @@ func TestAppSettingsDefaultToken(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
svc := NewService(config.Config{DataDir: dir}, NewStore(conn), box, slog.New(slog.NewTextHandler(io.Discard, nil)), nil)
|
||||
token := base64.StdEncoding.EncodeToString([]byte(`{"a":"acc-1","t":"tun-1","s":"sec-1"}`))
|
||||
|
||||
settings, err := svc.SaveAppSettings(context.Background(), AppSettingsInput{
|
||||
Token: token, Mirror: "gh-proxy-org", Network: DefaultNetworkSettings(),
|
||||
AccountID: "acc-1", APIToken: "cfat_test_token", Mirror: "gh-proxy-org", Network: DefaultNetworkSettings(),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !settings.DefaultTokenConfigured || settings.DefaultTokenMasked == "" {
|
||||
t.Fatalf("默认 token 应标记为已配置并返回掩码:%#v", settings)
|
||||
if settings.AccountID != "acc-1" || !settings.APITokenConfigured || settings.APITokenMasked == "" {
|
||||
t.Fatalf("Account ID 与 API Token 应保存并回显掩码:%#v", settings)
|
||||
}
|
||||
|
||||
tunnel, err := svc.Create(context.Background(), CreateInput{
|
||||
Name: "demo", Mode: ModeTokenLocal, Hostnames: []string{"a.example.com"}, Network: DefaultNetworkSettings(),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("应能使用默认 token 创建隧道: %v", err)
|
||||
}
|
||||
if tunnel.TunnelID != "tun-1" || tunnel.AccountTag != "acc-1" {
|
||||
t.Fatalf("默认 token 解析结果不符:%#v", tunnel)
|
||||
api, err := svc.cloudflareAPI(context.Background())
|
||||
if err != nil || api.AccountID != "acc-1" || api.APIToken != "cfat_test_token" {
|
||||
t.Fatalf("cloudflareAPI 构造失败:%v %#v", err, api)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user