mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboards: set max length of message to 500 (#99229)
This commit is contained in:
committed by
GitHub
parent
865e911e10
commit
2fe510eb6f
@@ -70,6 +70,10 @@ var (
|
||||
Reason: "uid too long, max 40 characters",
|
||||
StatusCode: 400,
|
||||
}
|
||||
ErrDashboardMessageTooLong = DashboardErr{
|
||||
Reason: "message too long, max 500 characters",
|
||||
StatusCode: 400,
|
||||
}
|
||||
ErrDashboardCannotSaveProvisionedDashboard = DashboardErr{
|
||||
Reason: "Cannot save provisioned dashboard",
|
||||
StatusCode: 400,
|
||||
|
||||
@@ -353,6 +353,10 @@ func (dr *DashboardServiceImpl) BuildSaveDashboardCommand(ctx context.Context, d
|
||||
return nil, dashboards.ErrDashboardTitleEmpty
|
||||
}
|
||||
|
||||
if len(dto.Message) > 500 {
|
||||
return nil, dashboards.ErrDashboardMessageTooLong
|
||||
}
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Dashboard).Inc()
|
||||
// nolint:staticcheck
|
||||
if dash.IsFolder && dash.FolderID > 0 {
|
||||
|
||||
@@ -67,6 +67,22 @@ func TestDashboardService(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Should return validation error if message is too long", func(t *testing.T) {
|
||||
dto.Dashboard = dashboards.NewDashboard("Dash")
|
||||
dto.Message = `Here we go, 500+ characters for testing. I'm sorry that you're
|
||||
having to read this. I spent too long trying to come up with something clever
|
||||
to say or a funny joke. Unforuntately, nothing came to mind. So instead, I'm
|
||||
will share this with you, as a form of payment for having to read this:
|
||||
https://youtu.be/dQw4w9WgXcQ?si=KeoTIpn9tUtQnOBk! Enjoy :) Now lets see if
|
||||
this test passes or if the result is more exciting than these 500 characters
|
||||
I wrote. Best of luck to the both of us!`
|
||||
_, err := service.SaveDashboard(context.Background(), dto, false)
|
||||
require.Equal(t, err, dashboards.ErrDashboardMessageTooLong)
|
||||
|
||||
// set to a shorter message for the rest of the tests
|
||||
dto.Message = `message`
|
||||
})
|
||||
|
||||
t.Run("Should return validation error if folder is named General", func(t *testing.T) {
|
||||
dto.Dashboard = dashboards.NewDashboardFolder("General")
|
||||
_, err := service.SaveDashboard(context.Background(), dto, false)
|
||||
|
||||
Reference in New Issue
Block a user