[MM-37557] Move error out of client4 response (#18101)
* Return an error seperately from Response * Remove BuildErrorResponse * Drop Response.Error from model/client4.go * Migrate require.Nil checks * Migrate require.NotNil checks * More manual fixes * Move error check out of CheckOKStatus and CheckCreatedStatus * Move error check out of CheckForbiddenStatus * Move error check out of CheckUnauthorizedStatus * Move error check out of CheckNotFoundStatus * Move error check out of CheckBadRequestStatus * Move error check out of CheckNotImplementedStatus and CheckRequestEntityTooLargeStatus * Move error check out of CheckInternalErrorStatus * Move error check out of CheckServiceUnavailableStatus * Remove error check from checkHTTPStatus * Remove remaining references to Response.Error * Check previously unchecked errors * Manually fix compile and linter errors * Return error in CreateWebSocket methods * Return error instead of *AppError in DoApi methods * Manually fix bad replacments * Conistently return Response and error * Use err instead of seperate bool return value to indicate success * Reduce ussage of model.AppError in web/oauth_test.go * Remove client4.Must * Check error in buf.ReadFrom * Fix failing tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
96593580ae
Коммит
a8ca5c423f
@@ -28,8 +28,8 @@ func TestGetPing(t *testing.T) {
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
t.Run("healthy", func(t *testing.T) {
|
||||
status, resp := client.GetPing()
|
||||
CheckNoError(t, resp)
|
||||
status, _, err := client.GetPing()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, model.StatusOk, status)
|
||||
})
|
||||
|
||||
@@ -40,7 +40,8 @@ func TestGetPing(t *testing.T) {
|
||||
}()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.GoroutineHealthThreshold = 10 })
|
||||
status, resp := client.GetPing()
|
||||
status, resp, err := client.GetPing()
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
assert.Equal(t, model.StatusUnhealthy, status)
|
||||
})
|
||||
@@ -48,9 +49,8 @@ func TestGetPing(t *testing.T) {
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
t.Run("healthy", func(t *testing.T) {
|
||||
status, resp := client.GetPingWithServerStatus()
|
||||
|
||||
CheckNoError(t, resp)
|
||||
status, _, err := client.GetPingWithServerStatus()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, model.StatusOk, status)
|
||||
})
|
||||
|
||||
@@ -62,7 +62,8 @@ func TestGetPing(t *testing.T) {
|
||||
th.App.Config().FileSettings.DriverName = oldDriver
|
||||
}()
|
||||
|
||||
status, resp := client.GetPingWithServerStatus()
|
||||
status, resp, err := client.GetPingWithServerStatus()
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
assert.Equal(t, model.StatusUnhealthy, status)
|
||||
})
|
||||
@@ -70,8 +71,8 @@ func TestGetPing(t *testing.T) {
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
th.App.ReloadConfig()
|
||||
resp, appErr := client.DoApiGet(client.GetSystemRoute()+"/ping", "")
|
||||
require.Nil(t, appErr)
|
||||
resp, err := client.DoApiGet(client.GetSystemRoute()+"/ping", "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
@@ -83,8 +84,8 @@ func TestGetPing(t *testing.T) {
|
||||
defer os.Unsetenv("MM_FEATUREFLAGS_TESTFEATURE")
|
||||
th.App.ReloadConfig()
|
||||
|
||||
resp, appErr = client.DoApiGet(client.GetSystemRoute()+"/ping", "")
|
||||
require.Nil(t, appErr)
|
||||
resp, err = client.DoApiGet(client.GetSystemRoute()+"/ping", "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
respBytes, err = ioutil.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
@@ -96,35 +97,37 @@ func TestGetPing(t *testing.T) {
|
||||
func TestGetAudits(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
audits, resp := th.SystemAdminClient.GetAudits(0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
audits, _, err := th.SystemAdminClient.GetAudits(0, 100, "")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, audits, "should not be empty")
|
||||
|
||||
audits, resp = th.SystemAdminClient.GetAudits(0, 1, "")
|
||||
CheckNoError(t, resp)
|
||||
audits, _, err = th.SystemAdminClient.GetAudits(0, 1, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, audits, 1, "should only be 1")
|
||||
|
||||
audits, resp = th.SystemAdminClient.GetAudits(1, 1, "")
|
||||
CheckNoError(t, resp)
|
||||
audits, _, err = th.SystemAdminClient.GetAudits(1, 1, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, audits, 1, "should only be 1")
|
||||
|
||||
_, resp = th.SystemAdminClient.GetAudits(-1, -1, "")
|
||||
CheckNoError(t, resp)
|
||||
_, _, err = th.SystemAdminClient.GetAudits(-1, -1, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp = Client.GetAudits(0, 100, "")
|
||||
_, resp, err := client.GetAudits(0, 100, "")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
Client.Logout()
|
||||
_, resp = Client.GetAudits(0, 100, "")
|
||||
client.Logout()
|
||||
_, resp, err = client.GetAudits(0, 100, "")
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestEmailTest(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
require.NoError(t, err)
|
||||
@@ -155,13 +158,14 @@ func TestEmailTest(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
_, resp := Client.TestEmail(&config)
|
||||
resp, err := client.TestEmail(&config)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
_, resp := th.SystemAdminClient.TestEmail(&config)
|
||||
CheckErrorMessage(t, resp, "api.admin.test_email.missing_server")
|
||||
resp, err := th.SystemAdminClient.TestEmail(&config)
|
||||
CheckErrorID(t, err, "api.admin.test_email.missing_server")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
inbucket_host := os.Getenv("CI_INBUCKET_HOST")
|
||||
@@ -176,14 +180,16 @@ func TestEmailTest(t *testing.T) {
|
||||
|
||||
*config.EmailSettings.SMTPServer = inbucket_host
|
||||
*config.EmailSettings.SMTPPort = inbucket_port
|
||||
_, resp = th.SystemAdminClient.TestEmail(&config)
|
||||
resp, err = th.SystemAdminClient.TestEmail(&config)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
_, resp := th.SystemAdminClient.TestEmail(&config)
|
||||
resp, err := th.SystemAdminClient.TestEmail(&config)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
}
|
||||
@@ -196,22 +202,23 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
l := model.NewTestLicense()
|
||||
th.App.Srv().SetLicense(l)
|
||||
|
||||
file, resp := th.SystemAdminClient.GenerateSupportPacket()
|
||||
require.Nil(t, resp.Error)
|
||||
file, _, err := th.SystemAdminClient.GenerateSupportPacket()
|
||||
require.NoError(t, err)
|
||||
require.NotZero(t, len(file))
|
||||
})
|
||||
|
||||
t.Run("As a Regular User", func(t *testing.T) {
|
||||
_, resp := th.Client.GenerateSupportPacket()
|
||||
_, resp, err := th.Client.GenerateSupportPacket()
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("Server with no License", func(t *testing.T) {
|
||||
ok, resp := th.SystemAdminClient.RemoveLicenseFile()
|
||||
CheckNoError(t, resp)
|
||||
require.True(t, ok)
|
||||
_, err := th.SystemAdminClient.RemoveLicenseFile()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp = th.SystemAdminClient.GenerateSupportPacket()
|
||||
_, resp, err := th.SystemAdminClient.GenerateSupportPacket()
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
}
|
||||
@@ -219,7 +226,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
func TestSiteURLTest(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasSuffix(r.URL.Path, "/valid/api/v4/system/ping") {
|
||||
@@ -234,25 +241,30 @@ func TestSiteURLTest(t *testing.T) {
|
||||
invalidSiteURL := ts.URL + "/invalid"
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
_, resp := th.SystemAdminClient.TestSiteURL("")
|
||||
resp, err := th.SystemAdminClient.TestSiteURL("")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.TestSiteURL(invalidSiteURL)
|
||||
resp, err = th.SystemAdminClient.TestSiteURL(invalidSiteURL)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.TestSiteURL(validSiteURL)
|
||||
resp, err = th.SystemAdminClient.TestSiteURL(validSiteURL)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
_, resp := Client.TestSiteURL(validSiteURL)
|
||||
resp, err := client.TestSiteURL(validSiteURL)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
_, resp := Client.TestSiteURL(validSiteURL)
|
||||
resp, err := client.TestSiteURL(validSiteURL)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
}
|
||||
@@ -260,22 +272,24 @@ func TestSiteURLTest(t *testing.T) {
|
||||
func TestDatabaseRecycle(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
_, resp := Client.DatabaseRecycle()
|
||||
resp, err := client.DatabaseRecycle()
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
_, resp := th.SystemAdminClient.DatabaseRecycle()
|
||||
CheckNoError(t, resp)
|
||||
_, err := th.SystemAdminClient.DatabaseRecycle()
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
_, resp := th.SystemAdminClient.DatabaseRecycle()
|
||||
resp, err := th.SystemAdminClient.DatabaseRecycle()
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
}
|
||||
@@ -283,26 +297,25 @@ func TestDatabaseRecycle(t *testing.T) {
|
||||
func TestInvalidateCaches(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
ok, resp := Client.InvalidateCaches()
|
||||
resp, err := client.InvalidateCaches()
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.False(t, ok, "should not clean the cache due to no permission.")
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
ok, resp := th.SystemAdminClient.InvalidateCaches()
|
||||
CheckNoError(t, resp)
|
||||
require.True(t, ok, "should clean the cache")
|
||||
_, err := th.SystemAdminClient.InvalidateCaches()
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
ok, resp := th.SystemAdminClient.InvalidateCaches()
|
||||
resp, err := th.SystemAdminClient.InvalidateCaches()
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.False(t, ok, "should not clean the cache due to no permission.")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -315,41 +328,44 @@ func TestGetLogs(t *testing.T) {
|
||||
}
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
logs, resp := c.GetLogs(0, 10)
|
||||
CheckNoError(t, resp)
|
||||
logs, _, err := c.GetLogs(0, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, logs, 10)
|
||||
|
||||
for i := 10; i < 20; i++ {
|
||||
assert.Containsf(t, logs[i-10], fmt.Sprintf(`"msg":"%d"`, i), "Log line doesn't contain correct message")
|
||||
}
|
||||
|
||||
logs, resp = c.GetLogs(1, 10)
|
||||
CheckNoError(t, resp)
|
||||
logs, _, err = c.GetLogs(1, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, logs, 10)
|
||||
|
||||
logs, resp = c.GetLogs(-1, -1)
|
||||
CheckNoError(t, resp)
|
||||
logs, _, err = c.GetLogs(-1, -1)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, logs, "should not be empty")
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
_, resp := th.Client.GetLogs(0, 10)
|
||||
_, resp, err := th.Client.GetLogs(0, 10)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
_, resp := th.Client.GetLogs(0, 10)
|
||||
_, resp, err := th.Client.GetLogs(0, 10)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.Client.Logout()
|
||||
_, resp = th.Client.GetLogs(0, 10)
|
||||
_, resp, err = th.Client.GetLogs(0, 10)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestPostLog(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
enableDev := *th.App.Config().ServiceSettings.EnableDeveloper
|
||||
defer func() {
|
||||
@@ -361,28 +377,29 @@ func TestPostLog(t *testing.T) {
|
||||
message["level"] = "ERROR"
|
||||
message["message"] = "this is a test"
|
||||
|
||||
_, resp := Client.PostLog(message)
|
||||
CheckNoError(t, resp)
|
||||
_, _, err := client.PostLog(message)
|
||||
require.NoError(t, err)
|
||||
|
||||
*th.App.Config().ServiceSettings.EnableDeveloper = false
|
||||
|
||||
_, resp = Client.PostLog(message)
|
||||
CheckNoError(t, resp)
|
||||
_, _, err = client.PostLog(message)
|
||||
require.NoError(t, err)
|
||||
|
||||
*th.App.Config().ServiceSettings.EnableDeveloper = true
|
||||
|
||||
Client.Logout()
|
||||
client.Logout()
|
||||
|
||||
_, resp = Client.PostLog(message)
|
||||
CheckNoError(t, resp)
|
||||
_, _, err = client.PostLog(message)
|
||||
require.NoError(t, err)
|
||||
|
||||
*th.App.Config().ServiceSettings.EnableDeveloper = false
|
||||
|
||||
_, resp = Client.PostLog(message)
|
||||
_, resp, err := client.PostLog(message)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
logMessage, resp := th.SystemAdminClient.PostLog(message)
|
||||
CheckNoError(t, resp)
|
||||
logMessage, _, err := th.SystemAdminClient.PostLog(message)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, logMessage, "should return the log message")
|
||||
|
||||
}
|
||||
@@ -390,13 +407,14 @@ func TestPostLog(t *testing.T) {
|
||||
func TestGetAnalyticsOld(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
rows, resp := Client.GetAnalyticsOld("", "")
|
||||
rows, resp, err := client.GetAnalyticsOld("", "")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.Nil(t, rows, "should be nil")
|
||||
rows, resp = th.SystemAdminClient.GetAnalyticsOld("", "")
|
||||
CheckNoError(t, resp)
|
||||
rows, _, err = th.SystemAdminClient.GetAnalyticsOld("", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
found := false
|
||||
found2 := false
|
||||
@@ -412,17 +430,17 @@ func TestGetAnalyticsOld(t *testing.T) {
|
||||
assert.True(t, found, "should return unique user count")
|
||||
assert.True(t, found2, "should return inactive user count")
|
||||
|
||||
_, resp = th.SystemAdminClient.GetAnalyticsOld("post_counts_day", "")
|
||||
CheckNoError(t, resp)
|
||||
_, _, err = th.SystemAdminClient.GetAnalyticsOld("post_counts_day", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp = th.SystemAdminClient.GetAnalyticsOld("user_counts_with_posts_day", "")
|
||||
CheckNoError(t, resp)
|
||||
_, _, err = th.SystemAdminClient.GetAnalyticsOld("user_counts_with_posts_day", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp = th.SystemAdminClient.GetAnalyticsOld("extra_counts", "")
|
||||
CheckNoError(t, resp)
|
||||
_, _, err = th.SystemAdminClient.GetAnalyticsOld("extra_counts", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
rows, resp = th.SystemAdminClient.GetAnalyticsOld("", th.BasicTeam.Id)
|
||||
CheckNoError(t, resp)
|
||||
rows, _, err = th.SystemAdminClient.GetAnalyticsOld("", th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, row := range rows {
|
||||
if row.Name == "inactive_user_count" {
|
||||
@@ -430,35 +448,36 @@ func TestGetAnalyticsOld(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
rows2, resp2 := th.SystemAdminClient.GetAnalyticsOld("standard", "")
|
||||
CheckNoError(t, resp2)
|
||||
rows2, _, err := th.SystemAdminClient.GetAnalyticsOld("standard", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "total_websocket_connections", rows2[5].Name)
|
||||
assert.Equal(t, float64(0), rows2[5].Value)
|
||||
|
||||
WebSocketClient, err := th.CreateWebSocketClient()
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
rows2, resp2 = th.SystemAdminClient.GetAnalyticsOld("standard", "")
|
||||
CheckNoError(t, resp2)
|
||||
rows2, _, err = th.SystemAdminClient.GetAnalyticsOld("standard", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "total_websocket_connections", rows2[5].Name)
|
||||
assert.Equal(t, float64(1), rows2[5].Value)
|
||||
|
||||
WebSocketClient.Close()
|
||||
|
||||
rows2, resp2 = th.SystemAdminClient.GetAnalyticsOld("standard", "")
|
||||
CheckNoError(t, resp2)
|
||||
rows2, _, err = th.SystemAdminClient.GetAnalyticsOld("standard", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "total_websocket_connections", rows2[5].Name)
|
||||
assert.Equal(t, float64(0), rows2[5].Value)
|
||||
|
||||
Client.Logout()
|
||||
_, resp = Client.GetAnalyticsOld("", th.BasicTeam.Id)
|
||||
client.Logout()
|
||||
_, resp, err = client.GetAnalyticsOld("", th.BasicTeam.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestS3TestConnection(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
s3Host := os.Getenv("CI_MINIO_HOST")
|
||||
if s3Host == "" {
|
||||
@@ -485,49 +504,53 @@ func TestS3TestConnection(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
_, resp := Client.TestS3Connection(&config)
|
||||
resp, err := client.TestS3Connection(&config)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
_, resp := th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(&config)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.Equal(t, resp.Error.Message, "S3 Bucket is required", "should return error - missing s3 bucket")
|
||||
CheckErrorMessage(t, err, "S3 Bucket is required")
|
||||
// If this fails, check the test configuration to ensure minio is setup with the
|
||||
// `mattermost-test` bucket defined by model.MINIO_BUCKET.
|
||||
*config.FileSettings.AmazonS3Bucket = model.MinioBucket
|
||||
config.FileSettings.AmazonS3PathPrefix = model.NewString("")
|
||||
*config.FileSettings.AmazonS3Region = "us-east-1"
|
||||
_, resp = th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(&config)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
config.FileSettings.AmazonS3Region = model.NewString("")
|
||||
_, resp = th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(&config)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
config.FileSettings.AmazonS3Bucket = model.NewString("Wrong_bucket")
|
||||
_, resp = th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(&config)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
assert.Equal(t, "api.file.test_connection_s3_bucket_does_not_exist.app_error", resp.Error.Id)
|
||||
CheckErrorID(t, err, "api.file.test_connection_s3_bucket_does_not_exist.app_error")
|
||||
|
||||
*config.FileSettings.AmazonS3Bucket = "shouldnotcreatenewbucket"
|
||||
_, resp = th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(&config)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
assert.Equal(t, "api.file.test_connection_s3_bucket_does_not_exist.app_error", resp.Error.Id)
|
||||
CheckErrorID(t, err, "api.file.test_connection_s3_bucket_does_not_exist.app_error")
|
||||
})
|
||||
|
||||
t.Run("with incorrect credentials", func(t *testing.T) {
|
||||
configCopy := config
|
||||
*configCopy.FileSettings.AmazonS3AccessKeyId = "invalidaccesskey"
|
||||
_, resp := th.SystemAdminClient.TestS3Connection(&configCopy)
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(&configCopy)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
assert.Equal(t, "api.file.test_connection_s3_auth.app_error", resp.Error.Id)
|
||||
CheckErrorID(t, err, "api.file.test_connection_s3_auth.app_error")
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
_, resp := th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(&config)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
}
|
||||
@@ -535,12 +558,12 @@ func TestS3TestConnection(t *testing.T) {
|
||||
func TestSupportedTimezones(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
supportedTimezonesFromConfig := th.App.Timezones().GetSupported()
|
||||
supportedTimezones, resp := Client.GetSupportedTimezone()
|
||||
supportedTimezones, _, err := client.GetSupportedTimezone()
|
||||
|
||||
CheckNoError(t, resp)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, supportedTimezonesFromConfig, supportedTimezones)
|
||||
}
|
||||
|
||||
@@ -558,7 +581,7 @@ func TestRedirectLocation(t *testing.T) {
|
||||
|
||||
th := Setup(t)
|
||||
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 })
|
||||
@@ -567,36 +590,38 @@ func TestRedirectLocation(t *testing.T) {
|
||||
*th.App.Config().ServiceSettings.EnableLinkPreviews = true
|
||||
*th.App.Config().ServiceSettings.AllowedUntrustedInternalConnections = "127.0.0.1"
|
||||
|
||||
_, resp := th.SystemAdminClient.GetRedirectLocation("https://mattermost.com/", "")
|
||||
CheckNoError(t, resp)
|
||||
_, _, err := th.SystemAdminClient.GetRedirectLocation("https://mattermost.com/", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp = th.SystemAdminClient.GetRedirectLocation("", "")
|
||||
_, resp, err := th.SystemAdminClient.GetRedirectLocation("", "")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
actual, resp := th.SystemAdminClient.GetRedirectLocation(mockBitlyLink, "")
|
||||
CheckNoError(t, resp)
|
||||
actual, _, err := th.SystemAdminClient.GetRedirectLocation(mockBitlyLink, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, actual)
|
||||
|
||||
// Check cached value
|
||||
actual, resp = th.SystemAdminClient.GetRedirectLocation(mockBitlyLink, "")
|
||||
CheckNoError(t, resp)
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation(mockBitlyLink, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, actual)
|
||||
|
||||
*th.App.Config().ServiceSettings.EnableLinkPreviews = false
|
||||
actual, resp = th.SystemAdminClient.GetRedirectLocation("https://mattermost.com/", "")
|
||||
CheckNoError(t, resp)
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation("https://mattermost.com/", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, actual, "")
|
||||
|
||||
actual, resp = th.SystemAdminClient.GetRedirectLocation("", "")
|
||||
CheckNoError(t, resp)
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation("", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, actual, "")
|
||||
|
||||
actual, resp = th.SystemAdminClient.GetRedirectLocation(mockBitlyLink, "")
|
||||
CheckNoError(t, resp)
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation(mockBitlyLink, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, actual, "")
|
||||
|
||||
Client.Logout()
|
||||
_, resp = Client.GetRedirectLocation("", "")
|
||||
client.Logout()
|
||||
_, resp, err = client.GetRedirectLocation("", "")
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
|
||||
@@ -607,16 +632,15 @@ func TestSetServerBusy(t *testing.T) {
|
||||
const secs = 30
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
ok, resp := th.Client.SetServerBusy(secs)
|
||||
resp, err := th.Client.SetServerBusy(secs)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.False(t, ok, "should not set server busy due to no permission")
|
||||
require.False(t, th.App.Srv().Busy.IsBusy(), "server should not be marked busy")
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
ok, resp := c.SetServerBusy(secs)
|
||||
CheckNoError(t, resp)
|
||||
require.True(t, ok, "should set server busy successfully")
|
||||
_, err := c.SetServerBusy(secs)
|
||||
require.NoError(t, err)
|
||||
require.True(t, th.App.Srv().Busy.IsBusy(), "server should be marked busy")
|
||||
}, "as system admin")
|
||||
}
|
||||
@@ -628,9 +652,9 @@ func TestSetServerBusyInvalidParam(t *testing.T) {
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
params := []int{-1, 0, MaxServerBusySeconds + 1}
|
||||
for _, p := range params {
|
||||
ok, resp := c.SetServerBusy(p)
|
||||
resp, err := c.SetServerBusy(p)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.False(t, ok, "should not set server busy due to invalid param ", p)
|
||||
require.False(t, th.App.Srv().Busy.IsBusy(), "server should not be marked busy due to invalid param ", p)
|
||||
}
|
||||
}, "as system admin, invalid param")
|
||||
@@ -642,17 +666,16 @@ func TestClearServerBusy(t *testing.T) {
|
||||
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
ok, resp := th.Client.ClearServerBusy()
|
||||
resp, err := th.Client.ClearServerBusy()
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.False(t, ok, "should not clear server busy flag due to no permission.")
|
||||
require.True(t, th.App.Srv().Busy.IsBusy(), "server should be marked busy")
|
||||
})
|
||||
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
ok, resp := c.ClearServerBusy()
|
||||
CheckNoError(t, resp)
|
||||
require.True(t, ok, "should clear server busy flag successfully")
|
||||
_, err := c.ClearServerBusy()
|
||||
require.NoError(t, err)
|
||||
require.False(t, th.App.Srv().Busy.IsBusy(), "server should not be marked busy")
|
||||
}, "as system admin")
|
||||
}
|
||||
@@ -664,14 +687,15 @@ func TestGetServerBusy(t *testing.T) {
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
_, resp := th.Client.GetServerBusy()
|
||||
_, resp, err := th.Client.GetServerBusy()
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
sbs, resp := c.GetServerBusy()
|
||||
sbs, _, err := c.GetServerBusy()
|
||||
expires := time.Unix(sbs.Expires, 0)
|
||||
CheckNoError(t, resp)
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, expires.Unix(), time.Now().Unix())
|
||||
}, "as system admin")
|
||||
}
|
||||
@@ -684,25 +708,29 @@ func TestServerBusy503(t *testing.T) {
|
||||
|
||||
t.Run("search users while busy", func(t *testing.T) {
|
||||
us := &model.UserSearch{Term: "test"}
|
||||
_, resp := th.SystemAdminClient.SearchUsers(us)
|
||||
_, resp, err := th.SystemAdminClient.SearchUsers(us)
|
||||
require.Error(t, err)
|
||||
CheckServiceUnavailableStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("search teams while busy", func(t *testing.T) {
|
||||
ts := &model.TeamSearch{}
|
||||
_, resp := th.SystemAdminClient.SearchTeams(ts)
|
||||
_, resp, err := th.SystemAdminClient.SearchTeams(ts)
|
||||
require.Error(t, err)
|
||||
CheckServiceUnavailableStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("search channels while busy", func(t *testing.T) {
|
||||
cs := &model.ChannelSearch{}
|
||||
_, resp := th.SystemAdminClient.SearchChannels("foo", cs)
|
||||
_, resp, err := th.SystemAdminClient.SearchChannels("foo", cs)
|
||||
require.Error(t, err)
|
||||
CheckServiceUnavailableStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("search archived channels while busy", func(t *testing.T) {
|
||||
cs := &model.ChannelSearch{}
|
||||
_, resp := th.SystemAdminClient.SearchArchivedChannels("foo", cs)
|
||||
_, resp, err := th.SystemAdminClient.SearchArchivedChannels("foo", cs)
|
||||
require.Error(t, err)
|
||||
CheckServiceUnavailableStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -710,8 +738,8 @@ func TestServerBusy503(t *testing.T) {
|
||||
|
||||
t.Run("search users while not busy", func(t *testing.T) {
|
||||
us := &model.UserSearch{Term: "test"}
|
||||
_, resp := th.SystemAdminClient.SearchUsers(us)
|
||||
CheckNoError(t, resp)
|
||||
_, _, err := th.SystemAdminClient.SearchUsers(us)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user