Added log to show which URL is blocked by CORS. (#26347)

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Arya Khochare 2024-04-06 08:25:50 +05:30 committed by GitHub
parent 71e26b8df2
commit a040618485
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 3 deletions

View File

@ -32,7 +32,10 @@ func connectWebSocket(c *Context, w http.ResponseWriter, r *http.Request) {
ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
c.Err = model.NewAppError("connect", "api.web_socket.connect.upgrade.app_error", nil, err.Error(), http.StatusBadRequest)
params := map[string]any{
"BlockedOrigin": r.Header.Get("Origin"),
}
c.Err = model.NewAppError("connect", "api.web_socket.connect.upgrade.app_error", params, err.Error(), http.StatusBadRequest)
return
}

View File

@ -465,5 +465,5 @@ func TestWebSocketUpgrade(t *testing.T) {
require.NoError(t, err)
require.Equal(t, resp.StatusCode, http.StatusBadRequest)
require.NoError(t, th.TestLogger.Flush())
testlib.AssertLog(t, buffer, mlog.LvlDebug.Name, "Failed to upgrade websocket connection.")
testlib.AssertLog(t, buffer, mlog.LvlDebug.Name, "URL Blocked because of CORS. Url: ")
}

View File

@ -4552,7 +4552,7 @@
},
{
"id": "api.web_socket.connect.upgrade.app_error",
"translation": "Failed to upgrade websocket connection."
"translation": "URL Blocked because of CORS. Url: {{.BlockedOrigin}}"
},
{
"id": "api.web_socket_router.bad_action.app_error",