Files
mirror-3x-ui/internal/web/controller/wechat_test.go
T
17 3cb5bb7187 feat(wechat): add WeCom and webhook notifications (#7086)
Panel alerts and the scheduled status report could go to Telegram, Discord or email, but not to a WeCom group robot or a generic webhook.

Add a WeChat channel, off by default, with two modes: a WeCom group robot, or a webhook that receives a small signed-free JSON envelope with an optional bearer token. It carries the same events as the other channels (logins, CPU and memory, Xray crash, node and outbound state) and a scheduled text report. Delivery goes through the SSRF-guarded dialer, follows no redirects, and the URL and token are stored and redacted like the other notification secrets.
2026-11-24 21:54:39 +03:30

40 lines
1.3 KiB
Go

package controller
import (
"encoding/json"
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
"github.com/gin-gonic/gin"
"github.com/mhsanaei/3x-ui/v3/internal/database/dbtest"
"github.com/mhsanaei/3x-ui/v3/internal/web/service"
"github.com/mhsanaei/3x-ui/v3/internal/web/service/wechat"
)
func TestWechatTestEndpointRefusesDisabledSavedConfiguration(t *testing.T) {
dbtest.InitDB(t, filepath.Join(t.TempDir(), "x-ui.db"))
previous := wechatService
t.Cleanup(func() { wechatService = previous })
SetWechatService(wechat.NewService(service.SettingService{}))
gin.SetMode(gin.TestMode)
router := gin.New()
NewSettingController(router.Group("/panel/api"))
response := httptest.NewRecorder()
router.ServeHTTP(response, httptest.NewRequest(http.MethodPost, "/panel/api/setting/testWechat", nil))
var result struct {
Success bool `json:"success"`
Msg string `json:"msg"`
}
if err := json.Unmarshal(response.Body.Bytes(), &result); err != nil {
t.Fatal(err)
}
// Without the endpoint's own check the sender fails too, but with its generic configuration error.
if response.Code != http.StatusOK || result.Success || !strings.HasSuffix(result.Msg, "(WeChat notifications are disabled)") {
t.Fatalf("disabled test endpoint returned %d %s", response.Code, response.Body.String())
}
}