优化客服云权限安全与访客IP解析
This commit is contained in:
@@ -1,10 +1,26 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCheckOriginUsesConfiguredAllowlist(t *testing.T) {
|
||||
SetAllowedOrigins([]string{"https://portal.example"})
|
||||
defer SetAllowedOrigins([]string{"*"})
|
||||
allowed := httptest.NewRequest("GET", "/api/ws", nil)
|
||||
allowed.Header.Set("Origin", "https://portal.example")
|
||||
if !checkOrigin(allowed) {
|
||||
t.Fatal("白名单来源应允许 WebSocket 升级")
|
||||
}
|
||||
denied := httptest.NewRequest("GET", "/api/ws", nil)
|
||||
denied.Header.Set("Origin", "https://evil.example")
|
||||
if checkOrigin(denied) {
|
||||
t.Fatal("非白名单来源不应允许 WebSocket 升级")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBroadcastToSessionRestrictsRecipients(t *testing.T) {
|
||||
hub := NewHub()
|
||||
go hub.Run()
|
||||
|
||||
Reference in New Issue
Block a user