[MM-43199] api4/elasticsearch: test elasticsearch after checking the config values (#20078)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
72a5d99ae3
Коммит
a096a99542
@@ -21,6 +21,16 @@ func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg = c.App.Config()
|
||||
}
|
||||
|
||||
// we set BulkIndexingTimeWindowSeconds to a random value to avoid failing on the nil check
|
||||
// TODO: remove this hack once we remove BulkIndexingTimeWindowSeconds from the config.
|
||||
if cfg.ElasticsearchSettings.BulkIndexingTimeWindowSeconds == nil {
|
||||
cfg.ElasticsearchSettings.BulkIndexingTimeWindowSeconds = model.NewInt(0)
|
||||
}
|
||||
if checkHasNilFields(&cfg.ElasticsearchSettings) {
|
||||
c.Err = model.NewAppError("testElasticsearch", "api.elasticsearch.test_elasticsearch_settings_nil.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// PERMISSION_TEST_ELASTICSEARCH is an ancillary permission of PERMISSION_SYSCONSOLE_WRITE_ENVIRONMENT_ELASTICSEARCH,
|
||||
// which should prevent read-only managers from password sniffing
|
||||
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionTestElasticsearch) {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
@@ -26,8 +28,24 @@ func TestElasticsearchTest(t *testing.T) {
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("invalid config", func(t *testing.T) {
|
||||
cfg := &model.Config{}
|
||||
cfg.SetDefaults()
|
||||
cfg.ElasticsearchSettings.Password = nil
|
||||
|
||||
data, err := json.Marshal(cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := th.SystemAdminClient.DoAPIPost("/elasticsearch/test", string(data))
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.ElasticsearchSettings.SetDefaults()
|
||||
*cfg.ExperimentalSettings.RestrictSystemAdmin = true
|
||||
})
|
||||
|
||||
resp, err := th.SystemAdminClient.TestElasticsearch()
|
||||
require.Error(t, err)
|
||||
|
||||
@@ -1594,6 +1594,10 @@
|
||||
"id": "api.custom_status.set_custom_statuses.update.app_error",
|
||||
"translation": "Failed to update the custom status. Please add either emoji or custom text status or both."
|
||||
},
|
||||
{
|
||||
"id": "api.elasticsearch.test_elasticsearch_settings_nil.app_error",
|
||||
"translation": "Elasticsearch settings has unset values."
|
||||
},
|
||||
{
|
||||
"id": "api.email.send_warn_metric_ack.failure.app_error",
|
||||
"translation": "Failure to send admin acknowledgment email"
|
||||
|
||||
Ссылка в новой задаче
Block a user