mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
f376a2abe3
Unify webhook handling across channel adapters and add the WeChat Official Account channel so inbound routing and replies work without platform-specific handlers. Add adapter-scoped proxy support and stable config field ordering so restricted network environments can deliver WeChat and Telegram messages reliably.
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package wechatoa
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeConfig_DefaultSafe(t *testing.T) {
|
|
out, err := normalizeConfig(map[string]any{
|
|
"appId": "wx123",
|
|
"appSecret": "secret",
|
|
"token": "token",
|
|
"encodingAESKey": "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("normalizeConfig error = %v", err)
|
|
}
|
|
if out["encryptionMode"] != encryptionModeSafe {
|
|
t.Fatalf("unexpected encryption mode: %v", out["encryptionMode"])
|
|
}
|
|
}
|
|
|
|
func TestNormalizeTarget(t *testing.T) {
|
|
got := normalizeTarget("wechat:openid:o123")
|
|
if got != "openid:o123" {
|
|
t.Fatalf("normalizeTarget = %q", got)
|
|
}
|
|
}
|
|
|
|
func TestResolveTargetRequiresOpenID(t *testing.T) {
|
|
_, err := resolveTarget(map[string]any{"unionid": "u1"})
|
|
if err == nil {
|
|
t.Fatal("expected error")
|
|
}
|
|
}
|
|
|
|
func TestParseConfig_HTTPProxy(t *testing.T) {
|
|
proxyURL := "http://memoh:" + "proxy-secret" + "@sztu.cc:3128"
|
|
cfg, err := parseConfig(map[string]any{
|
|
"appId": "wx123",
|
|
"appSecret": "secret",
|
|
"token": "token",
|
|
"encodingAESKey": "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG",
|
|
"httpProxyUrl": proxyURL,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("parseConfig error = %v", err)
|
|
}
|
|
if cfg.HTTPProxy.URL != proxyURL {
|
|
t.Fatalf("unexpected httpProxyUrl: %q", cfg.HTTPProxy.URL)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeConfig_HTTPProxy(t *testing.T) {
|
|
proxyURL := "http://memoh:" + "proxy-secret" + "@sztu.cc:3128"
|
|
out, err := normalizeConfig(map[string]any{
|
|
"appId": "wx123",
|
|
"appSecret": "secret",
|
|
"token": "token",
|
|
"encodingAESKey": "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG",
|
|
"httpProxyUrl": proxyURL,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("normalizeConfig error = %v", err)
|
|
}
|
|
if out["httpProxyUrl"] != proxyURL {
|
|
t.Fatalf("unexpected httpProxyUrl: %v", out["httpProxyUrl"])
|
|
}
|
|
}
|