if EnableLinkPreviews not enabled, do not call url (#9461)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
328d9a55ee
Коммит
3e462713de
@@ -451,6 +451,13 @@ func testS3(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
m := make(map[string]string)
|
||||||
|
m["location"] = ""
|
||||||
|
cfg := c.App.GetConfig()
|
||||||
|
if !*cfg.ServiceSettings.EnableLinkPreviews {
|
||||||
|
w.Write([]byte(model.MapToJson(m)))
|
||||||
|
return
|
||||||
|
}
|
||||||
url := r.URL.Query().Get("url")
|
url := r.URL.Query().Get("url")
|
||||||
if len(url) == 0 {
|
if len(url) == 0 {
|
||||||
c.SetInvalidParam("url")
|
c.SetInvalidParam("url")
|
||||||
@@ -463,9 +470,6 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
m := make(map[string]string)
|
|
||||||
m["location"] = ""
|
|
||||||
|
|
||||||
res, err := client.Head(url)
|
res, err := client.Head(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Always return a success status and a JSON string to limit the amount of information returned to a
|
// Always return a success status and a JSON string to limit the amount of information returned to a
|
||||||
|
|||||||
@@ -717,6 +717,12 @@ func TestRedirectLocation(t *testing.T) {
|
|||||||
th := Setup().InitBasic().InitSystemAdmin()
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
Client := th.Client
|
Client := th.Client
|
||||||
|
enableLinkPreviews := *th.App.Config().ServiceSettings.EnableLinkPreviews
|
||||||
|
defer func() {
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableLinkPreviews = enableLinkPreviews })
|
||||||
|
}()
|
||||||
|
|
||||||
|
*th.App.Config().ServiceSettings.EnableLinkPreviews = true
|
||||||
|
|
||||||
_, resp := th.SystemAdminClient.GetRedirectLocation("https://mattermost.com/", "")
|
_, resp := th.SystemAdminClient.GetRedirectLocation("https://mattermost.com/", "")
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
@@ -730,6 +736,19 @@ func TestRedirectLocation(t *testing.T) {
|
|||||||
t.Errorf("Expected %v but got %v.", expected, actual)
|
t.Errorf("Expected %v but got %v.", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*th.App.Config().ServiceSettings.EnableLinkPreviews = false
|
||||||
|
actual, resp = th.SystemAdminClient.GetRedirectLocation("https://mattermost.com/", "")
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
assert.Equal(t, actual, "")
|
||||||
|
|
||||||
|
actual, resp = th.SystemAdminClient.GetRedirectLocation("", "")
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
assert.Equal(t, actual, "")
|
||||||
|
|
||||||
|
actual, resp = th.SystemAdminClient.GetRedirectLocation(mockBitlyLink, "")
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
assert.Equal(t, actual, "")
|
||||||
|
|
||||||
Client.Logout()
|
Client.Logout()
|
||||||
_, resp = Client.GetRedirectLocation("", "")
|
_, resp = Client.GetRedirectLocation("", "")
|
||||||
CheckUnauthorizedStatus(t, resp)
|
CheckUnauthorizedStatus(t, resp)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user