diff --git a/server/cells.go b/server/cells.go index 29d78b000..2b2f15e2f 100644 --- a/server/cells.go +++ b/server/cells.go @@ -76,14 +76,31 @@ func ValidDashboardCellRequest(c *chronograf.DashboardCell) error { // HasCorrectAxes verifies that only permitted axes exist within a DashboardCell func HasCorrectAxes(c *chronograf.DashboardCell) error { - for axis, _ := range c.Axes { - switch axis { + for label, axis := range c.Axes { + switch label { case "x", "y", "y2": // no-op default: return chronograf.ErrInvalidAxis } + + // validate axis scale + switch axis.Scale { + case "linear", "", "log": + // no-op + default: + return chronograf.ErrInvalidAxis + } + + // validate axis base + switch axis.Base { + case "10", "2", "": + // no-op + default: + return chronograf.ErrInvalidAxis + } } + return nil } diff --git a/server/cells_test.go b/server/cells_test.go index c0ade6f5f..12b109679 100644 --- a/server/cells_test.go +++ b/server/cells_test.go @@ -55,6 +55,78 @@ func Test_Cells_CorrectAxis(t *testing.T) { }, true, }, + { + "linear scale value", + &chronograf.DashboardCell{ + Axes: map[string]chronograf.Axis{ + "x": chronograf.Axis{ + Scale: "linear", + Bounds: []string{"0", "100"}, + }, + }, + }, + false, + }, + { + "log scale value", + &chronograf.DashboardCell{ + Axes: map[string]chronograf.Axis{ + "x": chronograf.Axis{ + Scale: "log", + Bounds: []string{"0", "100"}, + }, + }, + }, + false, + }, + { + "invalid scale value", + &chronograf.DashboardCell{ + Axes: map[string]chronograf.Axis{ + "x": chronograf.Axis{ + Scale: "potatoes", + Bounds: []string{"0", "100"}, + }, + }, + }, + true, + }, + { + "base 10 axis", + &chronograf.DashboardCell{ + Axes: map[string]chronograf.Axis{ + "x": chronograf.Axis{ + Base: "10", + Bounds: []string{"0", "100"}, + }, + }, + }, + false, + }, + { + "base 2 axis", + &chronograf.DashboardCell{ + Axes: map[string]chronograf.Axis{ + "x": chronograf.Axis{ + Base: "2", + Bounds: []string{"0", "100"}, + }, + }, + }, + false, + }, + { + "invalid base", + &chronograf.DashboardCell{ + Axes: map[string]chronograf.Axis{ + "x": chronograf.Axis{ + Base: "all your base are belong to us", + Bounds: []string{"0", "100"}, + }, + }, + }, + true, + }, } for _, test := range axisTests {