fix: include api key in tenant websocket endpoint
This commit is contained in:
+5
-1
@@ -856,8 +856,12 @@ func imPublicEndpoints(req *http.Request) map[string]any {
|
||||
} else if strings.HasPrefix(wsBase, "http://") {
|
||||
wsBase = "ws://" + strings.TrimPrefix(wsBase, "http://")
|
||||
}
|
||||
wsEndpoint := strings.TrimRight(wsBase, "/") + "/v0/channels"
|
||||
if apiKey := strings.TrimSpace(getAPIKey(req)); apiKey != "" {
|
||||
wsEndpoint += "?apikey=" + url.QueryEscape(apiKey)
|
||||
}
|
||||
return map[string]any{
|
||||
"websocket": strings.TrimRight(wsBase, "/") + "/v0/channels",
|
||||
"websocket": wsEndpoint,
|
||||
"api": strings.TrimRight(base, "/") + "/v1/im",
|
||||
"file": strings.TrimRight(base, "/") + "/v0/file",
|
||||
}
|
||||
|
||||
@@ -1472,7 +1472,8 @@ func TestServeIMTenantResolveSuccessFromHeader(t *testing.T) {
|
||||
globals.servingAt = "https://im.example.com/"
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/v1/im/tenants/resolve", nil)
|
||||
req.Header.Set("X-MeetingIM-APIKey", makeTestAPIKey(t))
|
||||
apiKey := makeTestAPIKey(t)
|
||||
req.Header.Set("X-MeetingIM-APIKey", apiKey)
|
||||
req.Header.Set("X-Tenant-Code", " acme ")
|
||||
req.Header.Set("X-Request-ID", "req-1")
|
||||
rec := httptest.NewRecorder()
|
||||
@@ -1495,7 +1496,7 @@ func TestServeIMTenantResolveSuccessFromHeader(t *testing.T) {
|
||||
t.Fatalf("tenant payload must not expose internal id: %#v", tenant)
|
||||
}
|
||||
endpoints := data["endpoints"].(map[string]any)
|
||||
if endpoints["websocket"] != "wss://im.example.com/v0/channels" {
|
||||
if endpoints["websocket"] != "wss://im.example.com/v0/channels?apikey="+url.QueryEscape(apiKey) {
|
||||
t.Fatalf("unexpected websocket endpoint: %#v", endpoints)
|
||||
}
|
||||
}
|
||||
@@ -1536,7 +1537,8 @@ func TestServeIMTenantResolveUsesForwardedPublicHost(t *testing.T) {
|
||||
req.Host = "internal:6060"
|
||||
req.Header.Set("X-Forwarded-Proto", "https")
|
||||
req.Header.Set("X-Forwarded-Host", "api.118im.com")
|
||||
req.Header.Set("X-MeetingIM-APIKey", makeTestAPIKey(t))
|
||||
apiKey := makeTestAPIKey(t)
|
||||
req.Header.Set("X-MeetingIM-APIKey", apiKey)
|
||||
req.Header.Set("X-Tenant-Code", "acme")
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
@@ -1547,7 +1549,7 @@ func TestServeIMTenantResolveUsesForwardedPublicHost(t *testing.T) {
|
||||
}
|
||||
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
|
||||
endpoints := data["endpoints"].(map[string]any)
|
||||
if endpoints["websocket"] != "wss://api.118im.com/v0/channels" ||
|
||||
if endpoints["websocket"] != "wss://api.118im.com/v0/channels?apikey="+url.QueryEscape(apiKey) ||
|
||||
endpoints["api"] != "https://api.118im.com/v1/im" ||
|
||||
endpoints["file"] != "https://api.118im.com/v0/file" {
|
||||
t.Fatalf("unexpected endpoints: %#v", endpoints)
|
||||
|
||||
Reference in New Issue
Block a user